Skip to content

fix(kafka): exclude retention-deleted messages from lag for uncommitted offsets - #7937

Open
Nikko-Foti wants to merge 1 commit into
kedacore:mainfrom
Nikko-Foti:fix/kafka-earliest-lag-retention
Open

fix(kafka): exclude retention-deleted messages from lag for uncommitted offsets#7937
Nikko-Foti wants to merge 1 commit into
kedacore:mainfrom
Nikko-Foti:fix/kafka-earliest-lag-retention

Conversation

@Nikko-Foti

@Nikko-Foti Nikko-Foti commented Jul 27, 2026

Copy link
Copy Markdown

Kafka consumer groups with no committed offset on a partition were scaled on the partition's full log end offset when offsetResetPolicy: earliest, counting messages retention had already deleted. Idle workloads were held at the topic's partition count as a result.

Lag is now logEndOffset - logStartOffset, i.e. what a consumer starting from earliest can actually fetch. Earliest offsets are requested only for partitions lacking a committed offset, so there is no extra broker traffic for latest, for scaleToZeroOnInvalidOffset: true, or for fully committed groups. A failed request logs and falls back to the previous value rather than failing the poll.

Alternative considered: returning 1 for earliest, matching the latest branch. Avoids the extra request but under-reports a genuine retained backlog.

Two unit cases were added for the new math and the fallback.

Checklist

  • When introducing a new scaler, I agree with the scaling governance policy
  • I have verified that my change is according to the deprecations & breaking changes policy
  • Tests have been added (if applicable)
  • Ensure make generate-scalers-schema has been run to update any outdated generated files
  • Changelog has been updated and is aligned with our changelog requirements, only when the change impacts end users
  • A PR is opened to update our Helm chart (repo) (if applicable, ie. when deployment manifests are modified)
  • A PR is opened to update the documentation on (repo) (if applicable)
  • Commits are signed with Developer Certificate of Origin (DCO - learn more)

Fixes #7936

Relates to kedacore/keda-docs#1825

…ed offsets

Consumer groups with no committed offset under offsetResetPolicy: earliest
were scaled on the partition's full log end offset, counting messages that
retention had already deleted and that no consumer could ever read. Idle
workloads were held at the partition count as a result.

Lag is now measured from the log start offset, so it reflects what a
consumer starting from earliest can actually fetch. The earliest offsets
are fetched only for partitions that lack a committed offset, and a failed
fetch falls back to the previous behavior.

Signed-off-by: Nikko Foti <nfoti201@gmail.com>
@Nikko-Foti
Nikko-Foti requested a review from a team as a code owner July 27, 2026 21:02
@snyk-io

snyk-io Bot commented Jul 27, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! 🙏

Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected.

While you are waiting, make sure to:

  • Add an entry in our changelog in alphabetical order and link related issue
  • Update the documentation, if needed
  • Add unit & e2e tests for your changes
  • GitHub checks are passing
  • Is the DCO check failing? Here is how you can fix DCO issues

Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient.

Learn more about our contribution guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kafka scaler counts retention-deleted messages as lag when offsetResetPolicy: earliest and a partition has no committed offset

1 participant