From 793da21fd4e720302cdf8808fce72c610ef2ff01 Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Tue, 25 Jun 2024 13:28:47 +0200 Subject: [PATCH] generate-metrics and distributions telemetry events expect collection of metrics as input --- lib/datadog/core/telemetry/metric.rb | 4 ++++ sig/datadog/core/telemetry/event.rbs | 4 ++-- spec/datadog/core/telemetry/event_spec.rb | 25 +++++++++++++++-------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/datadog/core/telemetry/metric.rb b/lib/datadog/core/telemetry/metric.rb index ebe8ecbe533..2c6ba8d97de 100644 --- a/lib/datadog/core/telemetry/metric.rb +++ b/lib/datadog/core/telemetry/metric.rb @@ -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|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 = [] diff --git a/sig/datadog/core/telemetry/event.rbs b/sig/datadog/core/telemetry/event.rbs index 61b2e34588d..791f014f9a4 100644 --- a/sig/datadog/core/telemetry/event.rbs +++ b/sig/datadog/core/telemetry/event.rbs @@ -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 diff --git a/spec/datadog/core/telemetry/event_spec.rb b/spec/datadog/core/telemetry/event_spec.rb index 50ae1265539..f53bd9468ad 100644 --- a/spec/datadog/core/telemetry/event_spec.rb +++ b/spec/datadog/core/telemetry/event_spec.rb @@ -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') } @@ -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