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.
Issue
The main goal of this PR is to add the ability for
kprom
plugin to differentiate between multiple clients.The current implementation of the
WithClientLabel()
option in the kprom package assigns metrics to the most recently registered kgo client, which leads to metrics being grouped under a static client_id. The goal is to keep the existing API but make theclient_id
label dynamic, allowing it to reflect the actual client making the request rather than being statically set at first registration (see twmb#815).Only a subset of metrics will be affected by this change:
write_bytes_total
write_errors_total
write_wait_seconds
write_time_seconds
read_bytes_total
read_errors_total
read_time_seconds
request_duration_e2e_seconds
request_throttled_seconds
produce_compressed_bytes_total
produce_(uncompressed_)bytes_total
produce_batches_total
produce_records_total
fetch_compressed_bytes_total
fetch_(uncompressed_)bytes_total
fetch_batches_total
fetch_records_total
Metrics that will continue to have a constant
client_id
:connects_total
connect_errors_total
disconnects_total
buffered_fetch_records_total
buffered_produce_records_total
Testing
I tested the updated metrics locally using a combination of consumers and producers. When scraping Prometheus, the metrics are now properly separated by the client_id label, even when writing to and reading from the same topic using different client IDs for two producers and consumers:
Implementation
Since
kgo
doesn’t exportclient_id
in a way that supports dynamic labeling in hooks, I had to make some modifications to the core library. My goal was to minimize changes to the kgo package itself and to avoid breaking any existing APIs (such as hooks). To that end, I chose not to add dynamic labels to the connection and buffered metrics, keeping those labels static.