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] Deduplicate hosts for which we send running metrics #3539

Merged
merged 2 commits into from
May 27, 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
14 changes: 9 additions & 5 deletions exporter/datadogexporter/metrics_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func mapHistogramMetrics(name string, slice pdata.HistogramDataPointSlice, bucke
func mapMetrics(logger *zap.Logger, cfg config.MetricsConfig, prevPts *ttlmap.TTLMap, fallbackHost string, md pdata.Metrics, buildInfo component.BuildInfo) (series []datadog.Metric, droppedTimeSeries int) {
pushTime := uint64(time.Now().UTC().UnixNano())
rms := md.ResourceMetrics()
seenHosts := make(map[string]struct{})
for i := 0; i < rms.Len(); i++ {
rm := rms.At(i)

Expand All @@ -270,11 +271,7 @@ func mapMetrics(logger *zap.Logger, cfg config.MetricsConfig, prevPts *ttlmap.TT
if !ok {
host = fallbackHost
}

// Report the host as running
runningMetric := metrics.DefaultMetrics("metrics", host, pushTime, buildInfo)

series = append(series, runningMetric...)
seenHosts[host] = struct{}{}

ilms := rm.InstrumentationLibraryMetrics()
for j := 0; j < ilms.Len(); j++ {
Expand Down Expand Up @@ -317,5 +314,12 @@ func mapMetrics(logger *zap.Logger, cfg config.MetricsConfig, prevPts *ttlmap.TT
}
}
}

for host := range seenHosts {
// Report the host as running
runningMetric := metrics.DefaultMetrics("metrics", host, pushTime, buildInfo)
series = append(series, runningMetric...)
}

return
}
2 changes: 1 addition & 1 deletion exporter/datadogexporter/metrics_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func TestRunningMetrics(t *testing.T) {

assert.ElementsMatch(t,
runningHostnames,
[]string{"fallbackHostname", "resource-hostname-1", "resource-hostname-1", "resource-hostname-2"},
[]string{"fallbackHostname", "resource-hostname-1", "resource-hostname-2"},
)

}
Expand Down
14 changes: 9 additions & 5 deletions exporter/datadogexporter/translate_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,27 @@ func convertToDatadogTd(td pdata.Traces, fallbackHost string, cfg *config.Config

var traces []*pb.TracePayload

var runningMetrics []datadog.Metric
seenHosts := make(map[string]struct{})
var series []datadog.Metric
pushTime := pdata.TimestampFromTime(time.Now())
for i := 0; i < resourceSpans.Len(); i++ {
rs := resourceSpans.At(i)
host, ok := metadata.HostnameFromAttributes(rs.Resource().Attributes())
if !ok {
host = fallbackHost
}

seenHosts[host] = struct{}{}
payload := resourceSpansToDatadogSpans(rs, host, cfg, blk)
traces = append(traces, &payload)
}

ms := metrics.DefaultMetrics("traces", host, uint64(pushTime), buildInfo)
runningMetrics = append(runningMetrics, ms...)
for host := range seenHosts {
// Report the host as running
runningMetric := metrics.DefaultMetrics("traces", host, uint64(pushTime), buildInfo)
series = append(series, runningMetric...)
}

return traces, runningMetrics
return traces, series
}

func aggregateTracePayloadsByEnv(tracePayloads []*pb.TracePayload) []*pb.TracePayload {
Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/translate_traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestRunningTraces(t *testing.T) {

assert.ElementsMatch(t,
runningHostnames,
[]string{"resource-hostname-1", "resource-hostname-1", "resource-hostname-2", "fallbackHost"},
[]string{"resource-hostname-1", "resource-hostname-2", "fallbackHost"},
)
}

Expand Down