-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improve][client] Add OpenTelemetry metrics for client memory buffer usage #24647
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
Merged
codelipenghui
merged 1 commit into
apache:master
from
codelipenghui:feature/add-client-memory-buffer-metrics
Aug 20, 2025
Merged
[improve][client] Add OpenTelemetry metrics for client memory buffer usage #24647
codelipenghui
merged 1 commit into
apache:master
from
codelipenghui:feature/add-client-memory-buffer-metrics
Aug 20, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit introduces new OpenTelemetry metrics to monitor the memory buffer usage in Pulsar Java clients, providing visibility into producer memory consumption. New metrics: - pulsar.client.memory.buffer.usage: Current memory usage in bytes - pulsar.client.memory.buffer.limit: Configured memory limit in bytes Key features: - Metrics are only created when memory limiting is enabled (memoryLimitBytes > 0) - Zero overhead when memory limiting is disabled - Follows existing OpenTelemetry patterns in the codebase - Observable metrics that automatically report current values Implementation: - Add ObservableUpDownCounter class for callback-based metrics - Add MemoryBufferStats to manage memory buffer metrics - Extend InstrumentProvider with observable counter support - Add memoryLimit() method to MemoryLimitController for metric access - Conditional metrics creation in PulsarClientImpl Testing: - Comprehensive unit tests with InMemoryMetricReader - Integration tests covering enabled/disabled scenarios - End-to-end testing with real broker interactions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
Documentation is added by apache/pulsar-site#1032 |
dao-jun
approved these changes
Aug 20, 2025
merlimat
approved these changes
Aug 20, 2025
manas-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Sep 12, 2025
…usage (apache#24647) (cherry picked from commit a66e806) (cherry picked from commit 02a7bbc)
srinath-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Sep 12, 2025
…usage (apache#24647) (cherry picked from commit a66e806) (cherry picked from commit 02a7bbc)
KannarFr
pushed a commit
to CleverCloud/pulsar
that referenced
this pull request
Sep 22, 2025
walkinggo
pushed a commit
to walkinggo/pulsar
that referenced
this pull request
Oct 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area/client
area/metrics
cherry-picked/branch-4.0
doc-complete
Your PR changes impact docs and the related docs have been already added.
ready-to-test
type/enhancement
The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds OpenTelemetry metrics to expose the status of the producer memory buffer defined by
producerMemoryLimitin the Java client. This provides visibility into memory usage and helps with monitoring and alerting on client-side memory consumption.Motivation
Currently, there's no way to monitor the memory buffer usage of Pulsar Java clients. Users cannot:
Changes
New Metrics
Two new OpenTelemetry metrics are added:
pulsar.client.memory.buffer.usage(bytes)pulsar.client.memory.buffer.limit(bytes)Key Features
memoryLimitBytes > 0)Implementation Details
ObservableUpDownCounterclass that extends existing metrics infrastructureMemoryBufferStatsclass manages the observable metricsInstrumentProviderwith observable counter supportmemoryLimit()method toMemoryLimitControllerfor metric accessPulsarClientImplUsage Example
The metrics will be available as:
Testing
MemoryBufferStatsTestwithInMemoryMetricReaderto verify metric valuesClientMetricsTestwith real broker to test end-to-end behaviorVerifying this change
Backward Compatibility
Documentation
docdoc-requireddoc-not-neededdoc-complete