← Back to Pull requests

Stop creating a Kafka consumer on every run just to read cluster_id #25667

Closed
unknown closed this pull request without merging on Oct 21, 2026 13:47 UTC
View on GitHub
unknown unknown commented on Oct 16, 2026 17:52 UTC
Author

What does this PR do?

On every run that collects highwater offsets, kafka_consumer creates a second Kafka client (a librdkafka Consumer, group datadog-agent), fetches full cluster metadata again, and closes it, only to read cluster_id. The AdminClient metadata that _run_check refreshes at the start of each run already contains it.

This adds KafkaClient.get_cluster_id(), which reads cluster_id from that AdminClient metadata, and removes the unused Consumer code. Metrics, tags and kafka_cluster_id values 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_consumer 8.1.0+) with consumer_groups, consumer_groups_regex, monitor_unlisted_consumer_groups: true, or Kafka Console enabled. With the default close_admin_client: true each run pays an extra connection and handshake (worse with TLS, SASL or MSK IAM); locally about 54 ms per run on one plaintext broker. With close_admin_client: false only the duplicate metadata request remains. Introduced in #24263.

Test: test_highwater_collection_reads_cluster_id_without_a_consumer in kafka_consumer/tests/test_unit.py runs two real check cycles with the real KafkaClient, faking only the librdkafka classes. It asserts no Consumer is created, one Metadata request per run, and kafka.broker_offset carries the AdminClient's cluster_id. It fails on master and passes here. test_client_init, which asserted open_consumer was 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_kbytes only 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

  • I self-reviewed the full diff, and this description matches the final change

  • Tests cover the change, or this description explains why none are needed

  • Automated review comments, including Codex review, were addressed or answered

  • I, the human author, understand this change, can explain it to reviewers, and believe it meets the repository standards
  • 🤖 Generated with Claude Code

    Diff: 342 lines (+256 / -86) across 4 files Reviewer: HadhemiDD Review duration: 6954m
    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
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.3% (MEDIUM) · Higher = larger blast radius
    42.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%