Don't return negative offset lags except for -1 when -1001 is the high watermark#406
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modifies the consumer lag calculation logic to handle edge cases with watermark offsets. The changes prevent returning negative offset lags by introducing validation for the high watermark offset and clamping calculated lag values to zero when they would otherwise be negative.
Key Changes:
- Added validation to skip lag calculation when high watermark is the invalid sentinel value (-1001)
- Introduced clamping logic to ensure offset lag values are never negative
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| offsetLag_ = offsetLag_ > 0 ? offsetLag_ : 0; | ||
| offsetLagLow_ = offsetLagLow_ > 0 ? offsetLagLow_ : 0; |
There was a problem hiding this comment.
The ternary condition uses > 0 which excludes zero lag as a valid value. This should use >= 0 to preserve zero lag, or the logic should clamp negative values: offsetLag_ = Math.max(0, offsetLag_) to be clearer about the intent.
| offsetLag_ = offsetLag_ > 0 ? offsetLag_ : 0; | |
| offsetLagLow_ = offsetLagLow_ > 0 ? offsetLagLow_ : 0; | |
| offsetLag_ = Math.max(0, offsetLag_); | |
| offsetLagLow_ = Math.max(0, offsetLagLow_); |
There was a problem hiding this comment.
considered that but don't want to involve the additional call for this simple logic.
Pratyush Ranjan (PratRanj07)
left a comment
There was a problem hiding this comment.
LGTM!
No description provided.