Skip to content

Commit

Permalink
add generate-metrics event
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jun 24, 2024
1 parent d501969 commit 0ac8821
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/datadog/core/telemetry/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,26 @@ def type
'app-closing'
end
end

# Telemetry class for the 'generate-metrics' event
class GenerateMetrics < Base
def type
'generate-metrics'
end

def initialize(namespace, metric_series)
super()
@namespace = namespace
@metric_series = metric_series
end

def payload(_)
{
namespace: @namespace,
series: @metric_series.map(&:to_h)
}
end
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions sig/datadog/core/telemetry/event.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ module Datadog

class AppClosing < Base
end

class GenerateMetrics < Base
@namespace: String
@metric_series: Enumerable[Hash[Symbol, untyped]]

def initialize: (String namespace, Enumerable[Hash[Symbol, untyped]] metric_series) -> void
end
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/datadog/core/telemetry/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,22 @@ def contain_configuration(*array)
is_expected.to eq({})
end
end

context 'GenerateMetrics' do
let(:event) { described_class::GenerateMetrics.new(namespace, metric_series) }

let(:namespace) { 'general' }
let(:metric_name) { 'request_count' }
let(:points) { [[123123123, 33]] }
let(:metric_series) { [{ metric: metric_name, points: points }] }

it do
is_expected.to eq(
{
namespace: namespace,
series: metric_series
}
)
end
end
end

0 comments on commit 0ac8821

Please sign in to comment.