Stats callback in promisified api#399
Merged
Emanuele Sabellico (emasab) merged 2 commits intomasterfrom Nov 11, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enables statistics callback support in the promisified API for all client types (Producer, Consumer, and Admin). Previously, stats callbacks were only available in the non-promisified API. The implementation moves background polling setup from Producer to the base Connection class, allowing all client types to receive statistics events.
Key Changes:
- Refactored
SetPollInBackgroundfrom Producer-specific to Connection base class - Added stats callback configuration and event handling for Producer, Consumer, and Admin clients
- Added comprehensive test coverage for stats callbacks across all three client types
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/connection.h | Added SetPollInBackground method declaration and m_is_background_polling field to base Connection class |
| src/connection.cc | Implemented SetPollInBackground method in Connection class with background polling queue management |
| src/producer.h | Changed to use inherited SetPollInBackground from Connection class |
| src/producer.cc | Removed Producer-specific SetPollInBackground implementation and m_is_background_polling field |
| src/admin.cc | Added automatic background polling activation when statistics interval is configured |
| lib/kafkajs/_producer.js | Added stats callback extraction, storage, and event listener registration |
| lib/kafkajs/_consumer.js | Added stats callback extraction, storage, and event listener registration |
| lib/kafkajs/_admin.js | Added stats callback extraction, storage, and event listener registration |
| test/promisified/producer/statsCallback.spec.js | Added test verifying Producer receives stats callbacks |
| test/promisified/consumer/statsCallback.spec.js | Added test verifying Consumer receives stats callbacks |
| test/promisified/admin/statsCallback.spec.js | Added test verifying Admin receives stats callbacks |
| CHANGELOG.md | Documented new statistics callback feature for promisified API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
22990aa to
fc56b7e
Compare
Pratyush Ranjan (PratRanj07)
approved these changes
Nov 11, 2025
Contributor
Pratyush Ranjan (PratRanj07)
left a comment
There was a problem hiding this comment.
Thanks for the PR Emanuele Sabellico (@emasab) . LGTM
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Statistics callback is available when using the promisified API with all client types.
Note for the reviewers:
SetPollInBackgroundis moved to the Connection base class, false by default and it's public only on the Producer where it's possible to chose if polling externally. For the AdminClient it's enabled only if thestatistics.interval.msis set as the main reply queue wasn't polled.Checklist
statistics.interval.mstogether with thestats_cband receive the statistics