Skip to content

Commit

Permalink
Fixes suspected duplicate label panic for some GCP metric (#153)
Browse files Browse the repository at this point in the history
* Fixes suspected duplicate label panic for some GCP metric

Metric like `istio.io/control` were failing because `mesh_id` and some other labels were added multiple times

Co-authored-by: Gidesh Pampingal <gidesh.pampingal@johnlewis.co.uk>
  • Loading branch information
gidesh and gideshrp1JL authored Apr 22, 2022
1 parent bf280ee commit df5aae7
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions collectors/monitoring_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,19 @@ func (c *MonitoringCollector) reportTimeSeriesMetrics(
// Add the metric labels
// @see https://cloud.google.com/monitoring/api/metrics
for key, value := range timeSeries.Metric.Labels {
labelKeys = append(labelKeys, key)
labelValues = append(labelValues, value)
if !c.keyExists(labelKeys, key) {
labelKeys = append(labelKeys, key)
labelValues = append(labelValues, value)
}
}

// Add the monitored resource labels
// @see https://cloud.google.com/monitoring/api/resources
for key, value := range timeSeries.Resource.Labels {
labelKeys = append(labelKeys, key)
labelValues = append(labelValues, value)
if !c.keyExists(labelKeys, key) {
labelKeys = append(labelKeys, key)
labelValues = append(labelValues, value)
}
}

if c.monitoringDropDelegatedProjects {
Expand Down Expand Up @@ -506,3 +510,13 @@ func (c *MonitoringCollector) generateHistogramBuckets(
}
return buckets, nil
}

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
}
}
return false
}

0 comments on commit df5aae7

Please sign in to comment.