Class: NewRelic::Agent::InfiniteTracing::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/infinite_tracing/channel.rb

Constant Summary collapse

COMPRESSION_LEVELS =
%i[none low medium high].freeze
DEFAULT_COMPRESSION_LEVEL =
:none

Instance Method Summary collapse

Instance Method Details

#channelObject



22
23
24
# File 'lib/infinite_tracing/channel.rb', line 22

def channel
  GRPC::Core::Channel.new(host_and_port, settings, credentials)
end

#channel_argsObject



26
27
28
29
30
# File 'lib/infinite_tracing/channel.rb', line 26

def channel_args
  return NewRelic::EMPTY_HASH unless compression_enabled?

  GRPC::Core::CompressionOptions.new(compression_options).to_channel_arg_hash
end

#compression_enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/infinite_tracing/channel.rb', line 32

def compression_enabled?
  compression_level != :none
end

#compression_levelObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/infinite_tracing/channel.rb', line 36

def compression_level
  @compression_level ||= begin
    level = if valid_compression_level?(configured_compression_level)
      configured_compression_level
    else
      DEFAULT_COMPRESSION_LEVEL
    end
    NewRelic::Agent.logger.debug("Infinite Tracer compression level set to #{level}")
    level
  end
end

#compression_optionsObject



48
49
50
51
# File 'lib/infinite_tracing/channel.rb', line 48

def compression_options
  {default_algorithm: :gzip,
   default_level: compression_level}
end

#configured_compression_levelObject



53
54
55
# File 'lib/infinite_tracing/channel.rb', line 53

def configured_compression_level
  NewRelic::Agent.config[:'infinite_tracing.compression_level']
end

#credentialsObject



57
58
59
60
# File 'lib/infinite_tracing/channel.rb', line 57

def credentials
  # Uses system configured certificates by default
  GRPC::Core::ChannelCredentials.new
end

#host_and_portObject



62
63
64
# File 'lib/infinite_tracing/channel.rb', line 62

def host_and_port
  Config.trace_observer_host_and_port
end

#settingsObject



66
67
68
69
70
71
# File 'lib/infinite_tracing/channel.rb', line 66

def settings
  {
    'grpc.minimal_stack' => 1,
    'grpc.enable_deadline_checking' => 0
  }
end

#stubObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/infinite_tracing/channel.rb', line 11

def stub
  NewRelic::Agent.logger.debug("Infinite Tracer Opening Channel to #{host_and_port}")

  Com::Newrelic::Trace::V1::IngestService::Stub.new( \
    host_and_port,
    credentials,
    channel_override: channel,
    channel_args: channel_args
  )
end

#valid_compression_level?(level) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
# File 'lib/infinite_tracing/channel.rb', line 73

def valid_compression_level?(level)
  return true if COMPRESSION_LEVELS.include?(level)

  NewRelic::Agent.logger.error("Invalid compression level '#{level}' specified! Must be one of " \
    "#{COMPRESSION_LEVELS.join('|')}. Using default level of '#{DEFAULT_COMPRESSION_LEVEL}'")

  false
end