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

[generator] Insert leading zero value for new counter series #2068

Merged
merged 6 commits into from
Feb 8, 2023

Conversation

zalegrala
Copy link
Contributor

@zalegrala zalegrala commented Feb 3, 2023

What this PR does:

Here we allow new values on counter series to be used by Prometehus by inserting a leading 0 into new counter series.

Which issue(s) this PR fixes:
Fixes #2006

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@zalegrala zalegrala changed the title Remote write counter0 [generator] Insert leading zero value for new counter series Feb 3, 2023
@zalegrala zalegrala force-pushed the remoteWriteCounter0 branch 2 times, most recently from 272f86a to b6cc556 Compare February 6, 2023 18:59
New counters are created with null values, which causes Prometheus to
ignore the first value to avoid the comparison of null -> x.  Here we
allow for first values on new series to be more useful by appending
first a zero to the series, followed by a value.  This will allow
Prometheus queries to use the first value of 0 -> x rather than null ->
x.
Signed-off-by: Zach Leslie <[email protected]>
@zalegrala zalegrala force-pushed the remoteWriteCounter0 branch from b6cc556 to dcff162 Compare February 7, 2023 17:45
@zalegrala zalegrala marked this pull request as ready for review February 7, 2023 17:45
Copy link
Member

@yvrhdn yvrhdn left a comment

Choose a reason for hiding this comment

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

Looks good overall, just left some comments. Nothing blocking from me.

Comment on lines +150 to +155
_, err = appender.Append(0, lb.Labels(nil), timeMs, 0)
if err != nil {
return
}
// Increment timeMs to ensure that the next value is not at the same time.
t = t.Add(insertOffsetDuration)
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we could just do timeMs - 1000. Instead of delaying our sample, write a zero sample before it. This might trigger out-of-order writes though... I'm not sure if Prometheus checks for out-of-order writes within the whole batch or just for the serie.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered about this also, but avoided going negative offset because I wasn't sure about the interplay with Prometheus and was somewhat hard to test. Do you think this will impact the usage having a delay on our sample?

Copy link
Member

Choose a reason for hiding this comment

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

It adds latency between when the span arrived and when we report it has arrived, so the data becomes more inaccurate. But since we already aggregate data in the collection interval (which is typically 15s) I don't think this will be significant. So I'm fine with going for the safe options and just adding a 1s offset.

@zalegrala zalegrala merged commit ad935d9 into grafana:main Feb 8, 2023
@zalegrala zalegrala deleted the remoteWriteCounter0 branch February 8, 2023 17:56
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.

Initialise stale counter series at 0
2 participants