Skip to content

Commit

Permalink
Add log to capture the duplicate label if it exists in a metric
Browse files Browse the repository at this point in the history
As suggested in PR

Signed-off-by: Gidesh Pampingal <gidesh.pampingal@johnlewis.co.uk>
  • Loading branch information
gideshrp1JL committed Apr 21, 2022
1 parent b427f24 commit 9f54b7d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions collectors/monitoring_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func (c *MonitoringCollector) reportTimeSeriesMetrics(
// Add the metric labels
// @see https://cloud.google.com/monitoring/api/metrics
for key, value := range timeSeries.Metric.Labels {
if !keyExists(labelKeys, key) {
if !c.keyExists(labelKeys, key) {
labelKeys = append(labelKeys, key)
labelValues = append(labelValues, value)
}
Expand All @@ -398,7 +398,7 @@ func (c *MonitoringCollector) reportTimeSeriesMetrics(
// Add the monitored resource labels
// @see https://cloud.google.com/monitoring/api/resources
for key, value := range timeSeries.Resource.Labels {
if !keyExists(labelKeys, key) {
if !c.keyExists(labelKeys, key) {
labelKeys = append(labelKeys, key)
labelValues = append(labelValues, value)
}
Expand Down Expand Up @@ -511,9 +511,10 @@ func (c *MonitoringCollector) generateHistogramBuckets(
return buckets, nil
}

func keyExists(labelKeys []string, key string) bool {
func (c *MonitoringCollector) keyExists(labelKeys []string, key string) bool {
for _, item := range labelKeys {
if item == key {
level.Debug(c.logger).Log("msg", "Found duplicate label key", "key", key)
return true
}
}
Expand Down

0 comments on commit 9f54b7d

Please sign in to comment.