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

Improve LogQL format stages requireLabel #4769

Merged
merged 3 commits into from
Nov 26, 2021

Conversation

cyriltovena
Copy link
Contributor

This only includes required labels.

➜ go test -benchmem -run=^$  -bench ^Benchmark_Pipeline ./pkg/logql/log -v -count 5  > after.txt && benchstat before.txt after.txt
name                                 old time/op    new time/op    delta
_Pipeline/pipeline_bytes-16            13.8µs ± 6%    11.5µs ± 1%  -16.42%  (p=0.008 n=5+5)
_Pipeline/pipeline_string-16           13.9µs ± 2%    11.5µs ± 2%  -17.27%  (p=0.008 n=5+5)
_Pipeline/line_extractor_bytes-16      14.0µs ± 4%    11.6µs ± 0%  -17.45%  (p=0.016 n=5+4)
_Pipeline/line_extractor_string-16     13.5µs ± 0%    11.5µs ± 0%  -14.67%  (p=0.008 n=5+5)
_Pipeline/label_extractor_bytes-16     13.7µs ± 1%    11.7µs ± 1%  -14.69%  (p=0.008 n=5+5)
_Pipeline/label_extractor_string-16    14.1µs ±11%    11.6µs ± 0%  -17.89%  (p=0.008 n=5+5)

name                                 old alloc/op   new alloc/op   delta
_Pipeline/pipeline_bytes-16            9.51kB ± 0%    7.50kB ± 0%  -21.19%  (p=0.008 n=5+5)
_Pipeline/pipeline_string-16           9.51kB ± 0%    7.50kB ± 0%  -21.19%  (p=0.008 n=5+5)
_Pipeline/line_extractor_bytes-16      9.51kB ± 0%    7.50kB ± 0%  -21.19%  (p=0.008 n=5+5)
_Pipeline/line_extractor_string-16     9.51kB ± 0%    7.50kB ± 0%     ~     (p=0.079 n=4+5)
_Pipeline/label_extractor_bytes-16     9.51kB ± 0%    7.50kB ± 0%  -21.18%  (p=0.008 n=5+5)
_Pipeline/label_extractor_string-16    9.51kB ± 0%    7.50kB ± 0%  -21.18%  (p=0.008 n=5+5)

name                                 old allocs/op  new allocs/op  delta
_Pipeline/pipeline_bytes-16              46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/pipeline_string-16             46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/line_extractor_bytes-16        46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/line_extractor_string-16       46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/label_extractor_bytes-16       46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/label_extractor_string-16      46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)

Also fixes the text/template parsing it was buggy.

Signed-off-by: Cyril Tovena cyril.tovena@gmail.com

This only includes required labels.

```
➜ go test -benchmem -run=^$  -bench ^Benchmark_Pipeline ./pkg/logql/log -v -count 5  > after.txt && benchstat before.txt after.txt
name                                 old time/op    new time/op    delta
_Pipeline/pipeline_bytes-16            13.8µs ± 6%    11.5µs ± 1%  -16.42%  (p=0.008 n=5+5)
_Pipeline/pipeline_string-16           13.9µs ± 2%    11.5µs ± 2%  -17.27%  (p=0.008 n=5+5)
_Pipeline/line_extractor_bytes-16      14.0µs ± 4%    11.6µs ± 0%  -17.45%  (p=0.016 n=5+4)
_Pipeline/line_extractor_string-16     13.5µs ± 0%    11.5µs ± 0%  -14.67%  (p=0.008 n=5+5)
_Pipeline/label_extractor_bytes-16     13.7µs ± 1%    11.7µs ± 1%  -14.69%  (p=0.008 n=5+5)
_Pipeline/label_extractor_string-16    14.1µs ±11%    11.6µs ± 0%  -17.89%  (p=0.008 n=5+5)

name                                 old alloc/op   new alloc/op   delta
_Pipeline/pipeline_bytes-16            9.51kB ± 0%    7.50kB ± 0%  -21.19%  (p=0.008 n=5+5)
_Pipeline/pipeline_string-16           9.51kB ± 0%    7.50kB ± 0%  -21.19%  (p=0.008 n=5+5)
_Pipeline/line_extractor_bytes-16      9.51kB ± 0%    7.50kB ± 0%  -21.19%  (p=0.008 n=5+5)
_Pipeline/line_extractor_string-16     9.51kB ± 0%    7.50kB ± 0%     ~     (p=0.079 n=4+5)
_Pipeline/label_extractor_bytes-16     9.51kB ± 0%    7.50kB ± 0%  -21.18%  (p=0.008 n=5+5)
_Pipeline/label_extractor_string-16    9.51kB ± 0%    7.50kB ± 0%  -21.18%  (p=0.008 n=5+5)

name                                 old allocs/op  new allocs/op  delta
_Pipeline/pipeline_bytes-16              46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/pipeline_string-16             46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/line_extractor_bytes-16        46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/line_extractor_string-16       46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/label_extractor_bytes-16       46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
_Pipeline/label_extractor_string-16      46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
```

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@cyriltovena cyriltovena requested a review from a team as a code owner November 16, 2021 16:43
return nil, fmt.Errorf("invalid line template: %w", err)
}
names := uniqueString(listNodeFields([]parse.Node{t.Root}))
namesMap := make(map[string]struct{}, len(names))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just a hashset? We don't seem to use the values.

Copy link
Contributor Author

@cyriltovena cyriltovena Nov 19, 2021

Choose a reason for hiding this comment

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

it is. I need more time to think about this PR. It does improve but I think we can do better at source I might just split this PR into 2.

Comment on lines 296 to 307
func (lf *LabelsFormatter) buildModel(lbs *LabelsBuilder) interface{} {
labels := lbs.Labels()
model := make(map[string]string, len(lf.requiredLabelNamesMap))
if len(lf.requiredLabelNames) > 0 {
for _, l := range labels {
if _, ok := lf.requiredLabelNamesMap[l.Name]; ok {
model[l.Name] = l.Value
}
}
}
return model
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be some code duplication.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@pull-request-size pull-request-size bot added size/M and removed size/L labels Nov 26, 2021
@cyriltovena
Copy link
Contributor Author

@jeschkies I rollback the buildModel change but kept the new way to compute required node.

I'll follow up with a better PR to improve performance later.

@cyriltovena cyriltovena changed the title Improve LogQL format stages. Improve LogQL format stages requireLabel Nov 26, 2021
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@cyriltovena cyriltovena merged commit 0a94467 into grafana:main Nov 26, 2021
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