-
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
Improve LogQL format stages requireLabel #4769
Conversation
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>
pkg/logql/log/fmt.go
Outdated
return nil, fmt.Errorf("invalid line template: %w", err) | ||
} | ||
names := uniqueString(listNodeFields([]parse.Node{t.Root})) | ||
namesMap := make(map[string]struct{}, len(names)) |
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.
Is this just a hashset? We don't seem to use the values.
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.
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.
pkg/logql/log/fmt.go
Outdated
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 | ||
} |
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.
This seems to be some code duplication.
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@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. |
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
This only includes required labels.
Also fixes the text/template parsing it was buggy.
Signed-off-by: Cyril Tovena cyril.tovena@gmail.com