Skip to content

Commit

Permalink
don't use monitorID dimension if matching meta value
Browse files Browse the repository at this point in the history
  • Loading branch information
rmfitzpatrick committed Apr 28, 2023
1 parent ea2d72b commit c350696
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/receiver/smartagentreceiver/converter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import (
"go.uber.org/zap"
)

const (
monitorIDDim = "monitorID"
)

var (
errUnsupportedMetricTypeTimestamp = fmt.Errorf("unsupported metric type timestamp")
)
Expand Down Expand Up @@ -72,6 +76,15 @@ func setDataTypeAndPoints(datapoint *sfx.Datapoint, ms pmetric.MetricSlice, time
return fmt.Errorf("unsupported value type %T: %v", datapoint.Value, datapoint.Value)
}

// isolated collectd plugins will set the "monitorID" dimension. We need to
// delete this dimension if it matches the meta value to prevent high cardinality values
// (especially a concern with receiver creator that uses endpoint IDs).
if mmID, metaSet := datapoint.Meta[monitorIDDim]; metaSet {
if dmID, dimSet := datapoint.Dimensions[monitorIDDim]; dimSet && dmID == mmID {
delete(datapoint.Dimensions, monitorIDDim)
}
}

switch sfxMetricType {
case sfx.Gauge, sfx.Enum, sfx.Rate:
m = ms.AppendEmpty()
Expand Down
26 changes: 26 additions & 0 deletions pkg/receiver/smartagentreceiver/converter/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,32 @@ func TestDatapointsToPDataMetrics(t *testing.T) {
}(),
expectedMetrics: pdataMetrics(pmetric.MetricTypeGauge, 13, now),
},
{
name: "undesired monitorID dimension",
datapoints: func() []*sfx.Datapoint {
pt := sfxDatapoint()
pt.Meta = map[any]any{"monitorID": "undesired.value"}
pt.Dimensions["monitorID"] = "undesired.value"
return []*sfx.Datapoint{pt}
}(),
expectedMetrics: func() pmetric.Metrics {
return pdataMetrics(pmetric.MetricTypeGauge, 13, now)
}(),
},
{
name: "desired monitorID dimension",
datapoints: func() []*sfx.Datapoint {
pt := sfxDatapoint()
pt.Meta = map[any]any{"monitorID": "undesired.value"}
pt.Dimensions["monitorID"] = "desired.value"
return []*sfx.Datapoint{pt}
}(),
expectedMetrics: func() pmetric.Metrics {
md := pdataMetrics(pmetric.MetricTypeGauge, 13, now)
md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Gauge().DataPoints().At(0).Attributes().PutStr("monitorID", "desired.value")
return md
}(),
},
}

for _, test := range tests {
Expand Down

0 comments on commit c350696

Please sign in to comment.