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

/api/prom/push produce error 400 with 'unexpected IDENTIFIER' #1727

Closed
mailtosmyk opened this issue Feb 21, 2020 · 7 comments · Fixed by #1750
Closed

/api/prom/push produce error 400 with 'unexpected IDENTIFIER' #1727

mailtosmyk opened this issue Feb 21, 2020 · 7 comments · Fixed by #1750
Labels
help wanted We would love help on these issues. Please come help us! keepalive An issue or PR that will be kept alive and never marked as stale. type/enhancement Something existing could be improved

Comments

@mailtosmyk
Copy link

mailtosmyk commented Feb 21, 2020

Describe the bug
When trying to submit stream thru api endpoint "/api/prom/push" loki return error code 400 with not helpful message "parse error at line 1, col 1: syntax error: unexpected IDENTIFIER"

To Reproduce
1 clone grafana/loki from https://github.com/grafana/loki
2 Run docker-compose up
3 Using chrome plugin ARC create POST request with based on documentation from https://github.com/grafana/loki/blob/v1.3.0/docs/api.md#get-lokiapiv1labels:

URL: http://localhost:3100/api/prom/push
Body content: application/json
body: {"streams":[{"labels":"cat","entries":[{"ts":"2018-12-18T08:28:06.801064-04:00","line":"fizzbuzz"}]}]}

CURL output:
c:\test\loki\production\loki-mixin>curl -H "Content-Type: application/json" -X POST "http://localhost:3100/api/prom/push" -d "{"streams": [{ "labels": "cats", "entries": [{ "ts": "2018-12-18T08:28:06.801064-04:00", "line": "fizzbuzz" }] }]}"
parse error at line 1, col 1: syntax error: unexpected IDENTIFIER

4 Loki server return "parse error at line 1, col 1: syntax error: unexpected IDENTIFIER"

Expected behavior
HTTP status code 2XX or better explanation what is missing/incorrect

Environment:

  • Infrastructure: laptop, windows 10, docker-compose
  • Deployment tool: docker-compose
@cyriltovena
Copy link
Contributor

The error should be better, the label field is incorrect. See https://github.com/grafana/loki/blob/master/docs/api.md#examples-8

Also I recommend you to use the v1 API see the link above.

@cyriltovena cyriltovena added help wanted We would love help on these issues. Please come help us! keepalive An issue or PR that will be kept alive and never marked as stale. type/enhancement Something existing could be improved labels Feb 21, 2020
@talham7391
Copy link

I can take a look at this!

@cyriltovena
Copy link
Contributor

Sure I'll feed you with more info on how to on Monday!

@Pixelstudio
Copy link

Hi,
Iv encoured the same error using the following json, im using the new api : loki/api/v1/push

{"streams": [{ "labels": "{foo="bar"}", "entries": [{ "ts": "2018-12-18T08:28:06.801064-04:00", "line": "fizzbuzz" }] }]}

The error is :
parse error at line 1, col 2: syntax error: unexpected }, expecting IDENTIFIER

@cyriltovena
Copy link
Contributor

I’m sorry you’re encountering this again, the v1 api has a different label format.

See https://github.com/grafana/loki/blob/master/docs/api.md#examples-4

Basically now it’s a map before it was a string.

@cyriltovena
Copy link
Contributor

@talham7391 It's happening here: https://github.com/grafana/loki/blob/master/pkg/distributor/validator.go#L60

I would change add more context to the error. Something like

return httpgrpc.Errorf(http.StatusBadRequest, fmt.Errorf("error parsing labels: %v", err.Error()))

@talham7391
Copy link

Okay great, will push a PR soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We would love help on these issues. Please come help us! keepalive An issue or PR that will be kept alive and never marked as stale. type/enhancement Something existing could be improved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants