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

feat: TraceQL metrics: average over time #4073

Merged
merged 31 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
03a3886
add avg_over_time to TraceQL metrics
javiermolinar Sep 12, 2024
cd722d9
fix test
javiermolinar Sep 12, 2024
bbc96e6
wording
javiermolinar Sep 12, 2024
4b68942
fix test
javiermolinar Sep 12, 2024
6421f9a
Merge branch 'main' into avg-over-time
javiermolinar Oct 7, 2024
67c0111
new average engine
javiermolinar Oct 10, 2024
18583d7
added missed method
javiermolinar Oct 10, 2024
700f21b
fix tests
javiermolinar Oct 10, 2024
378999a
added exemplars
javiermolinar Oct 17, 2024
afe513f
fix tests
javiermolinar Oct 17, 2024
0691946
fix another test
javiermolinar Oct 17, 2024
f55b1db
use constants
javiermolinar Oct 21, 2024
3c5e2f0
unexport structs and methods
javiermolinar Oct 21, 2024
0cf9dfb
refactor getSeries
javiermolinar Oct 21, 2024
86476fb
avoid out of index errors
javiermolinar Oct 21, 2024
8922940
fix combine
javiermolinar Oct 22, 2024
8cbd722
include compensation
javiermolinar Oct 24, 2024
26d3908
use incremental weighted mean
javiermolinar Oct 29, 2024
85dd9c1
fix panic
javiermolinar Oct 29, 2024
a859d3f
drop NaN count series to match average ones
javiermolinar Oct 29, 2024
e82b56d
refactor code
javiermolinar Oct 30, 2024
cbf4042
refactor code
javiermolinar Oct 30, 2024
f5e9c71
some improvements
javiermolinar Oct 30, 2024
9e94c26
fix bug with nil string
javiermolinar Oct 30, 2024
63c291a
Merge branch 'main' into avg-over-time
javiermolinar Oct 31, 2024
350ac40
doc changes
javiermolinar Oct 31, 2024
ab24abc
Update docs/sources/tempo/traceql/metrics-queries/functions.md
javiermolinar Oct 31, 2024
2c104d5
Update docs/sources/tempo/traceql/metrics-queries/functions.md
javiermolinar Oct 31, 2024
80e36d9
Update docs/sources/tempo/traceql/metrics-queries/functions.md
javiermolinar Oct 31, 2024
924b27b
Update docs/sources/tempo/traceql/metrics-queries/_index.md
javiermolinar Oct 31, 2024
057299c
Update docs/sources/tempo/traceql/metrics-queries/functions.md
javiermolinar Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/sources/tempo/traceql/metrics-queries/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Refer to [Solve problems using metrics queries](./solve-problems-metrics-queries

### Functions

TraceQL metrics queries currently include the following functions for aggregating over groups of spans: `rate`, `count_over_time`, `quantile_over_time`, `histogram_over_time`, and `compare`.
TraceQL metrics queries currently include the following functions for aggregating over groups of spans: `rate`, `count_over_time`, `max_over_time`, `min_over_time`, `avg_over_time`, `quantile_over_time`, `histogram_over_time`, and `compare`.
These functions can be added as an operator at the end of any TraceQL query.

For detailed information and example queries for each function, refer to [TraceQL metrics functions](./functions).
Expand Down
22 changes: 19 additions & 3 deletions docs/sources/tempo/traceql/metrics-queries/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords:

<!-- If you add a new function to this page, make sure you also add it to the _index.md#functions section.-->

TraceQL supports `rate`, `count_over_time`, `quantile_over_time`, `histogram_over_time`, and `compare` functions.
TraceQL supports `rate`, `count_over_time`, `min_over_time`, `avg_over_time`, `quantile_over_time`, `histogram_over_time`, and `compare` functions.

## Available functions

Expand All @@ -30,6 +30,9 @@ These functions can be added as an operator at the end of any TraceQL query.
`max_over_time`
: Returns the minimum value for the specified attribute across all matching spans per time interval (refer to the [`step` API parameter](https://grafana.com/docs/tempo/<TEMPO_VERSION>/api_docs/#traceql-metrics)).

`avg_over_time`
: Returns the average value for the specified attribute across all matching spans per time interval (refer to the [`step` API parameter](https://grafana.com/docs/tempo/<TEMPO_VERSION>/api_docs/#traceql-metrics)).

`quantile_over_time`
: The quantile of the values in the specified interval

Expand Down Expand Up @@ -94,7 +97,7 @@ This example counts the number of spans with name `"GET /:endpoint"` broken down

```

## The `min_over_time` and `max_over_time` functions
## The `min_over_time`, `max_over_time`, and `avg_over_time` functions

The `min_over_time()` function lets you aggregate numerical attributes by calculating their minimum value.
For example, you could choose to calculate the minimum duration of a group of spans, or you could choose to calculate the minimum value of a custom attribute you've attached to your spans, like `span.shopping.cart.entries`.
Expand All @@ -103,11 +106,14 @@ The time interval that the minimum is computed over is set by the `step` paramet
The `max_over_time()` let you aggregate numerical values by computing the maximum value of them, such as the all important span duration.
The time interval that the maximum is computer over is set by the `step` parameter.

The `avg_over_time()` function lets you aggregate numerical values by computing the maximum value of them, such as the all important span duration.
The time interval that the maximum is computer over is set by the `step` parameter.

For more information, refer to the [`step` API parameter](https://grafana.com/docs/tempo/<TEMPO_VERSION>/api_docs/#traceql-metrics).

### Parameters

Numerical field that you want to calculate the minimum or maximum of.
Numerical field that you want to calculate the minimum, maximum, or average of.

### Examples

Expand All @@ -134,6 +140,16 @@ This example computes the maximum duration for each `http.target` of all spans n
{ name = "GET /:endpoint" } | max_over_time(span.http.response.size)
```

This example computes the average duration for each `http.status_code` of all spans named `"GET /:endpoint"`.

```
{ name = "GET /:endpoint" } | avg_over_time(duration) by (span.http.status_code)
```

```
{ name = "GET /:endpoint" } | avg_over_time(span.http.response.size)
```

## The `quantile_over_time` and `histogram_over_time` functions

The `quantile_over_time()` and `histogram_over_time()` functions let you aggregate numerical values, such as the all important span duration.
Expand Down
10 changes: 7 additions & 3 deletions pkg/traceql/engine_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
)

const (
internalLabelMetaType = "__meta_type"
internalMetaTypeCount = "__count"
internalLabelBucket = "__bucket"
maxExemplars = 100
maxExemplarsPerBucket = 2
Expand Down Expand Up @@ -176,10 +178,12 @@ func (ls Labels) String() string {
promValue = "<nil>"
case l.Value.Type == TypeString:
s := l.Value.EncodeToString(false)
if s != "" {
promValue = s
} else {
if s == "nil" {
promValue = "<nil>"
} else if s == "" {
promValue = "<empty>"
} else {
promValue = s
}
default:
promValue = l.Value.EncodeToString(false)
Expand Down
Loading