diff --git a/collectors/monitoring_collector.go b/collectors/monitoring_collector.go index 5f6f1698..7d11b51a 100644 --- a/collectors/monitoring_collector.go +++ b/collectors/monitoring_collector.go @@ -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 { @@ -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 +}