Skip to content

Commit

Permalink
Logql/absent label optimization (#3299)
Browse files Browse the repository at this point in the history
* absent_over_time does not extract unnecessary labels

* rebase fix
  • Loading branch information
owen-d authored Feb 9, 2021
1 parent b848ac5 commit 5f0c06a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/logql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func (r rangeAggregationExpr) extractor(override *grouping) (log.SampleExtractor
}
}

// absent_over_time cannot be grouped (yet?), so set noLabels=true
// to make extraction more efficient and less likely to strip per query series limits.
if r.operation == OpRangeTypeAbsent {
noLabels = true
}

sort.Strings(groups)

var stages []log.Stage
Expand Down
36 changes: 36 additions & 0 deletions pkg/logql/log/parser_hints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,48 @@ func Test_ParserHints(t *testing.T) {
15.0,
`{Ingester_TotalBatches="0", Ingester_TotalChunksMatched="0", caller="spanlogger.go:79", traceID="2e5c7234b8640997", ts="2021-02-02T14:35:05.983992774Z"}`,
},
{
`sum(rate({app="nginx"} | json | remote_user="foo" [1m]))`,
jsonLine,
true,
1.0,
`{}`,
},
{
`sum(rate({app="nginx"} | json | nonexistant_field="foo" [1m]))`,
jsonLine,
false,
0,
``,
},
{
`absent_over_time({app="nginx"} | json [1m])`,
jsonLine,
true,
1.0,
`{}`,
},
{
`absent_over_time({app="nginx"} | json | nonexistant_field="foo" [1m])`,
jsonLine,
false,
0,
``,
},
{
`absent_over_time({app="nginx"} | json | remote_user="foo" [1m])`,
jsonLine,
true,
1.0,
`{}`,
},
} {
tt := tt
t.Run(tt.expr, func(t *testing.T) {
t.Parallel()
expr, err := logql.ParseSampleExpr(tt.expr)
require.NoError(t, err)

ex, err := expr.Extractor()
require.NoError(t, err)
v, lbsRes, ok := ex.ForStream(lbs).Process(tt.line)
Expand Down

0 comments on commit 5f0c06a

Please sign in to comment.