Skip to content

Commit

Permalink
Fixes suspected duplicate label panic for some GCP metric
Browse files Browse the repository at this point in the history
Metric like `istio.io/control` were failing because `mesh_id` and some other labels were added multiple times
  • Loading branch information
gideshrp1JL committed Apr 20, 2022
1 parent 96baa4c commit 440868f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 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 !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 !keyExists(labelKeys, key) {
labelKeys = append(labelKeys, key)
labelValues = append(labelValues, value)
}
}

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

func keyExists(labelKeys []string, key string) bool {
for _, item := range labelKeys {
if item == key {
return true
}
}
return false
}

0 comments on commit 440868f

Please sign in to comment.