Skip to content

fix: fixes duplicated labels - #400

Open
shk1999 wants to merge 2 commits into
prometheus-community:masterfrom
shk1999:develop
Open

shk1999 wants to merge 2 commits into
prometheus-community:masterfrom
shk1999:develop

Conversation

@shk1999

@shk1999 shk1999 commented Sep 22, 2025 •

Copy link
Copy Markdown

This commit fixes the metric conflicts
#394

in my case, the json_exporter could not resolve the /api/v1/alerts of prometheus instances due to a lot of duplicated labels (e.g. value, annotations, alertname, etc)

@shk1999
shk1999 force-pushed the develop branch 4 times, most recently from c5153e3 to abd4dc2 Compare October 1, 2025 06:31
Signed-off-by: shk1999 <shayan000karimi@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Prometheus “duplicate metric collected” conflicts by detecting repeated label sets during ObjectScrape collection and skipping duplicate samples so a scrape can complete successfully.

Changes:

  • Adds per-metric duplicate detection for ObjectScrape results using a seen set keyed by extracted label values.
  • Skips emitting metrics whose label set has already been emitted during the same metric collection loop and logs a message when skipping.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread exporter/collector.go
Comment on lines +99 to +101
if _, exists := seen[labelKey]; exists {
mc.Logger.Warn("Skipping duplicate metric with identical labels", "metric", m.Desc, "labels", fmt.Sprintf("%v", labels))
continue
Comment thread exporter/collector.go
Comment on lines +97 to +103
labels := extractLabels(mc.Logger, jdata, m.LabelsJSONPaths)
labelKey := strings.Join(labels, "\x00")
if _, exists := seen[labelKey]; exists {
mc.Logger.Warn("Skipping duplicate metric with identical labels", "metric", m.Desc, "labels", fmt.Sprintf("%v", labels))
continue
}
seen[labelKey] = struct{}{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants