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:, 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:, 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 |
# File 'lib/datadog/core/telemetry/worker.rb', line 23 def initialize( heartbeat_interval_seconds:, metrics_aggregation_interval_seconds:, emitter:, metrics_manager:, dependency_collection:, logger:, 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 @ticks_per_heartbeat = (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.
71 72 73 |
# File 'lib/datadog/core/telemetry/worker.rb', line 71 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.
70 71 72 |
# File 'lib/datadog/core/telemetry/worker.rb', line 70 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.
69 70 71 |
# File 'lib/datadog/core/telemetry/worker.rb', line 69 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.
68 69 70 |
# File 'lib/datadog/core/telemetry/worker.rb', line 68 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.
97 98 99 100 101 102 |
# File 'lib/datadog/core/telemetry/worker.rb', line 97 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.
108 109 110 |
# File 'lib/datadog/core/telemetry/worker.rb', line 108 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.
121 122 123 124 125 |
# File 'lib/datadog/core/telemetry/worker.rb', line 121 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.
112 113 114 |
# File 'lib/datadog/core/telemetry/worker.rb', line 112 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.
104 105 106 |
# File 'lib/datadog/core/telemetry/worker.rb', line 104 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.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/datadog/core/telemetry/worker.rb', line 76 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.
87 88 89 90 91 |
# File 'lib/datadog/core/telemetry/worker.rb', line 87 def stop(force_stop = false, timeout = @shutdown_timeout) buffer.close if running? super end |