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

frontend: implement cache control #1974

Merged
merged 12 commits into from
Jan 17, 2020

Conversation

GiedriusS
Copy link
Contributor

@GiedriusS GiedriusS commented Jan 10, 2020

👋 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 to Cache-Control - this is the header that will be checked
  • noCacheValue which is equal to no-store - that is the value that we are looking for to determine if the result should be cached

More 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!

Copy link
Contributor

@pracucci pracucci left a 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.

pkg/querier/queryrange/results_cache.go Outdated Show resolved Hide resolved
@GiedriusS GiedriusS marked this pull request as ready for review January 13, 2020 20:58
Copy link
Contributor

@sandeepsukhani sandeepsukhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@gouthamve gouthamve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit!

pkg/querier/queryrange/results_cache.go Outdated Show resolved Hide resolved
@gouthamve
Copy link
Contributor

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`
Copy link
Contributor

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 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a rebase

Copy link
Contributor Author

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>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants