Skip to content

Do not promote resource attributes when Prometheus resource_constant_labels is empty (#9014) - #9015

Merged
jack-berg merged 1 commit into
open-telemetry:mainfrom
rooks-ns:fix/prometheus-empty-resource-constant-labels
Dec 4, 2026
Merged

jack-berg merged 1 commit into
open-telemetry:mainfrom
rooks-ns:fix/prometheus-empty-resource-constant-labels

Conversation

@rooks-ns

@rooks-ns rooks-ns commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #9014

Problem

In declarative configuration, $defs.IncludeExclude allows an empty object (resource_constant_labels: {}). When parsed, PrometheusComponentProvider unconditionally forwarded (null, null) to IncludeExcludePredicate.createPatternMatching(null, null). Because IncludeExcludePredicate defaults (null, null) to s -> true (match all), this erroneously promoted every resource attribute onto all Prometheus metric time-series instead of none.

Solution

Only register allowedResourceAttributesFilter on the builder when included != null || excluded != null. If both are absent, the builder retains allowedResourceAttributesFilter = null (no-op), ensuring zero resource attributes are converted to metric labels.

Testing

  • Added PrometheusComponentProviderTest covering default behavior, empty {} config, whitelist, blacklist, and validation errors.
  • Added test case to MetricReaderFactoryTest verifying declarative config model parity with empty IncludeExcludeModel.
  • Verified via ./gradlew :exporters:prometheus:check :sdk-extensions:declarative-config:check.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-12-04 17:15 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.50%. Comparing base (e05860a) to head (e8d6d71).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9015   +/-   ##
=========================================
  Coverage     90.50%   90.50%           
- Complexity    11260    11265    +5     
=========================================
  Files          1040     1040           
  Lines         30737    30738    +1     
  Branches       4029     4030    +1     
=========================================
+ Hits          27817    27819    +2     
  Misses         1934     1934           
+ Partials        986      985    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rooks-ns
rooks-ns marked this pull request as ready for review November 7, 2026 05:28
@rooks-ns
rooks-ns requested a review from a team as a code owner November 7, 2026 05:28
@rooks-ns

Copy link
Copy Markdown
Contributor Author

@dashpole PTAL.

@opentelemetry-pr-dashboard

This comment has been minimized.

@jack-berg

Copy link
Copy Markdown
Member

Hey I think the linked issue incorrectly reports a bug and the current behavior is correct. See this comment. Let's hold off on this until we resolve whether or not this is indeed a bug in the linked issue.

@jack-berg jack-berg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We've resolved the blocking issue on #9014 and this can proceed. Just one comment about test coverage being a bit redundant.


@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class PrometheusComponentProviderTest {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we consolidate this coverage into the existing parameterized MetricReaderFactoryTest? It already covers defaults and combined include/exclude filters, and this PR adds the empty-map regression case there. Adding included-only and excluded-only cases would cover all four combinations for the new || condition without a separate test class, mocked configuration, or another port-allocation helper. The name/type and validation tests exercise unchanged behavior. That would also let us drop the added api:incubator test dependency.

@rooks-ns
rooks-ns force-pushed the fix/prometheus-empty-resource-constant-labels branch from 245467d to e8d6d71 Compare December 4, 2026 16:26
@jack-berg
jack-berg merged commit a31ceb7 into open-telemetry:main Dec 4, 2026
34 checks passed
@otelbot

otelbot Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution @rooks-ns! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

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.

PrometheusComponentProvider promotes all resource attributes when resource_constant_labels is empty ({})

2 participants