-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
add group_{left,right} to LogQL #4510
Changes from 1 commit
e6cf282
a3e2379
60b5550
b6419dd
22c6d04
96a6e98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Code generated by vfsgen; DO NOT EDIT. | ||
|
||
//go:build !dev | ||
// +build !dev | ||
|
||
package ui | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -163,6 +163,23 @@ This example will return every machine total count within the last minutes ratio | |||||
sum by(machine) (count_over_time({app="foo"}[1m])) / on() sum(count_over_time({app="foo"}[1m])) | ||||||
``` | ||||||
|
||||||
### Many-to-one and one-to-many vector matches | ||||||
Many-to-one and one-to-many matchings refer to the case where each vector element on the "one"-side can match with multiple elements on the "many"-side. This has to be explicitly requested using the group_left or group_right modifier, where left/right determines which vector has the higher cardinality. | ||||||
The syntax: | ||||||
```logql | ||||||
<vector expr> <bin-op> ignoring(<labels>) group_left(<labels>) <vector expr> | ||||||
<vector expr> <bin-op> ignoring(<labels>) group_right(<labels>) <vector expr> | ||||||
<vector expr> <bin-op> on(<labels>) group_left(<labels>) <vector expr> | ||||||
<vector expr> <bin-op> on(<labels>) group_right(<labels>) <vector expr> | ||||||
``` | ||||||
The label list provided with the group modifier contains additional labels from the "one"-side to be included in the result metrics. For on a label can only appear in one of the lists. Every time series of the result vector must be uniquely identifiable. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify the sentence that starts "For on a label..." What does that mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <vector expr> <bin-op> on(<labels>) group_right(<labels>) <vector expr> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved |
||||||
Grouping modifiers can only be used for comparison and arithmetic. Operations as and, unless and or operations match with all possible entries in the right vector by default. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible wording below for the sentence starting with "Operations as..." "By default, the system matches There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
|
||||||
This example will return sum results for the same app with the many part labels and the labels specified by group_right in the one side. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update wording to: "The following example returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
```logql | ||||||
sum by (app,pool) (count_over_time({foo="bar"}[1m])) + on (app) group_right (pool) sum by (app,machine) (count_over_time({foo="bar"}[1m])) | ||||||
``` | ||||||
|
||||||
## Comments | ||||||
|
||||||
LogQL queries can be commented using the `#` character: | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -537,9 +537,7 @@ func TestEngine_LogsInstantQuery(t *testing.T) { | |||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `count_over_time({app="foo"}[1m])`}}, | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `count_over_time({app="bar"}[1m])`}}, | ||||||
}, | ||||||
promql.Vector{ | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}}}, | ||||||
}, | ||||||
promql.Vector{}, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the fix! |
||||||
}, | ||||||
{ | ||||||
`sum without(app) (count_over_time({app="foo"}[1m])) > bool sum without(app) (count_over_time({app="bar"}[1m]))`, | ||||||
|
@@ -554,9 +552,7 @@ func TestEngine_LogsInstantQuery(t *testing.T) { | |||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum without (app) (count_over_time({app="foo"}[1m]))`}}, | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum without (app) (count_over_time({app="bar"}[1m]))`}}, | ||||||
}, | ||||||
promql.Vector{ | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{}}, | ||||||
}, | ||||||
promql.Vector{}, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the fix! |
||||||
}, | ||||||
{ | ||||||
`sum without(app) (count_over_time({app="foo"}[1m])) >= sum without(app) (count_over_time({app="bar"}[1m]))`, | ||||||
|
@@ -649,7 +645,24 @@ func TestEngine_LogsInstantQuery(t *testing.T) { | |||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app) (count_over_time({app="foo"}[1m]))`}}, | ||||||
}, | ||||||
promql.Vector{ | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 120}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "fuzz"}}}, | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 120}, Metric: labels.Labels{}}, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||||||
}, | ||||||
}, | ||||||
{ | ||||||
`sum by (app,machine) (count_over_time({app="foo"}[1m])) + on (app) sum by (app) (count_over_time({app="foo"}[1m]))`, | ||||||
time.Unix(60, 0), | ||||||
logproto.FORWARD, | ||||||
0, | ||||||
[][]logproto.Series{ | ||||||
{newSeries(testSize, identity, `{app="foo",machine="fuzz"}`)}, | ||||||
{newSeries(testSize, identity, `{app="foo"}`)}, | ||||||
}, | ||||||
[]SelectSampleParams{ | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app,machine) (count_over_time({app="foo"}[1m]))`}}, | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app) (count_over_time({app="foo"}[1m]))`}}, | ||||||
}, | ||||||
promql.Vector{ | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 120}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}}}, | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
|
@@ -666,7 +679,7 @@ func TestEngine_LogsInstantQuery(t *testing.T) { | |||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app) (count_over_time({app="foo"}[1m]))`}}, | ||||||
}, | ||||||
promql.Vector{ | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "fuzz"}}}, | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}}}, | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
|
@@ -682,7 +695,79 @@ func TestEngine_LogsInstantQuery(t *testing.T) { | |||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app,machine) (count_over_time({app="foo"}[1m]))`}}, | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app) (count_over_time({app="foo"}[1m]))`}}, | ||||||
}, | ||||||
errors.New("multiple matches for labels"), | ||||||
errors.New("multiple matches for labels: many-to-one matching must be explicit (group_left/group_right)"), | ||||||
}, | ||||||
{ | ||||||
`sum by (app,machine) (count_over_time({app="foo"}[1m])) > bool on () group_left (app) sum by (app) (count_over_time({app="foo"}[1m]))`, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can safely remove the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct, removed it. |
||||||
time.Unix(60, 0), | ||||||
logproto.FORWARD, | ||||||
0, | ||||||
[][]logproto.Series{ | ||||||
{newSeries(testSize, identity, `{app="foo",machine="fuzz"}`), newSeries(testSize, identity, `{app="foo",machine="buzz"}`)}, | ||||||
{newSeries(testSize, identity, `{app="foo"}`)}, | ||||||
}, | ||||||
[]SelectSampleParams{ | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app,machine) (count_over_time({app="foo"}[1m]))`}}, | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app) (count_over_time({app="foo"}[1m]))`}}, | ||||||
}, | ||||||
promql.Vector{ | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "buzz"}}}, | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "fuzz"}}}, | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
`sum by (app,machine) (count_over_time({app="foo"}[1m])) > bool on () group_left () sum by (app) (count_over_time({app="foo"}[1m]))`, | ||||||
time.Unix(60, 0), | ||||||
logproto.FORWARD, | ||||||
0, | ||||||
[][]logproto.Series{ | ||||||
{newSeries(testSize, identity, `{app="foo",machine="fuzz"}`), newSeries(testSize, identity, `{app="foo",machine="buzz"}`)}, | ||||||
{newSeries(testSize, identity, `{app="foo"}`)}, | ||||||
}, | ||||||
[]SelectSampleParams{ | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app,machine) (count_over_time({app="foo"}[1m]))`}}, | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app) (count_over_time({app="foo"}[1m]))`}}, | ||||||
}, | ||||||
promql.Vector{ | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "buzz"}}}, | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "fuzz"}}}, | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
`sum by (app,machine) (count_over_time({app="foo"}[1m])) > bool on (app) group_left (pool) sum by (app,pool) (count_over_time({app="foo"}[1m]))`, | ||||||
time.Unix(60, 0), | ||||||
logproto.FORWARD, | ||||||
0, | ||||||
[][]logproto.Series{ | ||||||
{newSeries(testSize, identity, `{app="foo",machine="fuzz"}`), newSeries(testSize, identity, `{app="foo",machine="buzz"}`)}, | ||||||
{newSeries(testSize, identity, `{app="foo",pool="foo"}`)}, | ||||||
}, | ||||||
[]SelectSampleParams{ | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app,machine) (count_over_time({app="foo"}[1m]))`}}, | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app,pool) (count_over_time({app="foo"}[1m]))`}}, | ||||||
}, | ||||||
promql.Vector{ | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "buzz"}, labels.Label{Name: "pool", Value: "foo"}}}, | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "fuzz"}, labels.Label{Name: "pool", Value: "foo"}}}, | ||||||
}, | ||||||
}, | ||||||
{ | ||||||
`sum by (app,pool) (count_over_time({app="foo"}[1m])) > bool on (app) group_right (pool) sum by (app,machine) (count_over_time({app="foo"}[1m]))`, | ||||||
time.Unix(60, 0), | ||||||
logproto.FORWARD, | ||||||
0, | ||||||
[][]logproto.Series{ | ||||||
{newSeries(testSize, identity, `{app="foo",pool="foo"}`)}, | ||||||
{newSeries(testSize, identity, `{app="foo",machine="fuzz"}`), newSeries(testSize, identity, `{app="foo",machine="buzz"}`)}, | ||||||
}, | ||||||
[]SelectSampleParams{ | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app,pool) (count_over_time({app="foo"}[1m]))`}}, | ||||||
{&logproto.SampleQueryRequest{Start: time.Unix(0, 0), End: time.Unix(60, 0), Selector: `sum by (app,machine) (count_over_time({app="foo"}[1m]))`}}, | ||||||
}, | ||||||
promql.Vector{ | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "buzz"}, labels.Label{Name: "pool", Value: "foo"}}}, | ||||||
promql.Sample{Point: promql.Point{T: 60 * 1000, V: 0}, Metric: labels.Labels{labels.Label{Name: "app", Value: "foo"}, labels.Label{Name: "machine", Value: "fuzz"}, labels.Label{Name: "pool", Value: "foo"}}}, | ||||||
}, | ||||||
}, | ||||||
} { | ||||||
test := test | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved