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

feat: Add utf8 support to Pattern Lexer to support utf8 chars #13085

Merged
merged 4 commits into from
May 31, 2024

Conversation

benclive
Copy link
Contributor

What this PR does / why we need it:
Drain was producing patterns which did not match the original line in some cases. Example logline:

13:25:18.033470 ▶ INFO route ops sending to dest https://graphite-cortex-ops-blocks-us-east4.grafana.net/graphite/metrics: service_is_carbon-relay-ng.instance_is_carbon-relay-ng-c665b7b-j2trk.mtype_is_gauge.dest_is_https_graphite-cortex-ops-blocks-us-east4_grafana_netgraphitemetrics.unit_is_B.what_is_FlushSize.type_is_manual.stat_is_max_999 0.00 1717075518

The issue was in the LogQL pattern matching code: The pattern parser was identifying the single UTF8 character as 3 separate ASCII characters. This is actually a single 3-byte UTF encoded character.
I added support for UTF-8 bytes in the Lexer to correctly identify them as 1 character in order to resolve this.

The lexer code was generated by Copilot, although I found an alternative implementation to check it against.

@benclive benclive requested a review from a team as a code owner May 30, 2024 15:44
@@ -13,11 +13,25 @@ package pattern
}
}%%

%%{
utf8 = (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this bit was generated by copilot but I've manually checked it and I think its correct. As far as I understand, anyway.

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

Lgtm

@cyriltovena cyriltovena merged commit f6f8bab into main May 31, 2024
60 checks passed
@cyriltovena cyriltovena deleted the add-utf8-support-to-pattern-lexer branch May 31, 2024 09:21
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