Skip to content

kafka_consumer: cache earliest offsets across collection intervals#24515

Merged
piochelepiotr merged 4 commits into
masterfrom
piotr.wolski/kafka-consumer-cache-earliest-offsets
Jul 15, 2026
Merged

kafka_consumer: cache earliest offsets across collection intervals#24515
piochelepiotr merged 4 commits into
masterfrom
piotr.wolski/kafka-consumer-cache-earliest-offsets

Conversation

@piochelepiotr

Copy link
Copy Markdown
Contributor

What does this PR do?

Caches the per-partition earliest (log-start) offset used to compute kafka.topic.size and kafka.partition.size, instead of refetching it from the broker on every collection interval. The cache TTL is derived from the broker's log.retention.check.interval.ms config when available, clamped to [60s, 1800s], defaulting to 300s.

Motivation

The earliest offset only moves forward via the broker's log-cleaner cycle, so refetching it every check run adds unnecessary ListOffsets load on the broker without the value ever changing between cleaner cycles. Caching it across runs, with a TTL tied to that cycle, removes that redundant load while keeping the reported values accurate.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add qa/required if this PR needs QA validation, or qa/skip-qa if it does not. Exactly one of the two is required.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

Log start offsets only move via the broker's log-cleaner cycle
(log.retention.check.interval.ms), so refetching them on every check
run is unnecessary broker load. Cache the result with a TTL derived
from that broker config, clamped to a sane range.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@piochelepiotr
piochelepiotr marked this pull request as ready for review July 10, 2026 21:22
@piochelepiotr
piochelepiotr requested a review from a team as a code owner July 10, 2026 21:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 491f476b33

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread kafka_consumer/datadog_checks/kafka_consumer/cluster_metadata.py Outdated
Comment thread kafka_consumer/datadog_checks/kafka_consumer/cluster_metadata.py Outdated
@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Jul 10, 2026

Copy link
Copy Markdown

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 86.59%
Overall Coverage: 92.01%

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 3150cf3 | Docs | Datadog PR Page | Give us feedback!

…sing partitions on a fresh cache

log.retention.check.interval.ms is now read from broker config data purely to
derive the earliest-offsets cache TTL, without being added to the metric
emission list. fetch_earliest_offsets also now refetches from the broker when
a fresh cache doesn't cover every requested partition (e.g. newly added
partitions), while keeping the cache's original expiration.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@piochelepiotr
piochelepiotr added this pull request to the merge queue Jul 15, 2026
Merged via the queue into master with commit 7be739d Jul 15, 2026
45 of 48 checks passed
@piochelepiotr
piochelepiotr deleted the piotr.wolski/kafka-consumer-cache-earliest-offsets branch July 15, 2026 21:25
@dd-octo-sts dd-octo-sts Bot added this to the 7.83.0 milestone Jul 15, 2026
@temporal-github-worker-1

Copy link
Copy Markdown

Backport evaluation: View Slack thread

@dd-octo-sts

dd-octo-sts Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Validation Report

All 21 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and code coverage settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
qa-label Validate the pull request declares whether it needs QA for the next Agent release
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

nubtron pushed a commit that referenced this pull request Jul 17, 2026
…24515) (#24575)

* kafka_consumer: cache earliest offsets across collection intervals

Log start offsets only move via the broker's log-cleaner cycle
(log.retention.check.interval.ms), so refetching them on every check
run is unnecessary broker load. Cache the result with a TTL derived
from that broker config, clamped to a sane range.



* Add changelog entry



* kafka_consumer: trim redundant comments, add earliest-offsets cache test



* Address review feedback: avoid an undocumented metric and refetch missing partitions on a fresh cache

log.retention.check.interval.ms is now read from broker config data purely to
derive the earliest-offsets cache TTL, without being added to the metric
emission list. fetch_earliest_offsets also now refetches from the broker when
a fresh cache doesn't cover every requested partition (e.g. newly added
partitions), while keeping the cache's original expiration.



---------


(cherry picked from commit 7be739d)

Co-authored-by: Piotr WOLSKI <piotr.wolski42@gmail.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants