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

Detect body format after reading from cache and restore content-type header #3759

Merged
merged 3 commits into from
Jun 7, 2024

Conversation

mdisibio
Copy link
Contributor

@mdisibio mdisibio commented Jun 7, 2024

What this PR does:
This fixes a bug introduced in #3731 and caching the new protobuf responses. Cache loses the Content-Type header and therefore it falls back to json parsing which fails with an error like error unmarshalling response body: invalid character '\x17' looking for beginning of value. This is a quick work-around to readd the Content-Type by detecting the format. I wish we could use https://pkg.go.dev/net/http#DetectContentType but it doesn't seem to detect either json or proto, and yields either text/plain or application/octet-stream.

Long-term cache needs to be updated to store the http response more comprehensively, likely including all headers. And add more structure around upgrading/migration cache content. Changing the cache key (stv:v1 -> stv:v2) isn't sufficient in this case because the cache key is determined by the frontend, and the response format by the querier, so there is a disconnect.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@mdisibio mdisibio merged commit 64a8d6b into grafana:main Jun 7, 2024
14 checks passed
@mapno mapno deleted the fix-cache-content-type branch June 11, 2024 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants