← Back to Pull requests

kafka_consumer: keep earliest-offsets cache when some partitions fail to fetch #25668

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 18:00 UTC
Author

What does this PR do?

Fixes the earliest-offsets TTL cache in kafka_consumer (added in #24515) so it keeps working when some partitions' earliest offsets cannot be read.

What's wrong


fetch_earliest_offsets only used the cache when it held every requested partition. Unreadable partitions are never cached, so a single one forced a full refetch on every run. With Kafka Console enabled (enable_kafka_console: true, or legacy enable_cluster_monitoring: true), the Agent then sends ListOffsets(EARLIEST) for every partition each check run (15 s default) instead of once per TTL (60 to 1800 s, 5 min default), roughly doubling ListOffsets load on the brokers. Triggers:
  • an offline partition (no leader) or a per-partition ListOffsets error

  • Windows x64 (Agent 7.84.0+) with a log-start offset above 2^31, which comes back negative and is discarded since #24814
  • Nothing is visible in Datadog: metrics and Kafka Console stay correct.

    Introduced in 7be739df3c (#24515), shipped in kafka_consumer 9.0.0 through 9.2.1 (Agent 7.83.0 through 7.84.3).

    Fix


    When the cache is fresh but incomplete, only the uncached partitions are requested from the broker. The results are merged into the cached map and saved under the original expire_at. Metric names, tags and config do not change. Unreadable partitions are still retried every run.

    | | Before | After |
    |---|---|---|
    | Earliest-offset requests with one partition unreadable | All partitions, every run | Unreadable ones each run, all once per TTL |
    | Log, offline partition | Failed to fetch earliest offset for 1/N partitions | ... for 1/1 partitions |

    Test


  • New test_fetch_earliest_offsets_persistent_failure_keeps_cache_for_healthy_partitions in kafka_consumer/tests/test_cluster_metadata.py. Fails on master (second run refetches every partition), passes here.

  • test_fetch_earliest_offsets_refetches_when_cache_missing_partitions now also asserts only the missing partition is requested and the merged map is saved. Also fails on master.

  • kafka_consumer unit suite (pytest tests -m unit): 176 passed. E2E not run.
  • Motivation

    Makes the earliest-offsets cache from #24515 deliver its reduced broker load on clusters where a partition stays unreadable.

    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: 357 lines (+267 / -90) across 4 files Reviewer: HadhemiDD Review duration: 6947m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 357 lines diff across 4 files
    0.43
    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.352
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #25668"
    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.6% (MEDIUM) · Higher = larger blast radius
    42.6%
    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.8% · Safe to merge
    16.8%