-
Notifications
You must be signed in to change notification settings - Fork 7
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,6 +161,9 @@ pkg/otlp/metrics,github.com/DataDog/sketches-go/ddsketch/pb/sketchpb,Apache-2.0, | |
pkg/otlp/metrics,github.com/DataDog/sketches-go/ddsketch/stat,Apache-2.0,"Copyright 2021 DataDog, Inc | Copyright 2021 Datadog, Inc" | ||
pkg/otlp/metrics,github.com/DataDog/sketches-go/ddsketch/store,Apache-2.0,"Copyright 2021 DataDog, Inc | Copyright 2021 Datadog, Inc" | ||
pkg/otlp/metrics,github.com/dustin/go-humanize,MIT,Copyright (c) 2005-2008 Dustin Sallings <[email protected]> | ||
pkg/otlp/metrics,github.com/go-logr/logr,Apache-2.0,Copyright 2019 The logr Authors. | ||
pkg/otlp/metrics,github.com/go-logr/logr/funcr,Apache-2.0,Copyright 2019 The logr Authors. | ||
pkg/otlp/metrics,github.com/go-logr/stdr,Apache-2.0,Copyright 2019 The logr Authors. | ||
pkg/otlp/metrics,github.com/gogo/protobuf/gogoproto,BSD-3-Clause,"Copyright (c) 2013, The GoGo Authors. All rights reserved | Copyright 2010 The Go Authors. All rights reserved | Sendgrid, Inc | Vastech SA (PTY) LTD | Walter Schulze <[email protected]> | Anton Povarov <[email protected]> | Brian Goff <[email protected]> | Clayton Coleman <[email protected]> | Denis Smirnov <[email protected]> | DongYun Kang <[email protected]> | Dwayne Schultz <[email protected]> | Georg Apitz <[email protected]> | Gustav Paul <[email protected]> | Johan Brandhorst <[email protected]> | John Shahid <[email protected]> | John Tuley <[email protected]> | Laurent <[email protected]> | Patrick Lee <[email protected]> | Peter Edge <[email protected]> | Roger Johansson <[email protected]> | Sam Nguyen <[email protected]> | Sergio Arbeo <[email protected]> | Stephen J Day <[email protected]> | Tamir Duberstein <[email protected]> | Todd Eisenberger <[email protected]> | Tormod Erevik Lea <[email protected]> | Vyacheslav Kim <[email protected]> | Walter Schulze <[email protected]>" | ||
pkg/otlp/metrics,github.com/gogo/protobuf/jsonpb,BSD-3-Clause,"Copyright (c) 2013, The GoGo Authors. All rights reserved | Copyright 2010 The Go Authors. All rights reserved | Sendgrid, Inc | Vastech SA (PTY) LTD | Walter Schulze <[email protected]> | Anton Povarov <[email protected]> | Brian Goff <[email protected]> | Clayton Coleman <[email protected]> | Denis Smirnov <[email protected]> | DongYun Kang <[email protected]> | Dwayne Schultz <[email protected]> | Georg Apitz <[email protected]> | Gustav Paul <[email protected]> | Johan Brandhorst <[email protected]> | John Shahid <[email protected]> | John Tuley <[email protected]> | Laurent <[email protected]> | Patrick Lee <[email protected]> | Peter Edge <[email protected]> | Roger Johansson <[email protected]> | Sam Nguyen <[email protected]> | Sergio Arbeo <[email protected]> | Stephen J Day <[email protected]> | Tamir Duberstein <[email protected]> | Todd Eisenberger <[email protected]> | Tormod Erevik Lea <[email protected]> | Vyacheslav Kim <[email protected]> | Walter Schulze <[email protected]>" | ||
pkg/otlp/metrics,github.com/gogo/protobuf/proto,BSD-3-Clause,"Copyright (c) 2013, The GoGo Authors. All rights reserved | Copyright 2010 The Go Authors. All rights reserved | Sendgrid, Inc | Vastech SA (PTY) LTD | Walter Schulze <[email protected]> | Anton Povarov <[email protected]> | Brian Goff <[email protected]> | Clayton Coleman <[email protected]> | Denis Smirnov <[email protected]> | DongYun Kang <[email protected]> | Dwayne Schultz <[email protected]> | Georg Apitz <[email protected]> | Gustav Paul <[email protected]> | Johan Brandhorst <[email protected]> | John Shahid <[email protected]> | John Tuley <[email protected]> | Laurent <[email protected]> | Patrick Lee <[email protected]> | Peter Edge <[email protected]> | Roger Johansson <[email protected]> | Sam Nguyen <[email protected]> | Sergio Arbeo <[email protected]> | Stephen J Day <[email protected]> | Tamir Duberstein <[email protected]> | Todd Eisenberger <[email protected]> | Tormod Erevik Lea <[email protected]> | Vyacheslav Kim <[email protected]> | Walter Schulze <[email protected]>" | ||
|
@@ -207,12 +210,15 @@ pkg/otlp/metrics,go.opentelemetry.io/collector/pdata/pcommon,Apache-2.0,Copyrigh | |
pkg/otlp/metrics,go.opentelemetry.io/collector/pdata/pmetric,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/collector/semconv/v1.6.1,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/attribute,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/baggage,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/codes,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/internal,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/internal/attribute,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/internal/baggage,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/metric,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/metric/embedded,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/metric/noop,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/propagation,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/trace,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/trace/embedded,Apache-2.0,Copyright The OpenTelemetry Authors | ||
pkg/otlp/metrics,go.opentelemetry.io/otel/trace/noop,Apache-2.0,Copyright The OpenTelemetry Authors | ||
|
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.