Class: Datadog::Core::Remote::Component Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/remote/component.rb

Overview

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.

Configures the HTTP transport to communicate with the agent to fetch and sync the remote configuration.

Defined Under Namespace

Classes: Barrier

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings, capabilities, agent_settings, logger:) ⇒ Component

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 Component.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/datadog/core/remote/component.rb', line 20

def initialize(settings, capabilities, agent_settings, logger:)
  @logger = logger

  negotiation = Negotiation.new(settings, agent_settings, logger: logger)
  transport_v7 = Datadog::Core::Remote::Transport::HTTP.v7(agent_settings: agent_settings, logger: logger)

  @barrier = Barrier.new(settings.remote.boot_timeout_seconds)

  @client = Client.new(transport_v7, capabilities, settings: settings, logger: logger)
  @healthy = false
  logger.debug { "new remote configuration client: #{@client.id}" }

  @worker = Worker.new(interval: settings.remote.poll_interval_seconds, logger: logger) do
    unless @healthy || negotiation.endpoint?('/v0.7/config')
      @barrier.lift

      next
    end

    begin
      @client.sync
      @healthy ||= true
    rescue Client::SyncError => e
      # Transient errors due to network or agent. Logged the error but not via telemetry
      logger.error do
        "remote worker client sync error: #{e.message} location: #{Array(e.backtrace).first}. skipping sync"
      end
    rescue => e
      # In case of unexpected errors, reset the negotiation object
      # given external conditions have changed and the negotiation
      # negotiation object stores error logging state that should be reset.
      negotiation = Negotiation.new(settings, agent_settings, logger: logger)

      # Transient errors due to network or agent. Logged the error but not via telemetry
      logger.error do
        "remote worker error: #{e.class.name} #{e.message} location: #{Array(e.backtrace).first}. " \
        'resetting client state'
      end

      # client state is unknown, state might be corrupted
      @client = Client.new(transport_v7, capabilities, settings: settings, logger: logger)
      @healthy = false
      logger.debug { "new remote configuration client: #{@client.id}" }

      # TODO: bail out if too many errors?
    end

    @barrier.lift
  end
end

Instance Attribute Details

#clientObject (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.



18
19
20
# File 'lib/datadog/core/remote/component.rb', line 18

def client
  @client
end

#healthyObject (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.



18
19
20
# File 'lib/datadog/core/remote/component.rb', line 18

def healthy
  @healthy
end

#loggerObject (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.



18
19
20
# File 'lib/datadog/core/remote/component.rb', line 18

def logger
  @logger
end

#workerObject (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.



18
19
20
# File 'lib/datadog/core/remote/component.rb', line 18

def worker
  @worker
end

Class Method Details

.build(settings, agent_settings, logger:, telemetry:) ⇒ 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.

Because the agent might not be available yet, we can’t perform agent-specific checks yet, as they would prevent remote configuration from ever running.

Those checks are instead performed inside the worker loop. This allows users to upgrade their agent while keeping their application running.



154
155
156
157
158
# File 'lib/datadog/core/remote/component.rb', line 154

def build(settings, agent_settings, logger:, telemetry:)
  return unless settings.remote.enabled

  new(settings, Client::Capabilities.new(settings, telemetry), agent_settings, logger: logger)
end

Instance Method Details

#barrier(_kind) ⇒ 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.

If the worker is not initialized, initialize it.

Then, waits for one client sync to be executed if ‘kind` is `:once`.



84
85
86
87
# File 'lib/datadog/core/remote/component.rb', line 84

def barrier(_kind)
  start
  @barrier.wait_once
end

#shutdown!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.



89
90
91
# File 'lib/datadog/core/remote/component.rb', line 89

def shutdown!
  @worker.stop
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.

Starts the Remote Configuration worker without waiting for first run



72
73
74
# File 'lib/datadog/core/remote/component.rb', line 72

def start
  @worker.start
end

#started?Boolean

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.

Is the Remote Configuration worker running?

Returns:

  • (Boolean)


77
78
79
# File 'lib/datadog/core/remote/component.rb', line 77

def started?
  @worker.started?
end