Skip to content

Commit

Permalink
Sanitize ethtool metric name keys
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
SuperQ authored and discordianfish committed Mar 21, 2024
1 parent 274cd51 commit b3bbd1f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions collector/ethtool_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,18 +445,19 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
// Sanitizing the metric names can lead to duplicate metric names. Therefore check for clashes beforehand.
metricFQNames := make(map[string]string)
for metric := range stats {
if !c.metricsPattern.MatchString(metric) {
metricName := SanitizeMetricName(metric)
if !c.metricsPattern.MatchString(metricName) {
continue
}
metricFQName := buildEthtoolFQName(metric)
metricFQName := buildEthtoolFQName(metricName)
existingMetric, exists := metricFQNames[metricFQName]
if exists {
level.Debug(c.logger).Log("msg", "dropping duplicate metric name", "device", device,
"metricFQName", metricFQName, "metric1", existingMetric, "metric2", metric)
// Keep the metric as "deleted" in the dict in case there are 3 duplicates.
"metricFQName", metricFQName, "metric1", existingMetric, "metric2", metricName)
// Keep the metricName as "deleted" in the dict in case there are 3 duplicates.
metricFQNames[metricFQName] = ""
} else {
metricFQNames[metricFQName] = metric
metricFQNames[metricFQName] = metricName
}
}

Expand Down

0 comments on commit b3bbd1f

Please sign in to comment.