-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pkg/otlp/metrics] Add telemetry metric counting the number of missin…
…g sources (#220) * [pkg/otlp/metrics] Add telemetry metric counting the number of missing sources * Add changelog PR number * genlicenses * Address feedback
- Loading branch information
Showing
10 changed files
with
389 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component (e.g. pkg/quantile) | ||
component: pkg/otlp/metric | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add `datadog.otlp_translator.metrics.missing_source` counter, which counts the number of metrics that are missing a source (e.g. hostname). | ||
|
||
# The PR related to this change | ||
issues: [220] | ||
|
||
# (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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2022-present Datadog, Inc. | ||
|
||
package metrics | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
sdkmetric "go.opentelemetry.io/otel/sdk/metric" | ||
"go.opentelemetry.io/otel/sdk/metric/metricdata" | ||
) | ||
|
||
// deltaSelector sets delta aggregation temporality for monotonic counters and histograms. | ||
func deltaSelector(kind sdkmetric.InstrumentKind) metricdata.Temporality { | ||
switch kind { | ||
case sdkmetric.InstrumentKindCounter, | ||
sdkmetric.InstrumentKindHistogram, | ||
sdkmetric.InstrumentKindObservableGauge, | ||
sdkmetric.InstrumentKindObservableCounter: | ||
return metricdata.DeltaTemporality | ||
case sdkmetric.InstrumentKindUpDownCounter, | ||
sdkmetric.InstrumentKindObservableUpDownCounter: | ||
return metricdata.CumulativeTemporality | ||
} | ||
panic("unknown instrument kind") | ||
} | ||
|
||
// AssertHasSumMetric asserts that an OTLP metrics payload has | ||
// a single sum metric with a single datapoint and with the given name and value. | ||
func AssertHasSumMetric[N int64 | float64](t *testing.T, rm *metricdata.ResourceMetrics, name string, value int64) { | ||
var found bool | ||
for _, scopeMetric := range rm.ScopeMetrics { | ||
for _, metric := range scopeMetric.Metrics { | ||
if metric.Name == name { | ||
if !found { | ||
assert.Len(t, metric.Data.(metricdata.Sum[N]).DataPoints, 1) | ||
assert.Equal(t, value, metric.Data.(metricdata.Sum[N]).DataPoints[0].Value) | ||
found = true | ||
} else { | ||
assert.Fail(t, "metric %s found more than once", name) | ||
} | ||
} | ||
} | ||
} | ||
|
||
assert.True(t, found, "metric %s not found", name) | ||
} | ||
|
||
func TestInternalTelemetryMetrics(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
otlpfile string | ||
ddogfile string | ||
expectedNumMissing int64 | ||
}{ | ||
{ | ||
name: "simple", | ||
otlpfile: "testdata/otlpdata/source/simple.json", | ||
ddogfile: "testdata/datadogdata/source/simple.json", | ||
expectedNumMissing: 4, | ||
}, | ||
} | ||
|
||
for _, testinstance := range tests { | ||
t.Run(testinstance.name, func(t *testing.T) { | ||
set := componenttest.NewNopTelemetrySettings() | ||
reader := sdkmetric.NewManualReader(sdkmetric.WithTemporalitySelector(deltaSelector)) | ||
set.MeterProvider = sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader)) | ||
translator, err := NewTranslator(set) | ||
require.NoError(t, err) | ||
AssertTranslatorMap(t, translator, testinstance.otlpfile, testinstance.ddogfile) | ||
|
||
rm := &metricdata.ResourceMetrics{} | ||
assert.NoError(t, reader.Collect(context.Background(), rm)) | ||
AssertHasSumMetric[int64](t, rm, missingSourceMetricName, testinstance.expectedNumMissing) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ | ||
"Sketches": null, | ||
"TimeSeries": [ | ||
{ | ||
"Name": "with-source", | ||
"Tags": [], | ||
"Host": "res-hostname", | ||
"OriginID": "", | ||
"OriginProduct": 0, | ||
"OriginCategory": 0, | ||
"OriginService": 0, | ||
"Type": "gauge", | ||
"Timestamp": 1667560641226420924, | ||
"Value": 1 | ||
}, | ||
{ | ||
"Name": "with-source-2", | ||
"Tags": [], | ||
"Host": "res-hostname", | ||
"OriginID": "", | ||
"OriginProduct": 0, | ||
"OriginCategory": 0, | ||
"OriginService": 0, | ||
"Type": "gauge", | ||
"Timestamp": 1667560641226420924, | ||
"Value": 1 | ||
}, | ||
{ | ||
"Name": "missing-source-1", | ||
"Tags": [], | ||
"Host": "", | ||
"OriginID": "", | ||
"OriginProduct": 0, | ||
"OriginCategory": 0, | ||
"OriginService": 0, | ||
"Type": "gauge", | ||
"Timestamp": 1667560641226420924, | ||
"Value": 1 | ||
}, | ||
{ | ||
"Name": "missing-source-2", | ||
"Tags": [], | ||
"Host": "", | ||
"OriginID": "", | ||
"OriginProduct": 0, | ||
"OriginCategory": 0, | ||
"OriginService": 0, | ||
"Type": "gauge", | ||
"Timestamp": 1667560641226420924, | ||
"Value": 1 | ||
}, | ||
{ | ||
"Name": "missing-source-3", | ||
"Tags": [], | ||
"Host": "", | ||
"OriginID": "", | ||
"OriginProduct": 0, | ||
"OriginCategory": 0, | ||
"OriginService": 0, | ||
"Type": "gauge", | ||
"Timestamp": 1667560641226420924, | ||
"Value": 1 | ||
}, | ||
{ | ||
"Name": "missing-source-4", | ||
"Tags": [], | ||
"Host": "", | ||
"OriginID": "", | ||
"OriginProduct": 0, | ||
"OriginCategory": 0, | ||
"OriginService": 0, | ||
"Type": "gauge", | ||
"Timestamp": 1667560641226420924, | ||
"Value": 1 | ||
}, | ||
{ | ||
"Name": "datadog.otlp_translator.metrics.missing_source", | ||
"Tags": [], | ||
"Host": "", | ||
"OriginID": "", | ||
"OriginProduct": 0, | ||
"OriginCategory": 0, | ||
"OriginService": 0, | ||
"Type": "gauge", | ||
"Timestamp": 1667560641226420924, | ||
"Value": 37 | ||
} | ||
] | ||
} |
Oops, something went wrong.