Skip to content

feat(kafka): add MessageBroker/Kafka/Cluster/{id}/Topic/{topic} metrics#1747

Draft
shashank-reddy-nr wants to merge 4 commits into
newrelic:mainfrom
shashank-reddy-nr:feat/kafka-cluster-id
Draft

feat(kafka): add MessageBroker/Kafka/Cluster/{id}/Topic/{topic} metrics#1747
shashank-reddy-nr wants to merge 4 commits into
newrelic:mainfrom
shashank-reddy-nr:feat/kafka-cluster-id

Conversation

@shashank-reddy-nr

@shashank-reddy-nr shashank-reddy-nr commented Jun 1, 2026

Copy link
Copy Markdown

What

Adds per-cluster, per-topic throughput metrics using the Kafka cluster UUID.

New metrics:

  MessageBroker/Kafka/Cluster/{cluster_id}/Topic/{topic}/Produce
  MessageBroker/Kafka/Cluster/{cluster_id}/Topic/{topic}/Consume

NRQL

SELECT sum(newrelic.timeslice.value) FROM Metric
WHERE metricTimesliceName LIKE 'MessageBroker/Kafka/Cluster%'
FACET appName, metricTimesliceName SINCE 30 minutes ago

Before contributing, please read our contributing guidelines and code of conduct.

Overview

Describe the changes present in the pull request

Related Github Issue

Include a link to the related GitHub issue, if applicable

Testing

The agent includes a suite of tests which should be used to
verify your changes don't break existing functionality. These tests will run with
Github Actions when a pull request is made. More details on running the tests locally can be found in our
testing guidelines,
For most contributions it is strongly recommended to add additional tests which
exercise your changes.

@shashank-reddy-nr shashank-reddy-nr requested a review from a team as a code owner June 1, 2026 10:44
@shashank-reddy-nr shashank-reddy-nr marked this pull request as draft June 1, 2026 10:52
@mergify mergify Bot added the tests-failing Tests failing in CI. label Jun 1, 2026
@codecov-commenter

codecov-commenter commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.50485% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.96%. Comparing base (949339a) to head (c322bd5).
⚠️ Report is 40 commits behind head on main.

Files with missing lines Patch % Lines
newrelic/hooks/messagebroker_confluentkafka.py 57.89% 25 Missing and 15 partials ⚠️
newrelic/hooks/messagebroker_kafkapython.py 73.87% 14 Missing and 15 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1747      +/-   ##
==========================================
- Coverage   82.08%   81.96%   -0.12%     
==========================================
  Files         215      215              
  Lines       26309    26792     +483     
  Branches     4150     4260     +110     
==========================================
+ Hits        21596    21961     +365     
- Misses       3301     3352      +51     
- Partials     1412     1479      +67     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mergify mergify Bot removed the tests-failing Tests failing in CI. label Jun 1, 2026
@hmstepanek hmstepanek self-requested a review June 1, 2026 22:10
@mergify mergify Bot added tests-failing Tests failing in CI. and removed tests-failing Tests failing in CI. labels Jun 4, 2026
@shashank-reddy-nr shashank-reddy-nr marked this pull request as ready for review June 15, 2026 17:10
@mergify mergify Bot added the tests-failing Tests failing in CI. label Jun 21, 2026
Records per-cluster Kafka metrics (MessageBroker/Kafka/Cluster/{clusterId}/Topic/{topic}/Produce
and MessageBroker/Kafka/Cluster/{clusterId}/Topic/{topic}/Consume) to let customers track
throughput broken out by Kafka cluster, not just by topic. The cluster ID is fetched
once per unique broker set via a background AdminClient call; the hot produce/consume path
has no additional overhead. The feature is always-on and best-effort — it does not inject
anything into Kafka wire headers and does not add span or custom attributes.

Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@shashank-reddy-nr shashank-reddy-nr marked this pull request as draft June 22, 2026 20:26
…aches

Both hooks now store (cluster_id, time.monotonic()) tuples and trigger a
background re-fetch on expiry, returning the stale value in the meantime.
Also handles describe_cluster() returning a dict (newer kafka-python-ng).

Assisted-by: Claude Sonnet 4.6
…unit

Ruff E702 (multiple statements on one line) and I001 (unsorted imports)
flagged the inline `import time; time.sleep(...)` patterns. Moving the
import to the module-level import block is the correct fix.

Assisted-by: Claude Sonnet 4.6
The hook stores cluster IDs as (str, float) tuples for stale-while-revalidate
TTL tracking. Three test files seeded _kafka_cluster_id_cache with plain
strings, so isinstance(_cached, tuple) was False and metrics were never
recorded — causing test_cluster_produce_metric, test_cluster_consume_metric,
and test_cluster_id_written_to_cache_on_success to fail.

- test_producer.py / test_consumer.py: seed with (id, time.monotonic()) tuple;
  add missing import time
- test_cluster_metrics_unit.py: same for key-preservation and resolved-entry
  fixtures; fix assertion to check cached[0] instead of comparing full tuple
  to a bare string

Assisted-by: Claude Sonnet 4.6
@mergify mergify Bot removed the tests-failing Tests failing in CI. label Jun 28, 2026
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.

2 participants