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

Short circuit parsing when label matchers are present #8890

Merged
merged 3 commits into from Mar 28, 2023

Conversation

MasslessParticle
Copy link
Contributor

@MasslessParticle MasslessParticle commented Mar 23, 2023

This PR makes parsers aware of any downstream label-matcher stages at parse time. As labels are parsed, if one has a matcher, the matcher is checked at parse time. If the label does not match it's matcher, parsing is halted on that log line.

ex 1:
consider the log:
foo=1 bar=2 baz=3

And the query
{} | logfmt | bar=3

When bar is parsed it is immediately checked against it's matcher. The match fails so we the parser never spends time parsing the rest of the line.

ex 2:
consider the log:
foo=1 baz=3 bletch=4

And the query
{} | logfmt | bar=3

bar is never seen in the log so the whole line is parsed.

Benchmarks:

                                                   │ parsers__old_2.txt │          parsers__new_3.txt          │
                                                   │       sec/op       │    sec/op     vs base                │
_Parser/json/inline_stages-8                              3413.5n ±  5%    766.4n ± 4%  -77.55% (p=0.000 n=10)
_Parser/jsonParser-not_json_line/inline_stages-8           101.5n ±  6%    103.1n ± 8%        ~ (p=0.645 n=10)
_Parser/unpack/inline_stages-8                             383.8n ±  4%    388.0n ± 9%        ~ (p=0.954 n=10)
_Parser/unpack-not_json_line/inline_stages-8               13.30n ±  2%    13.11n ± 1%        ~ (p=0.247 n=10)
_Parser/logfmt/inline_stages-8                            2105.5n ± 16%    727.7n ± 4%  -65.44% (p=0.000 n=10)
_Parser/regex_greedy/inline_stages-8                       4.220µ ±  4%    4.175µ ± 4%        ~ (p=0.739 n=10)
_Parser/regex_status_digits/inline_stages-8                319.8n ±  5%    326.4n ± 8%        ~ (p=0.481 n=10)
_Parser/pattern/inline_stages-8                            185.2n ±  7%    154.2n ± 3%  -16.74% (p=0.000 n=10)

                                                   │ parsers__old_2.txt │          parsers__new_3.txt          │
                                                   │        B/op        │    B/op     vs base                  │
_Parser/json/inline_stages-8                              280.00 ± 0%     64.00 ± 0%  -77.14% (p=0.000 n=10)
_Parser/jsonParser-not_json_line/inline_stages-8           16.00 ± 0%     16.00 ± 0%        ~ (p=1.000 n=10) 
_Parser/unpack/inline_stages-8                             80.00 ± 0%     80.00 ± 0%        ~ (p=1.000 n=10) 
_Parser/unpack-not_json_line/inline_stages-8               0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) 
_Parser/logfmt/inline_stages-8                            336.00 ± 0%     74.00 ± 0%  -77.98% (p=0.000 n=10)
_Parser/regex_greedy/inline_stages-8                       193.0 ± 1%     192.0 ± 1%        ~ (p=0.656 n=10)
_Parser/regex_status_digits/inline_stages-8                51.00 ± 0%     51.00 ± 0%        ~ (p=1.000 n=10) 
_Parser/pattern/inline_stages-8                           35.000 ± 0%     3.000 ± 0%  -91.43% (p=0.000 n=10)

                                                   │ parsers__old_2.txt │          parsers__new_3.txt          │
                                                   │     allocs/op      │ allocs/op   vs base                  │

_Parser/json/inline_stages-8                              18.000 ± 0%     4.000 ± 0%  -77.78% (p=0.000 n=10)
_Parser/jsonParser-not_json_line/inline_stages-8           1.000 ± 0%     1.000 ± 0%        ~ (p=1.000 n=10) 
_Parser/unpack/inline_stages-8                             4.000 ± 0%     4.000 ± 0%        ~ (p=1.000 n=10) 
_Parser/unpack-not_json_line/inline_stages-8               0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) 
_Parser/logfmt/inline_stages-8                            16.000 ± 0%     6.000 ± 0%  -62.50% (p=0.000 n=10)
_Parser/regex_greedy/inline_stages-8                       2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) 
_Parser/regex_status_digits/inline_stages-8                2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) 
_Parser/pattern/inline_stages-8                            2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.000 n=10)

@MasslessParticle MasslessParticle requested a review from a team as a code owner March 23, 2023 20:18
pkg/logql/log/parser_hints.go Show resolved Hide resolved
Co-authored-by: Owen Diehl <ow.diehl@gmail.com>
@MasslessParticle MasslessParticle merged commit 163fd9d into main Mar 28, 2023
3 checks passed
@MasslessParticle MasslessParticle deleted the tpatterson/short-circuit-parsing-on-labels branch March 28, 2023 18:35
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.

None yet

2 participants