Class: NewRelic::Agent::NewRelicService::Marshaller

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/new_relic_service.rb

Direct Known Subclasses

JsonMarshaller, PrubyMarshaller

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



263
264
265
# File 'lib/new_relic/agent/new_relic_service.rb', line 263

def encoding
  @encoding
end

Instance Method Details

#compress(data, opts = {}) ⇒ Object

This method handles the compression of the request body that we are going to send to the server

We currently optimize for CPU here since we get roughly a 10x reduction in message size with this, and CPU overhead is at a premium. For extra-large posts, we use the higher compression since otherwise it actually errors out.

We do not compress if content is smaller than 64kb. There are problems with bugs in Ruby in some versions that expose us to a risk of segfaults if we compress aggressively.

medium payloads get fast compression, to save CPU big payloads get all the compression possible, to stay under the 2,000,000 byte post threshold



280
281
282
283
284
285
286
287
288
# File 'lib/new_relic/agent/new_relic_service.rb', line 280

def compress(data, opts={})
  if opts[:force] || data.size > 64 * 1024
    data = Zlib::Deflate.deflate(data, Zlib::DEFAULT_COMPRESSION)
    @encoding = 'deflate'
  else
    @encoding = 'identity'
  end
  data
end

#parsed_error(error) ⇒ Object



290
291
292
293
294
295
296
# File 'lib/new_relic/agent/new_relic_service.rb', line 290

def parsed_error(error)
  error_class = error['error_type'].split('::') \
    .inject(Module) {|mod,const| mod.const_get(const) }
  error_class.new(error['message'])
rescue NameError
  CollectorError.new("#{error['error_type']}: #{error['message']}")
end