-
Notifications
You must be signed in to change notification settings - Fork 802
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
frontend: implement cache control #1974
frontend: implement cache control #1974
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Changes make sense to me. I just left a minor comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nit!
Could you also add changelog entry? |
CHANGELOG.md
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
## master / unreleased | |||
|
|||
* [CHANGE] The frontend component now does not cache results if it finds a `Cache-Control` header and if one of its values is `no-store` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Full stop and add the PR number too please :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And a rebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was fast 😄 will do.
Add an extra `Headers` field to the `PrometheusResponse` message which contains the headers and their values that came from Prometheus. Use them in other places to deduce if the response should be cached. If `Cache-Control` is equal to `no-store` then it is *not* cached. This will be used by the Thanos project to indicate when a partial response has been returned. In such cases the result should not be cached so that invalid data would not be stored there. Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
`Cache-Control` might contain more than one value so check all of them. Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
Signed-off-by: Giedrius Statkevičius <giedriuswork@gmail.com>
b8011eb
to
24ee2c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
👋 from the Thanos project. Thanks, first of all, for your work on making the frontend component work with regular Prometheus end-points! We would like to extend it a bit so that it would fit better for use with Thanos. One of the things is that we would like to avoid caching the results when Thanos gets what is called a "partial response" - when one of the nodes does not respond but some end-result with partial data is still returned to the user. Obviously, such data is incomplete and might very well change after a minute or two so it must not be cached.
Thus, let's capture the headers from the response as well. They will be used to determine if the result should be cached. For that reason two new variables are introduced:
cachecontrolHeader
which is equal toCache-Control
- this is the header that will be checkednoCacheValue
which is equal tono-store
- that is the value that we are looking for to determine if the result should be cachedMore documents/ideas are available here: thanos-io/thanos#1651
Example user: thanos-io/thanos#1984. I actually tested that this works as expected with that PR applied on top of
master
.Added a simple test for the function which determines if the result should be cached based on the response's headers.
All ideas/feedback/suggestions welcome as I have never contributed to Cortex thus I am unfamiliar with the codebase. Also, I wonder if you would be even open to accepting something like this. Obviously this is missing such things like documentation & E2E tests, and so on so let's discuss this before moving further. Thanks a lot!