Skip to content

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

Merged
mdisibio merged 3 commits intografana:mainfrom
mdisibio:fix-cache-content-type
Jun 7, 2024
Merged

Detect body format after reading from cache and restore content-type header#3759
mdisibio merged 3 commits intografana:mainfrom
mdisibio:fix-cache-content-type

Conversation

@mdisibio
Copy link
Copy Markdown
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
@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