kafka_consumer: keep earliest-offsets cache when some partitions fail to fetch #25668
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
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.352
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #25668"
general
weight: 0.35
HadhemiDD
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_offsetsonly 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 legacyenable_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: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
test_fetch_earliest_offsets_persistent_failure_keeps_cache_for_healthy_partitionsinkafka_consumer/tests/test_cluster_metadata.py. Fails on master (second run refetches every partition), passes here.test_fetch_earliest_offsets_refetches_when_cache_missing_partitionsnow also asserts only the missing partition is requested and the merged map is saved. Also fails on master.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
🤖 Generated with Claude Code