Class: Datadog::Core::Remote::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/remote/client.rb,
lib/datadog/core/remote/client/capabilities.rb

Overview

Client communicates with the agent and sync remote configuration

Defined Under Namespace

Classes: Capabilities, SyncError, TransportError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport, capabilities, settings:, logger:, repository: Configuration::Repository.new) ⇒ Client

Returns a new instance of Client.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/datadog/core/remote/client.rb', line 25

def initialize(transport, capabilities, settings:, logger:, repository: Configuration::Repository.new)
  @transport = transport
  @settings = settings
  @logger = logger

  @repository = repository
  @id = SecureRandom.uuid
  @capabilities = capabilities
  @dispatcher = Dispatcher.new(@capabilities.receivers)
  @pending_initial_reconcile = true
end

Instance Attribute Details

#dispatcher ⇒ Object (readonly)

Returns the value of attribute dispatcher.



17
18
19
# File 'lib/datadog/core/remote/client.rb', line 17

def dispatcher
  @dispatcher
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



17
18
19
# File 'lib/datadog/core/remote/client.rb', line 17

def id
  @id
end

#logger ⇒ Object (readonly)

Returns the value of attribute logger.



17
18
19
# File 'lib/datadog/core/remote/client.rb', line 17

def logger
  @logger
end

#pending_initial_reconcile ⇒ Boolean (readonly)

Whether the initial reconcile is still pending, to run on the first sync whose response contains targets.

Returns:

  • (Boolean)


23
24
25
# File 'lib/datadog/core/remote/client.rb', line 23

def pending_initial_reconcile
  @pending_initial_reconcile
end

#repository ⇒ Object (readonly)

Returns the value of attribute repository.



17
18
19
# File 'lib/datadog/core/remote/client.rb', line 17

def repository
  @repository
end

#settings ⇒ Object (readonly)

Returns the value of attribute settings.



17
18
19
# File 'lib/datadog/core/remote/client.rb', line 17

def settings
  @settings
end

#transport ⇒ Object (readonly)

Returns the value of attribute transport.



17
18
19
# File 'lib/datadog/core/remote/client.rb', line 17

def transport
  @transport
end

Instance Method Details

#sync ⇒ void

This method returns an undefined value.

Polls the agent for remote configuration, applies the response to the repository and dispatches the resulting changes to the receivers.

The agent sends an empty response when it holds no targets newer than the targets version the client reported. Until the client applies a response that carries targets, it reports the initial targets version, so an empty response then means the agent has not received targets from the backend. The initial reconcile therefore waits for a response that carries targets.

Raises:

  • (TransportError) —

    when the agent reports an internal error

  • (SyncError) —

    when the response cannot be applied to the repository



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/datadog/core/remote/client.rb', line 50

def sync
  # TODO: Skip sync if no capabilities are registered
  response = transport.send_config(payload)

  if response.ok?
    changes = process_response(response)
    if pending_initial_reconcile && !response.empty?
      dispatcher.reconcile(changes, repository)
      @pending_initial_reconcile = false
    end
  elsif response.internal_error?
    raise TransportError, response.to_s
  end
  nil
end