Class: ElasticAPM::CentralConfig Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/elastic_apm/central_config.rb,
lib/elastic_apm/central_config/cache_control.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: CacheControl, ClientError, ResponseError, ServerError

Constant Summary collapse

DEFAULT_MAX_AGE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

300

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(config) ⇒ CentralConfig

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CentralConfig.



42
43
44
45
46
47
# File 'lib/elastic_apm/central_config.rb', line 42

def initialize(config)
  @config = config
  @modified_options = {}
  @http = Transport::Connection::Http.new(config)
  @etag = 1
end

Instance Attribute Details

#configObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/elastic_apm/central_config.rb', line 49

def config
  @config
end

#promiseObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

for specs



50
51
52
# File 'lib/elastic_apm/central_config.rb', line 50

def promise
  @promise
end

#scheduled_taskObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

for specs



50
51
52
# File 'lib/elastic_apm/central_config.rb', line 50

def scheduled_task
  @scheduled_task
end

Instance Method Details

#assign(update) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/elastic_apm/central_config.rb', line 91

def assign(update)
  # For each updated option, store the original value,
  # unless already stored
  update.each_key do |key|
    @modified_options[key] ||= config.get(key.to_sym)&.value
  end

  # If the new update doesn't set a previously modified option,
  # revert it to the original
  @modified_options.each_key do |key|
    next if update.key?(key)
    update[key] = @modified_options.delete(key)
  end

  @config.replace_options(update)
end

#fetch_and_apply_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
69
70
71
72
# File 'lib/elastic_apm/central_config.rb', line 66

def fetch_and_apply_config
  @promise =
    Concurrent::Promise
    .execute { fetch_config }
    .on_success { |resp| handle_success(resp) }
    .rescue { |err| handle_error(err) }
end

#fetch_configObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/elastic_apm/central_config.rb', line 74

def fetch_config
  resp = perform_request

  # rubocop:disable Lint/DuplicateBranch
  case resp.status
  when 200..299
    resp
  when 300..399
    resp
  when 400..499
    raise ClientError, resp
  when 500..599
    raise ServerError, resp
  end
  # rubocop:enable Lint/DuplicateBranch
end

#handle_forking!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



108
109
110
111
# File 'lib/elastic_apm/central_config.rb', line 108

def handle_forking!
  stop
  start
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
55
56
57
58
# File 'lib/elastic_apm/central_config.rb', line 52

def start
  return unless config.central_config?

  debug 'Starting CentralConfig'

  fetch_and_apply_config
end

#stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
63
64
# File 'lib/elastic_apm/central_config.rb', line 60

def stop
  debug 'Stopping CentralConfig'

  @scheduled_task&.cancel
end