Skip to content

Commit

Permalink
generate-metrics and distributions telemetry events expect collection…
Browse files Browse the repository at this point in the history
… of metrics as input
  • Loading branch information
anmarchenko committed Jun 25, 2024
1 parent 19afe2c commit 793da21
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lib/datadog/core/telemetry/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def self.metric_id(type, name, tags = [])
class Base
attr_reader :name, :tags, :values, :common, :interval

# @param name [String] metric name
# @param tags [Array<String>|Hash{String=>String}] metric tags as hash of array of "tag:val" strings
# @param common [Boolean] true if the metric is common for all languages, false for Ruby-specific metric
# @param interval [Integer] metrics aggregation interval in seconds
def initialize(name, tags: {}, common: true, interval: nil)
@name = name
@values = []
Expand Down
4 changes: 2 additions & 2 deletions sig/datadog/core/telemetry/event.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ module Datadog

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

def initialize: (String namespace, Enumerable[Hash[Symbol, untyped]] metric_series) -> void
def initialize: (String namespace, Enumerable[Datadog::Core::Telemetry::Metric::Base] metric_series) -> void
end

class Distributions < GenerateMetrics
Expand Down
25 changes: 17 additions & 8 deletions spec/datadog/core/telemetry/event_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'

require 'datadog/core/telemetry/event'
require 'datadog/core/telemetry/metric'

RSpec.describe Datadog::Core::Telemetry::Event do
let(:id) { double('seq_id') }
Expand Down Expand Up @@ -209,36 +210,44 @@ def contain_configuration(*array)
end

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

let(:namespace) { 'general' }
let(:metric_name) { 'request_count' }
let(:points) { [[123123123, 33]] }
let(:metric_series) { [{ metric: metric_name, points: points }] }
let(:metric) do
Datadog::Core::Telemetry::Metric::Count.new(metric_name, tags: { status: '200' })
end
let(:metrics) { [metric] }

let(:expected_metric_series) { [metric.to_h] }

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

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

let(:namespace) { 'general' }
let(:metric_name) { 'request_duration' }
let(:points) { [13, 14, 15, 16] }
let(:metric_series) { [{ metric: metric_name, points: points }] }
let(:metric) do
Datadog::Core::Telemetry::Metric::Distribution.new(metric_name, tags: { status: '200' })
end
let(:metrics) { [metric] }

let(:expected_metric_series) { [metric.to_h] }

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

0 comments on commit 793da21

Please sign in to comment.