From 56ed23d1940bdaced0f989f0d208cbee275050f2 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Tue, 19 Dec 2023 12:45:02 +0100 Subject: [PATCH] Rename metric to datadog.otlp_translator.resources.missing_source --- .chloggen/mx-psi_rename-to-resource.yaml | 16 ++++++++++++++++ pkg/otlp/metrics/metrics_translator.go | 21 +++++++++++++-------- pkg/otlp/metrics/source_test.go | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) create mode 100755 .chloggen/mx-psi_rename-to-resource.yaml diff --git a/.chloggen/mx-psi_rename-to-resource.yaml b/.chloggen/mx-psi_rename-to-resource.yaml new file mode 100755 index 00000000..1781dfc3 --- /dev/null +++ b/.chloggen/mx-psi_rename-to-resource.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component (e.g. pkg/quantile) +component: pkg/otlp/metrics + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Rename `datadog.otlp_translator.metrics.missing_source` to `datadog.otlp_translator.resources.missing_source` with `signal:metrics` attribute. + +# The PR related to this change +issues: [229] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/pkg/otlp/metrics/metrics_translator.go b/pkg/otlp/metrics/metrics_translator.go index 0c263e3b..abc837d5 100644 --- a/pkg/otlp/metrics/metrics_translator.go +++ b/pkg/otlp/metrics/metrics_translator.go @@ -29,6 +29,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" + "go.opentelemetry.io/otel/attribute" otelmetric "go.opentelemetry.io/otel/metric" "go.uber.org/zap" "golang.org/x/exp/slices" @@ -41,8 +42,12 @@ const ( metricName string = "metric name" errNoBucketsNoSumCount string = "no buckets mode and no send count sum are incompatible" - meterName string = "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics" - missingSourceMetricName string = "datadog.otlp_translator.metrics.missing_source" + meterName string = "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes" + missingSourceMetricName string = "datadog.otlp_translator.resources.missing_source" +) + +var ( + signalTypeSet = attribute.NewSet(attribute.String("signal", "logs")) ) var _ source.Provider = (*noSourceProvider)(nil) @@ -101,7 +106,7 @@ func NewTranslator(set component.TelemetrySettings, options ...TranslatorOption) missingSources, err := meter.Int64Counter( missingSourceMetricName, otelmetric.WithDescription("OTLP metrics that are missing a source (e.g. hostname)"), - otelmetric.WithUnit("[metric]"), + otelmetric.WithUnit("{resource}"), ) if err != nil { return nil, fmt.Errorf("failed to build missing source counter: %w", err) @@ -678,6 +683,11 @@ func (t *Translator) MapMetrics(ctx context.Context, md pmetric.Metrics, consume if err != nil { return metadata, err } + if !hasSource { + // Only count metrics if they do not come from the translator itself. + t.instruments.missingSources.Add(ctx, 1, otelmetric.WithAttributeSet(signalTypeSet)) + } + var host string switch src.Kind { case source.HostnameKind: @@ -699,11 +709,6 @@ func (t *Translator) MapMetrics(ctx context.Context, md pmetric.Metrics, consume ilm := ilms.At(j) metricsArray := ilm.Metrics() - if !hasSource && ilm.Scope().Name() != meterName { - // Only count metrics if they do not come from the translator itself. - t.instruments.missingSources.Add(ctx, int64(metricsArray.Len())) - } - var additionalTags []string if t.cfg.InstrumentationScopeMetadataAsTags { additionalTags = append(attributeTags, instrumentationscope.TagsFromInstrumentationScopeMetadata(ilm.Scope())...) diff --git a/pkg/otlp/metrics/source_test.go b/pkg/otlp/metrics/source_test.go index 91414054..4e2f2402 100644 --- a/pkg/otlp/metrics/source_test.go +++ b/pkg/otlp/metrics/source_test.go @@ -63,7 +63,7 @@ func TestInternalTelemetryMetrics(t *testing.T) { name: "simple", otlpfile: "testdata/otlpdata/source/simple.json", ddogfile: "testdata/datadogdata/source/simple.json", - expectedNumMissing: 4, + expectedNumMissing: 1, }, }