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 1 commit
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
6 changes: 5 additions & 1 deletion 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 @@ -304,6 +305,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:
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
5 changes: 3 additions & 2 deletions exporter/datadogexporter/metrics_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/stretchr/testify/assert"
"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/config"
Expand Down Expand Up @@ -534,7 +535,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 +686,7 @@ 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)
series, dropped := mapMetrics(zap.NewNop(), cfg, newTTLMap(), "", md)
assert.Equal(t, dropped, 0)
filtered := removeRunningMetrics(series)
assert.ElementsMatch(t, filtered, []datadog.Metric{
Expand Down