Skip to content

Commit

Permalink
don't use monitorID dimension if matching meta value (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmfitzpatrick authored Apr 28, 2023
1 parent 2f6cfce commit 98a27fa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -29,7 +28,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -45,7 +43,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -58,7 +55,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -72,7 +68,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand Down Expand Up @@ -102,7 +97,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand Down Expand Up @@ -145,7 +139,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand Down Expand Up @@ -187,7 +180,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand Down Expand Up @@ -217,7 +209,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -226,7 +217,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -237,7 +227,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -246,7 +235,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -255,7 +243,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -266,7 +253,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -278,7 +264,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -287,7 +272,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -296,7 +280,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -305,7 +288,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -314,23 +296,20 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
- name: mysql_octets.rx
type: IntMonotonicCumulativeSum
attributes:
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
- name: mysql_octets.tx
type: IntMonotonicCumulativeSum
attributes:
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -339,7 +318,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -348,7 +326,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -357,7 +334,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -366,7 +342,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -375,7 +350,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -384,7 +358,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -393,7 +366,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -402,7 +374,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -411,7 +382,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -420,7 +390,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -429,7 +398,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -438,7 +406,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -447,7 +414,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -456,7 +422,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -465,7 +430,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -474,7 +438,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -483,7 +446,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -492,7 +454,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -501,7 +462,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -526,7 +486,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand All @@ -535,7 +494,6 @@ resource_metrics:
attributes:
dsname: value
host: <ANY>
monitorID: smartagentcollectdmysql
plugin: mysql
plugin_instance: _testdb
system.type: mysql
Expand Down

0 comments on commit 98a27fa

Please sign in to comment.