Skip to content

[feat][monitor] PIP-447 for Customizable Prometheus Labels for Topic Metrics#24991

Open
coderzc wants to merge 30 commits intoapache:masterfrom
coderzc:feat_pip_447
Open

[feat][monitor] PIP-447 for Customizable Prometheus Labels for Topic Metrics#24991
coderzc wants to merge 30 commits intoapache:masterfrom
coderzc:feat_pip_447

Conversation

@coderzc
Copy link
Member

@coderzc coderzc commented Nov 16, 2025

PIP: https://github.com/apache/pulsar/blob/master/pip/pip-447.md

Motivation

Modifications

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository:

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 16, 2025
@lhotari lhotari requested a review from Copilot January 2, 2026 14:06
Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

One comment about the usage of PolicyName.MAX_SUBSCRIPTIONS

Copy link
Contributor

Copilot AI left a comment

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 implements PIP-447 to add support for customizable Prometheus labels on topic metrics, allowing operators to attach custom metadata (like SLA tier, team ownership, etc.) to topics that will be exposed as Prometheus labels.

Key changes:

  • Adds customMetricLabels field to TopicPolicies with clone and validation support
  • Implements REST APIs, admin client methods, and CLI commands for managing custom metric labels
  • Integrates custom labels into Prometheus metrics generation in TopicStats
  • Adds configuration options to enable/disable the feature and control allowed label keys and value lengths

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/TopicPolicies.java Adds customMetricLabels field with proper cloning and accessor methods
pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/HierarchyTopicPolicies.java Adds PolicyHierarchyValue for customMetricLabels to support policy hierarchy
pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/TopicPolicies.java Adds API methods for setting, getting, and removing custom metric labels
pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/TopicPoliciesImpl.java Implements client-side REST API calls for custom metric labels operations
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java Adds CLI commands for managing custom metric labels in CmdTopics
pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopicPolicies.java Adds CLI commands for managing custom metric labels in CmdTopicPolicies
pulsar-client-tools/src/test/java/org/apache/pulsar/admin/cli/CmdTopicPoliciesTest.java Adds comprehensive tests for CLI command functionality
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/PersistentTopics.java Adds REST endpoints for custom metric labels operations
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java Implements business logic for setting, getting, and removing custom metric labels with validation
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractTopic.java Updates topic policy loading to include customMetricLabels
pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/TopicStats.java Modifies metrics generation to include custom labels in Prometheus output
pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/NamespaceStatsAggregator.java Retrieves and passes custom metric labels to TopicStats for metrics generation
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java Adds integration tests for custom metric labels feature including validation scenarios
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java Adds three configuration properties for the custom metric labels feature
conf/broker.conf Documents the new configuration properties with examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderzc coderzc marked this pull request as draft January 5, 2026 02:43
…configuration

- Add namespace-level allowed_topic_properties_for_metrics field in Policies.java
- Add admin API methods for set/get/remove allowedTopicPropertiesForMetrics
- Add REST endpoints in Namespaces.java (v2)
- Add CLI commands: set-allowed-topic-properties-for-metrics, get-allowed-topic-properties-for-metrics, remove-allowed-topic-properties-for-metrics
- Integrate with Prometheus metrics generation to merge broker-level and namespace-level configurations
- Add test for namespace-level allowedTopicPropertiesForMetrics
Since PIP-447 now uses topic properties instead of topic policies, this removes:
- TopicPolicies.customMetricLabels field and methods
- HierarchyTopicPolicies.customMetricLabels field
- TopicPolicies admin API methods (set/get/removeCustomMetricLabels)
- CLI commands in CmdTopicPolicies and CmdTopics
- TopicPoliciesImpl implementation
- REST API endpoints in PersistentTopics.java (v2)
- Internal methods in PersistentTopicsBase.java
- References in AbstractTopic.java
- Unit tests in CmdTopicPoliciesTest.java
- Renamed test method in PrometheusMetricsLabelsTest.java
…metrics

- Move logic for fetching and filtering custom metric labels to TopicStats
- Simplify NamespaceStatsAggregator by delegating label handling to TopicStats
- Ensure only allowed topic properties are exposed as custom metric labels
@github-actions github-actions bot added the PIP label Feb 12, 2026
@coderzc coderzc added this to the 4.2.0 milestone Feb 12, 2026
@coderzc coderzc added the type/feature The PR added a new feature or issue requested a new feature label Feb 12, 2026
…cPropertyKeysForMetrics for clarity

Renamed the configuration, variable names, and API methods to use 'PropertyKeys'
instead of 'Properties' to avoid ambiguity between property keys and values.
@coderzc coderzc force-pushed the feat_pip_447 branch 2 times, most recently from 1852a3a to d59fd5a Compare March 6, 2026 05:15
…cPropertyKeysForMetrics for clarity - part 2

Additional fixes:
- PulsarService.java: fix config getter call
- AbstractTopic.java: fix helper method and getter call
- Namespaces.java: fix policies field reference (line 2648)
- NamespacesTest.java: fix test method names and API calls
- PrometheusMetricsLabelsTest.java: fix setter calls
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 86.46865% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.61%. Comparing base (d5145e4) to head (3570243).
⚠️ Report is 24 commits behind head on master.

Files with missing lines Patch % Lines
...n/java/org/apache/pulsar/broker/PulsarService.java 53.84% 8 Missing and 4 partials ⚠️
...ava/org/apache/pulsar/admin/cli/CmdNamespaces.java 40.00% 9 Missing ⚠️
.../org/apache/pulsar/broker/admin/v2/Namespaces.java 66.66% 8 Missing ⚠️
...rg/apache/pulsar/broker/service/AbstractTopic.java 83.87% 2 Missing and 3 partials ⚠️
...che/pulsar/broker/stats/prometheus/TopicStats.java 95.41% 2 Missing and 3 partials ⚠️
...g/apache/pulsar/common/policies/data/Policies.java 50.00% 0 Missing and 1 partial ⚠️
...e/pulsar/client/admin/internal/NamespacesImpl.java 98.52% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #24991       +/-   ##
=============================================
+ Coverage     29.94%   72.61%   +42.66%     
- Complexity      107    34591    +34484     
=============================================
  Files          1899     1968       +69     
  Lines        151150   156120     +4970     
  Branches      17230    17783      +553     
=============================================
+ Hits          45269   113369    +68100     
+ Misses        98854    33705    -65149     
- Partials       7027     9046     +2019     
Flag Coverage Δ
inttests 25.62% <4.95%> (-0.03%) ⬇️
systests 22.31% <4.29%> (+<0.01%) ⬆️
unittests 73.59% <86.46%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...org/apache/pulsar/broker/ServiceConfiguration.java 98.24% <100.00%> (+3.21%) ⬆️
...he/pulsar/broker/resources/NamespaceResources.java 78.08% <100.00%> (+30.25%) ⬆️
...pache/pulsar/broker/admin/impl/NamespacesBase.java 77.90% <100.00%> (+63.45%) ⬆️
...rg/apache/pulsar/broker/service/BrokerService.java 83.72% <100.00%> (+39.45%) ⬆️
...ker/stats/prometheus/NamespaceStatsAggregator.java 94.51% <100.00%> (+94.51%) ⬆️
...ava/org/apache/pulsar/client/admin/Namespaces.java 66.66% <ø> (+66.66%) ⬆️
...apache/pulsar/common/policies/data/PolicyName.java 100.00% <100.00%> (ø)
...g/apache/pulsar/common/policies/data/Policies.java 59.66% <50.00%> (+16.07%) ⬆️
...e/pulsar/client/admin/internal/NamespacesImpl.java 97.74% <98.52%> (+89.42%) ⬆️
...rg/apache/pulsar/broker/service/AbstractTopic.java 88.21% <83.87%> (+24.77%) ⬆️
... and 4 more

... and 1501 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/metrics doc-not-needed Your PR changes do not impact docs PIP ready-to-test type/feature The PR added a new feature or issue requested a new feature type/PIP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants