Stop creating a Kafka consumer on every run just to read cluster_id #25667
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 342 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.349
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #25667"
general
weight: 0.35
HadhemiDD
What does this PR do?
On every run that collects highwater offsets,
kafka_consumercreates a second Kafka client (a librdkafkaConsumer, groupdatadog-agent), fetches full cluster metadata again, and closes it, only to readcluster_id. The AdminClient metadata that_run_checkrefreshes at the start of each run already contains it.This adds
KafkaClient.get_cluster_id(), which readscluster_idfrom that AdminClient metadata, and removes the unused Consumer code. Metrics, tags andkafka_cluster_idvalues do not change.| | Before | After |
|---|---|---|
| Kafka clients per run (default config) | AdminClient plus a Consumer created and closed every run | AdminClient only |
| Full cluster metadata requests per run | 2 | 1 |
| Run fails if the extra metadata request fails | Yes, no offsets or lag for that run | Not possible |
Impact: Agent 7.82.0+ (
kafka_consumer8.1.0+) withconsumer_groups,consumer_groups_regex,monitor_unlisted_consumer_groups: true, or Kafka Console enabled. With the defaultclose_admin_client: trueeach run pays an extra connection and handshake (worse with TLS, SASL or MSK IAM); locally about 54 ms per run on one plaintext broker. Withclose_admin_client: falseonly the duplicate metadata request remains. Introduced in #24263.Test:
test_highwater_collection_reads_cluster_id_without_a_consumerinkafka_consumer/tests/test_unit.pyruns two real check cycles with the realKafkaClient, faking only the librdkafka classes. It asserts no Consumer is created, one Metadata request per run, andkafka.broker_offsetcarries the AdminClient'scluster_id. It fails on master and passes here.test_client_init, which assertedopen_consumerwas called, is removed. Unit suite: 175 passed; integration (noauth, Confluent 7.3.0): 38 passed.Motivation
The Consumer added connection churn, run time and a failure path without giving the check anything new.
consumer_queued_max_messages_kbytesonly configured that Consumer, so it no longer has any effect; deprecating it is left for a follow-up. Changelog:kafka_consumer/changelog.d/25667.fixed.Checklist before requesting review
🤖 Generated with Claude Code