Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Aug 5, 2024
1 parent 99fc408 commit 01db3dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 13 additions & 2 deletions pkg/otlp/metrics/kafka_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import (
"go.opentelemetry.io/collector/pdata/pmetric"
)

// kafkaMetricsToRename is a map of kafka metrics that should be renamed.
var kafkaMetricsToRename = map[string]bool{
"kafka.producer.request-rate": true,
"kafka.producer.response-rate": true,
"kafka.producer.request-latency-avg": true,
"kafka.consumer.fetch-size-avg": true,
"kafka.producer.compression-rate": true,
"kafka.producer.record-retry-rate": true,
"kafka.producer.record-send-rate": true,
"kafka.producer.record-error-rate": true,
}

// Note: `-` get converted into `_` which will result in some OTel and DD metric
// having the same name. In order to prevent duplicate stats, prepend by `otel.`
// in these cases.
Expand Down Expand Up @@ -430,8 +442,7 @@ func remapJvmMetrics(all pmetric.MetricSlice, m pmetric.Metric) {

// renameKafkaMetrics renames otel kafka metrics to avoid conflicts with DD metrics.
func renameKafkaMetrics(m pmetric.Metric) {
switch m.Name() {
case "kafka.producer.request-rate", "kafka.producer.response-rate", "kafka.producer.request-latency-avg", "kafka.consumer.fetch-size-avg", "kafka.producer.compression-rate", "kafka.producer.record-retry-rate", "kafka.producer.record-send-rate", "kafka.producer.record-error-rate":
if _, ok := kafkaMetricsToRename[m.Name()]; ok {
m.SetName("otel." + m.Name())
}
}
10 changes: 5 additions & 5 deletions pkg/otlp/metrics/metrics_remapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,16 +787,16 @@ func TestRemapAndRenameMetrics(t *testing.T) {
remapMetrics(dest, tt.in)
// Ensure remapMetrics does not add the otel.* prefix to the metric name
if checkprefix {
require.False(t, strings.HasPrefix(tt.in.Name(), "otel."), "system.* and process.* and a subset of kafka metrics need to be prepended with the otel.* namespace")
}
require.Equal(t, dest.Len()-lena, len(tt.out), "unexpected number of metrics added")
for i, out := range tt.out {
assert.NoError(t, pmetrictest.CompareMetric(out, dest.At(dest.Len()-len(tt.out)+i)))
require.False(t, strings.HasPrefix(tt.in.Name(), "otel."), "remapMetrics should not add the otel.* prefix to the metric name, it should only compute Datadog metrics")
}
renameMetrics(tt.in)
if checkprefix {
require.True(t, strings.HasPrefix(tt.in.Name(), "otel."), "system.* and process.* and a subset of kafka metrics need to be prepended with the otel.* namespace")
}
require.Equal(t, dest.Len()-lena, len(tt.out), "unexpected number of metrics added")
for i, out := range tt.out {
assert.NoError(t, pmetrictest.CompareMetric(out, dest.At(dest.Len()-len(tt.out)+i)))
}
}

}
Expand Down

0 comments on commit 01db3dc

Please sign in to comment.