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

[new feature] logql: extrapolate unwrapped rate function #5013

Merged
merged 4 commits into from
Jan 4, 2022

Conversation

liguozhong
Copy link
Contributor

@liguozhong liguozhong commented Dec 29, 2021

ref issue:#1136
doc: https://grafana.com/docs/loki/latest/logql/metric_queries/
rate function doc: rate(unwrapped-range): calculates per second rate of all values in the specified interval.

logql: rate({_source="vector-internal-metrics" }|json|name="component_received_event_bytes_total"|tags_component_id="service_metrics"|unwrap counter_value [1m])

image

image
image

qps = 20,000 /s

@liguozhong liguozhong requested a review from a team as a code owner December 29, 2021 07:22
@liguozhong
Copy link
Contributor Author

@cyriltovena review pr please

// It calculates the rate (allowing for counter resets if isCounter is true),
// extrapolates if the first/last sample is close to the boundary, and returns
// the result as either per-second (if isRate is true) or overall.
func extrapolatedRate(samples []promql.Point, selRange time.Duration, isCounter, isRate bool) float64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add a comment that this is taken from prometheus code base and where, this can be useful for everyone.

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 ,thanks

@cyriltovena cyriltovena changed the title [new feature] logql:reimplement metrics rate function [new feature] logql:extrapolate unwrapped rate function Jan 3, 2022
@cyriltovena cyriltovena changed the title [new feature] logql:extrapolate unwrapped rate function [new feature] logql: extrapolate unwrapped rate function Jan 3, 2022
[]SelectSampleParams{
{&logproto.SampleQueryRequest{Start: time.Unix(30, 0), End: time.Unix(60, 0), Selector: `rate({app="foo"} | unwrap foo[30s])`}},
},
promql.Vector{promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0.0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}}}},
Copy link
Contributor

@cyriltovena cyriltovena Jan 3, 2022

Choose a reason for hiding this comment

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

it would be better if we could have an example that returns a positive value.

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,thanks!

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

Looking good, left just 2 small comments PTAL

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena
Copy link
Contributor

It might be worth adding a note of this behaviour in the doc,

@cyriltovena cyriltovena merged commit a66e148 into grafana:main Jan 4, 2022
chaudum added a commit that referenced this pull request Jun 9, 2022
This PR reverts the implementation done in #5013 to the original
implementation that sums the extracted values from the log lines instead
of treating them like a Prometheus counter metric.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
chaudum added a commit that referenced this pull request Jun 9, 2022
`rate_counter()` takes an unwrapped range as input, but unlike `rate()`
it treats the values extracted from the log lines as "counter metric"
like in Prometheus' `rate()` function.

This is a replacement for the reverted change of #5013

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
chaudum added a commit that referenced this pull request Jun 10, 2022
This PR reverts the implementation done in #5013 to the original
implementation that sums the extracted values from the log lines instead
of treating them like a Prometheus counter metric.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
chaudum added a commit that referenced this pull request Jun 10, 2022
`rate_counter()` takes an unwrapped range as input, but unlike `rate()`
it treats the values extracted from the log lines as "counter metric"
like in Prometheus' `rate()` function.

This is a replacement for the reverted change of #5013

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
chaudum added a commit that referenced this pull request Jun 14, 2022
This PR reverts the implementation done in #5013 to the original
implementation that sums the extracted values from the log lines instead
of treating them like a Prometheus counter metric.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
chaudum added a commit that referenced this pull request Jun 14, 2022
`rate_counter()` takes an unwrapped range as input, but unlike `rate()`
it treats the values extracted from the log lines as "counter metric"
like in Prometheus' `rate()` function.

This is a replacement for the reverted change of #5013

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
owen-d pushed a commit that referenced this pull request Jun 16, 2022
…counter (#6361)

* Revert unwrapped rate aggregation to previous implementation

This PR reverts the implementation done in #5013 to the original
implementation that sums the extracted values from the log lines instead
of treating them like a Prometheus counter metric.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Move changelog entry

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Remove unused/dead code

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Clean changelog

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
chaudum added a commit that referenced this pull request Jun 16, 2022
`rate_counter()` takes an unwrapped range as input, but unlike `rate()`
it treats the values extracted from the log lines as "counter metric"
like in Prometheus' `rate()` function.

This is a replacement for the reverted change of #5013

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
owen-d pushed a commit that referenced this pull request Jun 16, 2022
`rate_counter()` takes an unwrapped range as input, but unlike `rate()`
it treats the values extracted from the log lines as "counter metric"
like in Prometheus' `rate()` function.

This is a replacement for the reverted change of #5013

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
grafanabot pushed a commit that referenced this pull request Jun 30, 2022
…counter (#6361)

* Revert unwrapped rate aggregation to previous implementation

This PR reverts the implementation done in #5013 to the original
implementation that sums the extracted values from the log lines instead
of treating them like a Prometheus counter metric.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Move changelog entry

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Remove unused/dead code

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Clean changelog

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
(cherry picked from commit b315ed0)
ssncferreira pushed a commit that referenced this pull request Jun 30, 2022
…counter (#6361) (#6555)

* Revert unwrapped rate aggregation to previous implementation

This PR reverts the implementation done in #5013 to the original
implementation that sums the extracted values from the log lines instead
of treating them like a Prometheus counter metric.

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Move changelog entry

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Remove unused/dead code

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>

* Clean changelog

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
(cherry picked from commit b315ed0)

Co-authored-by: Christian Haudum <christian.haudum@gmail.com>
grafanabot pushed a commit that referenced this pull request Jun 30, 2022
`rate_counter()` takes an unwrapped range as input, but unlike `rate()`
it treats the values extracted from the log lines as "counter metric"
like in Prometheus' `rate()` function.

This is a replacement for the reverted change of #5013

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
(cherry picked from commit a56a88b)
ssncferreira added a commit that referenced this pull request Jun 30, 2022
* Add unwrapped aggregation `rate_counter()` (#6412)

`rate_counter()` takes an unwrapped range as input, but unlike `rate()`
it treats the values extracted from the log lines as "counter metric"
like in Prometheus' `rate()` function.

This is a replacement for the reverted change of #5013

Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
(cherry picked from commit a56a88b)

* Update CHANGELOG

Co-authored-by: Christian Haudum <christian.haudum@gmail.com>
Co-authored-by: Susana Ferreira <susana.ferreira@grafana.com>
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