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 24 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
15 changes: 14 additions & 1 deletion docs/sources/tempo/traceql/metrics-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ These functions can be added as an operator at the end of any TraceQL query.
`max_over_time`
: Returns the maximum value of matching spans values per time interval (see the `step` API parameter)

`avg_over_time`
: Returns the average value of matching spans values per time interval (see the `step` API parameter)

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

Expand Down Expand Up @@ -97,7 +100,7 @@ down by HTTP route.
This might let you determine that `/api/sad` had a higher rate of erroring
spans than `/api/happy`, for example.

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

The `count_over_time()` let you counts the number of matching spans per time interval.
knylander-grafana marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -128,6 +131,16 @@ The `max_over_time()` let you aggregate numerical values by computing the maximu
{ name = "GET /:endpoint" } | max_over_time(span.http.status_code)
```

The `avg_over_time()` let you aggregate numerical values by computing the average value of them, such as the all important span duration.
javiermolinar marked this conversation as resolved.
Show resolved Hide resolved

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

```
{ name = "GET /:endpoint" } | avg_over_time(event:cpu_seconds_tota)
```

### 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