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

Loki: Change how push API checks for contentType #4443

Merged

Conversation

DylanGuedes
Copy link
Contributor

@DylanGuedes DylanGuedes commented Oct 8, 2021

What this PR does / why we need it:
Changes how the push API checks for contentType. Currently, the contentType is expected to be exactly application/json, however, even other valid values such as application/json; charset=utf-8 aren't accepted. In fact, Loki's response to that endpoint has contentType application/json; charset=utf-8 so I think it is worth to support it.

Which issue(s) this PR fixes:
Fixes #4442

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated

- Currently, the ContentType is expected to be exactly
  "application/json". That's a problem because although a
"application/json; charset=utf-8" is considered a valid JSON content
type, it will be seen as an error.
@DylanGuedes DylanGuedes changed the title Change how push API checks for contentType Loki: Change how push API checks for contentType Oct 8, 2021
- mime.ParseMediaType is more reliable than strings.Contains because if
  a wrong contentType (such as "application/jsonnn") is given, we still
accept it
- mime.ParseMediaType has support for contentType parameters. This way,
  valid contentTypes such as "application/json; charset=utf-8" will not
be rejected
@DylanGuedes DylanGuedes marked this pull request as ready for review October 9, 2021 11:10
@DylanGuedes DylanGuedes requested a review from a team as a code owner October 9, 2021 11:10
- Without this change, the lint fails because gzipString would be called
  with always the same input. Full error:
```
`gzipString` - `source` always receives ``{"streams": [{ "stream": {
"foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ]
}]}` ("{\"streams\": [{ \"stream\": { \"foo\": \"bar2\" }, \"values\": [
[ ...)
` (unparam)
```
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.

Nice, thanks @DylanGuedes 👍

@dannykopping dannykopping merged commit ab10bc6 into grafana:main Oct 11, 2021
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.

JSON Push API returns 400 when Content-Type is application/json; charset=utf-8
2 participants