Skip to content

otlptranslator: filter __name__ from OTLP attributes to prevent duplicates#17917

Merged
aknuds1 merged 2 commits intoprometheus:mainfrom
aknuds1:fix/otlp-duplicate-name-label
Jan 24, 2026
Merged

otlptranslator: filter __name__ from OTLP attributes to prevent duplicates#17917
aknuds1 merged 2 commits intoprometheus:mainfrom
aknuds1:fix/otlp-duplicate-name-label

Conversation

@aknuds1
Copy link
Contributor

@aknuds1 aknuds1 commented Jan 22, 2026

Which issue(s) does the PR fix:

OTLP metrics with a __name__ attribute may create duplicate __name__ labels.

Does this PR introduce a user-facing change?

Description

In data point handlers, all calls to createAttributes pass nil for ignoreAttrs, allowing __name__ attributes from OTLP data to pass through. Since __name__ is also added via the extras parameter, this creates duplicate labels.

This PR adds a reservedLabelNames slice and updates all data point handlers to filter these reserved labels:

  • addGaugeNumberDataPoints
  • addSumNumberDataPoints
  • addHistogramDataPoints
  • addSummaryDataPoints
  • addExponentialHistogramDataPoints
  • addCustomBucketsHistogramDataPoints

Includes regression tests verifying that only one __name__ label exists and the correct metric name is used.

[BUGFIX] OTLP: Filter `__name__` from OTLP attributes to prevent duplicate labels

Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

Oh wow, did you see that actually happening? 😱

Either way, it's a good bugfix. LGTM! Just one small suggestion

@aknuds1
Copy link
Contributor Author

aknuds1 commented Jan 24, 2026

Oh wow, did you see that actually happening? 😱

@ArthurSens No, it's just a defensive fix. Mainly to rule out the OTLP translation as a possible cause of this type of bug.

…cates

OTLP metrics can have a __name__ attribute which, when combined with the
metric name passed via extras, creates duplicate __name__ labels. This
causes TSDB compaction failures with errors like:

    corruption detected when writing postings to index: label "__name__"
    has 7479 uses, but maxPostings is 7477

The fix filters reserved label names (currently just __name__) from OTLP
attributes in all data point handlers: gauge, sum, histogram, exponential
histogram, custom buckets histogram, and summary.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@aknuds1 aknuds1 force-pushed the fix/otlp-duplicate-name-label branch from bbfcbae to a885ef0 Compare January 24, 2026 14:46
Add a subtest to TestPrometheusConverter_createAttributes to verify that
__type__ and __unit__ attributes in OTLP data are correctly overwritten by
auto-generated labels from metadata when EnableTypeAndUnitLabels is enabled.

Also rename TestCreateAttributes to TestPrometheusConverter_createAttributes
for consistency, and move TestOTLPNameAttributeFiltered into a subtest.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@aknuds1 aknuds1 force-pushed the fix/otlp-duplicate-name-label branch from a885ef0 to 24ccb57 Compare January 24, 2026 14:50
@aknuds1 aknuds1 requested a review from ArthurSens January 24, 2026 14:54
Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

LGTM

@aknuds1 aknuds1 merged commit 2332962 into prometheus:main Jan 24, 2026
32 checks passed
@aknuds1 aknuds1 deleted the fix/otlp-duplicate-name-label branch January 24, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants