Class: Datadog::Core::Telemetry::Worker Private
- Inherits:
-
Object
- Object
- Datadog::Core::Telemetry::Worker
- Includes:
- Workers::Polling, Workers::Queue
- Defined in:
- lib/datadog/core/telemetry/worker.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.
Accumulates events and sends them to the API at a regular interval, including heartbeat event.
Constant Summary collapse
- DEFAULT_BUFFER_MAX_SIZE =
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.
1000- APP_STARTED_EVENT_RETRIES =
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.
10
Constants included from Workers::Polling
Workers::Polling::DEFAULT_SHUTDOWN_TIMEOUT
Instance Attribute Summary collapse
- #emitter ⇒ Object readonly private
- #initial_event ⇒ Object readonly private
- #initial_event_once ⇒ Object readonly private
- #logger ⇒ Object readonly private
Attributes included from Workers::Queue
Instance Method Summary collapse
-
#enqueue(event) ⇒ Object
private
Returns true if event was enqueued, nil if not.
- #failed_initial_event? ⇒ Boolean private
-
#flush(timeout: nil) ⇒ Object
private
Wait for the worker to send out all events that have already been queued, up to 15 seconds.
-
#initialize(heartbeat_interval_seconds:, metrics_aggregation_interval_seconds:, emitter:, metrics_manager:, dependency_collection:, logger:, settings:, agent_settings:, extended_heartbeat_interval_seconds:, enabled: true, shutdown_timeout: Workers::Polling::DEFAULT_SHUTDOWN_TIMEOUT, buffer_size: DEFAULT_BUFFER_MAX_SIZE) ⇒ Worker
constructor
private
A new instance of Worker.
- #need_initial_event? ⇒ Boolean private
- #sent_initial_event? ⇒ Boolean private
-
#start(initial_event) ⇒ Object
private
Returns true if worker thread is successfully started, false if worker thread was not started but telemetry is enabled, nil if telemetry is disabled.
- #stop(force_stop = false, timeout = @shutdown_timeout) ⇒ Object private
Methods included from Workers::Polling
#enabled=, #enabled?, included
Methods included from Workers::Queue
Constructor Details
#initialize(heartbeat_interval_seconds:, metrics_aggregation_interval_seconds:, emitter:, metrics_manager:, dependency_collection:, logger:, settings:, agent_settings:, extended_heartbeat_interval_seconds:, enabled: true, shutdown_timeout: Workers::Polling::DEFAULT_SHUTDOWN_TIMEOUT, buffer_size: DEFAULT_BUFFER_MAX_SIZE) ⇒ Worker
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 Worker.
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 |
# File 'lib/datadog/core/telemetry/worker.rb', line 23 def initialize( heartbeat_interval_seconds:, metrics_aggregation_interval_seconds:, emitter:, metrics_manager:, dependency_collection:, logger:, settings:, agent_settings:, extended_heartbeat_interval_seconds:, enabled: true, shutdown_timeout: Workers::Polling::DEFAULT_SHUTDOWN_TIMEOUT, buffer_size: DEFAULT_BUFFER_MAX_SIZE ) @emitter = emitter @metrics_manager = metrics_manager @dependency_collection = dependency_collection @logger = logger @settings = settings @agent_settings = agent_settings @ticks_per_heartbeat = (heartbeat_interval_seconds / metrics_aggregation_interval_seconds).to_i @ticks_per_extended_heartbeat = (extended_heartbeat_interval_seconds / metrics_aggregation_interval_seconds).to_i @current_ticks = 0 # Workers::Polling settings self.enabled = enabled # Workers::IntervalLoop settings self.loop_base_interval = metrics_aggregation_interval_seconds # We actually restart the worker after fork, but this is done # via the AtForkMonkeyPatch rather than the worker fork policy # because we also need to reset state outside of the worker # (e.g. the metrics). self.fork_policy = Core::Workers::Async::Thread::FORK_POLICY_RESTART @shutdown_timeout = shutdown_timeout @buffer_size = buffer_size initialize_state end |
Instance Attribute Details
#emitter ⇒ Object (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.
78 79 80 |
# File 'lib/datadog/core/telemetry/worker.rb', line 78 def emitter @emitter end |
#initial_event ⇒ Object (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.
77 78 79 |
# File 'lib/datadog/core/telemetry/worker.rb', line 77 def initial_event @initial_event end |
#initial_event_once ⇒ Object (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.
76 77 78 |
# File 'lib/datadog/core/telemetry/worker.rb', line 76 def initial_event_once @initial_event_once end |
#logger ⇒ Object (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.
75 76 77 |
# File 'lib/datadog/core/telemetry/worker.rb', line 75 def logger @logger end |
Instance Method Details
#enqueue(event) ⇒ 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.
Returns true if event was enqueued, nil if not. While returning false may seem more reasonable, the only reason for not enqueueing event (presently) is that telemetry is disabled altogether, and in this case other methods return nil.
104 105 106 107 108 109 |
# File 'lib/datadog/core/telemetry/worker.rb', line 104 def enqueue(event) return unless enabled? buffer.push(event) true end |
#failed_initial_event? ⇒ 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.
115 116 117 |
# File 'lib/datadog/core/telemetry/worker.rb', line 115 def failed_initial_event? initial_event_once.failed? end |
#flush(timeout: nil) ⇒ 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.
Wait for the worker to send out all events that have already been queued, up to 15 seconds. Returns whether all events have been flushed.
128 129 130 131 132 |
# File 'lib/datadog/core/telemetry/worker.rb', line 128 def flush(timeout: nil) # Increase default timeout to 15 seconds - see the comment in # +idle?+ for more details. super(timeout: timeout || 15) end |
#need_initial_event? ⇒ 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.
119 120 121 |
# File 'lib/datadog/core/telemetry/worker.rb', line 119 def need_initial_event? !sent_initial_event? && !failed_initial_event? end |
#sent_initial_event? ⇒ 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.
111 112 113 |
# File 'lib/datadog/core/telemetry/worker.rb', line 111 def sent_initial_event? initial_event_once.success? end |
#start(initial_event) ⇒ 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.
Returns true if worker thread is successfully started, false if worker thread was not started but telemetry is enabled, nil if telemetry is disabled.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/datadog/core/telemetry/worker.rb', line 83 def start(initial_event) return unless enabled? @initial_event = initial_event # starts async worker # perform should return true if thread was actually started, # false otherwise perform end |
#stop(force_stop = false, timeout = @shutdown_timeout) ⇒ 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.
94 95 96 97 98 |
# File 'lib/datadog/core/telemetry/worker.rb', line 94 def stop(force_stop = false, timeout = @shutdown_timeout) buffer.close if running? super end |