Skip to content

Commit

Permalink
add settings for telemetry metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 5, 2024
1 parent da8b886 commit 49df7e4
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,16 @@ def initialize(*_)
o.type :bool
end

# Enable metrics collection for telemetry. Metrics collection only works when telemetry is enabled and
# metrics are enabled.
# @default `DD_TELEMETRY_METRICS_ENABLED` environment variable, otherwise `true`.
# @return [Boolean]
option :metrics_enabled do |o|
o.type :bool
o.env Core::Telemetry::Ext::ENV_METRICS_ENABLED
o.default true
end

# The interval in seconds when telemetry must be sent.
#
# This method is used internally, for testing purposes only.
Expand All @@ -676,6 +686,19 @@ def initialize(*_)
o.default 60.0
end

# The interval in seconds when telemetry metrics are aggregated.
# Should be a denominator of `heartbeat_interval_seconds`.
#
# This method is used internally, for testing purposes only.
# @default `DD_TELEMETRY_METRICS_AGGREGATION_INTERVAL` environment variable, otherwise `10`.
# @return [Float]
# @!visibility private
option :metrics_aggregation_interval_seconds do |o|
o.type :float
o.env Core::Telemetry::Ext::ENV_METRICS_AGGREGATION_INTERVAL
o.default 10.0
end

# The install id of the application.
#
# This method is used internally, by library injection.
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/core/telemetry/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ module Core
module Telemetry
module Ext
ENV_ENABLED = 'DD_INSTRUMENTATION_TELEMETRY_ENABLED'
ENV_METRICS_ENABLED = 'DD_TELEMETRY_METRICS_ENABLED'
ENV_HEARTBEAT_INTERVAL = 'DD_TELEMETRY_HEARTBEAT_INTERVAL'
ENV_METRICS_AGGREGATION_INTERVAL = 'DD_TELEMETRY_METRICS_AGGREGATION_INTERVAL'
ENV_DEPENDENCY_COLLECTION = 'DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED'
ENV_INSTALL_ID = 'DD_INSTRUMENTATION_INSTALL_ID'
ENV_INSTALL_TYPE = 'DD_INSTRUMENTATION_INSTALL_TYPE'
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/core/telemetry/ext.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module Datadog
module Ext
ENV_DEPENDENCY_COLLECTION: ::String
ENV_ENABLED: ::String
ENV_METRICS_ENABLED: ::String
ENV_HEARTBEAT_INTERVAL: ::String
ENV_METRICS_AGGREGATION_INTERVAL: ::String
ENV_INSTALL_ID: ::String
ENV_INSTALL_TIME: ::String
ENV_INSTALL_TYPE: ::String
Expand Down
62 changes: 62 additions & 0 deletions spec/datadog/core/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,39 @@
end
end

describe '#metrics_enabled' do
subject(:metrics_enabled) { settings.telemetry.metrics_enabled }
let(:env_var_name) { 'DD_TELEMETRY_METRICS_ENABLED' }

context 'when DD_TELEMETRY_METRICS_ENABLED' do
context 'is not defined' do
let(:env_var_value) { nil }

it { is_expected.to be true }
end

[true, false].each do |value|
context "is defined as #{value}" do
let(:env_var_value) { value.to_s }

it { is_expected.to be value }
end
end
end
end

describe '#metrics_enabled=' do
let(:env_var_name) { 'DD_TELEMETRY_METRICS_ENABLED' }
let(:env_var_value) { 'true' }

it 'updates the #metrics_enabled setting' do
expect { settings.telemetry.metrics_enabled = false }
.to change { settings.telemetry.metrics_enabled }
.from(true)
.to(false)
end
end

describe '#heartbeat_interval' do
subject(:heartbeat_interval_seconds) { settings.telemetry.heartbeat_interval_seconds }
let(:env_var_name) { 'DD_TELEMETRY_HEARTBEAT_INTERVAL' }
Expand Down Expand Up @@ -1505,6 +1538,35 @@
end
end

describe '#metrics_aggregation_interval_seconds' do
subject(:metrics_aggregation_interval_seconds) { settings.telemetry.metrics_aggregation_interval_seconds }
let(:env_var_name) { 'DD_TELEMETRY_METRICS_AGGREGATION_INTERVAL' }

context 'when DD_TELEMETRY_METRICS_AGGREGATION_INTERVAL' do
context 'is not defined' do
let(:env_var_value) { nil }

it { is_expected.to eq 10.0 }
end

context 'is defined' do
let(:env_var_value) { '1.1' }

it { is_expected.to eq 1.1 }
end
end
end

describe '#metrics_aggregation_interval_seconds=' do
let(:env_var_name) { 'DD_TELEMETRY_METRICS_AGGREGATION_INTERVAL' }
let(:env_var_value) { '1.1' }

it 'updates the #metrics_aggregation_interval_seconds setting' do
expect { settings.telemetry.metrics_aggregation_interval_seconds = 2.2 }
.to change { settings.telemetry.metrics_aggregation_interval_seconds }.from(1.1).to(2.2)
end
end

describe '#install_id' do
subject(:install_id) { settings.telemetry.install_id }
let(:env_var_name) { 'DD_INSTRUMENTATION_INSTALL_ID' }
Expand Down

0 comments on commit 49df7e4

Please sign in to comment.