Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[datadogexporter] Add logging for unknown or unsupported metric types #3421

Merged
merged 2 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exporter/datadogexporter/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (exp *metricsExporter) PushMetricsData(ctx context.Context, md pdata.Metric
}

fallbackHost := metadata.GetHost(exp.params.Logger, exp.cfg)
ms, _ := mapMetrics(exp.cfg.Metrics, exp.prevPts, fallbackHost, md)
ms, _ := mapMetrics(exp.params.Logger, exp.cfg.Metrics, exp.prevPts, fallbackHost, md)
metrics.ProcessMetrics(ms, exp.cfg)

err := exp.client.PostMetrics(ms)
Expand Down
8 changes: 5 additions & 3 deletions exporter/datadogexporter/metrics_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"go.opentelemetry.io/collector/consumer/pdata"
"go.uber.org/zap"
"gopkg.in/zorkian/go-datadog-api.v2"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/attributes"
Expand Down Expand Up @@ -250,7 +251,7 @@ func mapHistogramMetrics(name string, slice pdata.HistogramDataPointSlice, bucke
}

// mapMetrics maps OTLP metrics into the DataDog format
func mapMetrics(cfg config.MetricsConfig, prevPts *ttlmap.TTLMap, fallbackHost string, md pdata.Metrics) (series []datadog.Metric, droppedTimeSeries int) {
func mapMetrics(logger *zap.Logger, cfg config.MetricsConfig, prevPts *ttlmap.TTLMap, fallbackHost string, md pdata.Metrics) (series []datadog.Metric, droppedTimeSeries int) {
pushTime := uint64(time.Now().UTC().UnixNano())
rms := md.ResourceMetrics()
for i := 0; i < rms.Len(); i++ {
Expand Down Expand Up @@ -282,8 +283,6 @@ func mapMetrics(cfg config.MetricsConfig, prevPts *ttlmap.TTLMap, fallbackHost s
md := metricsArray.At(k)
var datapoints []datadog.Metric
switch md.DataType() {
case pdata.MetricDataTypeNone:
continue
case pdata.MetricDataTypeIntGauge:
datapoints = mapIntMetrics(md.Name(), md.IntGauge().DataPoints(), attributeTags)
case pdata.MetricDataTypeDoubleGauge:
Expand All @@ -304,6 +303,9 @@ func mapMetrics(cfg config.MetricsConfig, prevPts *ttlmap.TTLMap, fallbackHost s
datapoints = mapIntHistogramMetrics(md.Name(), md.IntHistogram().DataPoints(), cfg.Buckets, attributeTags)
case pdata.MetricDataTypeHistogram:
datapoints = mapHistogramMetrics(md.Name(), md.Histogram().DataPoints(), cfg.Buckets, attributeTags)
default: // pdata.MetricDataTypeNone or any other not supported type
logger.Debug("Unknown or unsupported metric type", zap.String("metric name", md.Name()), zap.Any("data type", md.DataType()))
continue
}

for i := range datapoints {
Expand Down
12 changes: 10 additions & 2 deletions exporter/datadogexporter/metrics_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/consumer/pdata"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest/observer"
"gopkg.in/zorkian/go-datadog-api.v2"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config"
Expand Down Expand Up @@ -534,7 +537,7 @@ func TestRunningMetrics(t *testing.T) {
cfg := config.MetricsConfig{}
prevPts := newTTLMap()

series, _ := mapMetrics(cfg, prevPts, "fallbackHostname", ms)
series, _ := mapMetrics(zap.NewNop(), cfg, prevPts, "fallbackHostname", ms)

runningHostnames := []string{}

Expand Down Expand Up @@ -685,7 +688,9 @@ func testCount(name string, val float64) datadog.Metric {
func TestMapMetrics(t *testing.T) {
md := createTestMetrics()
cfg := config.MetricsConfig{SendMonotonic: true}
series, dropped := mapMetrics(cfg, newTTLMap(), "", md)
core, observed := observer.New(zapcore.DebugLevel)
testLogger := zap.New(core)
series, dropped := mapMetrics(testLogger, cfg, newTTLMap(), "", md)
assert.Equal(t, dropped, 0)
filtered := removeRunningMetrics(series)
assert.ElementsMatch(t, filtered, []datadog.Metric{
Expand All @@ -700,4 +705,7 @@ func TestMapMetrics(t *testing.T) {
testCount("int.cumulative.sum", 3),
testCount("double.cumulative.sum", math.Pi),
})

// One metric was unknown or unsupported
assert.Equal(t, observed.FilterMessage("Unknown or unsupported metric type").Len(), 1)
}