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

JSON label extraction field validation expression overly strict #6372

Merged
merged 5 commits into from
Jun 13, 2022

Conversation

splitice
Copy link
Contributor

@splitice splitice commented Jun 12, 2022

What this PR does / why we need it:

A valid query started to fail. I can't share the exact query as it was from production, but the error message (slightly adjusted) is as follows).

level=error ts=2022-06-12T03:35:08.406753057Z caller=retry.go:73 org_id=fake msg="error processing request" try=0 err="rpc error: code = Code(500) desc = 3 errors: rpc error: code = Unknown desc = parse error : stage '| json layer7_something_detail=\"layer7_something_detail\"' : cannot parse expression [layer7_something_detail]: non-integer value: _; rpc error: code = Unknown desc = parse error : stage '| json layer7_something_detail=\"layer7_something_detail\"' : cannot parse expression [layer7_something_detail]: non-integer value: _; rpc error: code = Unknown desc = parse error : stage '| json layer7_something_detail=\"layer7_something_detail\"' : cannot parse expression [layer7_something_detail]: non-integer value: _\n"

Afer some experimentation the problem was found to be the number in the fields. Strangely it only affects some queries that use json fields.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Documentation added
  • Tests updated
  • Is this an important fix or new feature? Add an entry in the CHANGELOG.md.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/upgrading/_index.md

@splitice splitice force-pushed the test/add-json-test-with-number branch from 65caa24 to 711a372 Compare June 12, 2022 03:48
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@splitice splitice force-pushed the test/add-json-test-with-number branch from 772a5dc to 3cff1d0 Compare June 12, 2022 04:34
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@pull-request-size pull-request-size bot added size/M and removed size/S labels Jun 12, 2022
@splitice
Copy link
Contributor Author

splitice commented Jun 12, 2022

I'm not certain why the tests I added don't fail (without the fix). None the less they extend the test suite.

I've found what I beleive to be the issue and have gone about fixing it.

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@splitice splitice marked this pull request as ready for review June 12, 2022 05:10
@splitice splitice requested a review from a team as a code owner June 12, 2022 05:10
@splitice
Copy link
Contributor Author

Confirmed fix of discovered issue with 6cdbaec

Copy link
Contributor

@chaudum chaudum left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. Looks good to me! I think this change deserves a changelog entry :)

pkg/logql/log/jsonexpr/lexer.go Outdated Show resolved Hide resolved
@chaudum
Copy link
Contributor

chaudum commented Jun 13, 2022

I'm not certain why the tests I added don't fail (without the fix). None the less they extend the test suite.

We should investigate this before we merge :)

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @splitice - this looks great.

The reason why you can't replicate the issue in pkg/logql/syntax/parser_test.go is that it doesn't actually invoke the JSONExpressionParser I believe, it merely parses the expression.

You'll need a test in pkg/logql/log/jsonexpr/jsonexpr_test.go which will expose the issue:

I added

{
	"identifier with number",
	`utf8`,
	[]interface{}{"utf8"},
	nil,
},

under TestJSONExpressionParser and was able to replicate the issue and confirm your fix.

@splitice
Copy link
Contributor Author

@dannykopping I figured it was something like that. Unfortunately had production to fix and it was easier to just test the known failing query against a build.

I'll integrate feedback and that test case.

@splitice
Copy link
Contributor Author

splitice commented Jun 13, 2022

@dannykopping @chaudum review feedback integrated & resosolved merge conflicts

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
-        distributor	-0.3%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0%

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
+               loki	0.7%

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM

@dannykopping dannykopping merged commit 771e218 into grafana:main Jun 13, 2022
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

4 participants