Skip to content

Commit b3bbd1f

Browse files
SuperQdiscordianfish
authored andcommitted
Sanitize ethtool metric name keys
Apply the same metric name sanitization to the keys as to the metric names. This avoids conflicting help strings in the metric registry. Fixes: #2893 Signed-off-by: Ben Kochie <superq@gmail.com>
1 parent 274cd51 commit b3bbd1f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

collector/ethtool_linux.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,18 +445,19 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
445445
// Sanitizing the metric names can lead to duplicate metric names. Therefore check for clashes beforehand.
446446
metricFQNames := make(map[string]string)
447447
for metric := range stats {
448-
if !c.metricsPattern.MatchString(metric) {
448+
metricName := SanitizeMetricName(metric)
449+
if !c.metricsPattern.MatchString(metricName) {
449450
continue
450451
}
451-
metricFQName := buildEthtoolFQName(metric)
452+
metricFQName := buildEthtoolFQName(metricName)
452453
existingMetric, exists := metricFQNames[metricFQName]
453454
if exists {
454455
level.Debug(c.logger).Log("msg", "dropping duplicate metric name", "device", device,
455-
"metricFQName", metricFQName, "metric1", existingMetric, "metric2", metric)
456-
// Keep the metric as "deleted" in the dict in case there are 3 duplicates.
456+
"metricFQName", metricFQName, "metric1", existingMetric, "metric2", metricName)
457+
// Keep the metricName as "deleted" in the dict in case there are 3 duplicates.
457458
metricFQNames[metricFQName] = ""
458459
} else {
459-
metricFQNames[metricFQName] = metric
460+
metricFQNames[metricFQName] = metricName
460461
}
461462
}
462463

0 commit comments

Comments
 (0)