Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes suspected duplicate label panic for some GCP metric #153

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}