Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reset handling by checking against previous value instead of reset value. #263

Merged
merged 4 commits into from
Jan 12, 2021

Conversation

jkschulz
Copy link
Contributor

@jkschulz jkschulz commented Jan 11, 2021

There's been a bug in reset handling (since inception) that detects a reset by checking if the current value is less than the initial/reset value, when it should be detecting drops by comparing against the previous value instead. For example, if a series receives values 4->10->6, the existing code will not detect a reset when the value drops from 10 to 6 (even though it should), because 6 </ 4. It would only detect a reset if the data were e.g. 4->10->3, because 3<4.

Further, this meant that the sidecar could allow at most one reset per time series (so long as it stayed in the cache), because after one reset, the baseline resetValue was set to 0, and that was what all subsequent values were compared against to identify resets. Since Prometheus counters can't be negative, no additional resets could occur (0 </ 0).


Related bugs (internal access only):

@google-cla google-cla bot added the cla: yes label Jan 11, 2021
@jkschulz jkschulz requested a review from a team January 11, 2021 23:51
@jkschulz jkschulz requested review from a team and igorpeshansky and removed request for a team January 12, 2021 00:49
Copy link
Member

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

Beautiful.

LGTM :shipit: modulo one minor formatting comment.

// Value of the most recent point seen for the time series. If a new value is
// less than the previous, then the series has reset.
previousValue float64

hasReset bool
resetValue float64
resetTimestamp int64
Copy link
Member

Choose a reason for hiding this comment

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

Want to take the opportunity to add a blank line after this one? Or is this how the auto-formatter chose to format it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea -- added some additional comments too

Copy link
Member

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

LGTM :shipit: modulo one grammar nit.

hasReset bool

// The value and timestamp of the latest reset. The timestamp is when it
// occurred and the value is what it was reset to. resetValue will initially
Copy link
Member

Choose a reason for hiding this comment

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

Grammar nit: need a comma before the "and".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants