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

Caching: Refactor enterprise query caching middleware to a wire service #65616

Merged
merged 63 commits into from
Apr 12, 2023

Conversation

mmandrus
Copy link
Contributor

@mmandrus mmandrus commented Mar 30, 2023

What is this feature?

This work converts the enterprise query caching implementation from middleware to a service injected by wire. The OSS implementation of this service does nothing, while the enterprise service functionality remains the same.

This new implementation will live behind a feature flag in the near term. Once we have verified its stability, we will remove the flag.

Why do we need this feature?

Benefits of doing this include:

  • Reduce risk of breaking changes between enterprise and OSS
  • Reduce duplicated logic (e.g. assessing DS permissions in the middleware)
  • Performance & safety improvements (stop non-query API calls from passing through middleware)

Who is this feature for?

Enterprise customers using query caching, and OSS developers.

Which issue(s) does this PR fix?:

Fixes https://github.com/grafana/grafana-enterprise/issues/4666

Special notes for your reviewer:

Corresponding enterprise PR is here https://github.com/grafana/grafana-enterprise/pull/4851

The majority of interactions with the cache happen in the new plugin middleware, in order to consolidate things as best as possible. There is a follow-up task to fully consolidate the resource caching usage.

@mmandrus mmandrus added this to the 10.0.0 milestone Apr 11, 2023
Copy link
Member

@marefr marefr 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

@leandro-deveikis leandro-deveikis left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

mmandrus and others added 5 commits April 11, 2023 12:08
@mmandrus mmandrus requested review from a team and chri2547 as code owners April 12, 2023 13:50
@mmandrus mmandrus requested review from tskarhed and yaelleC and removed request for a team April 12, 2023 13:50
@mmandrus mmandrus merged commit 5626461 into main Apr 12, 2023
11 checks passed
@mmandrus mmandrus deleted the mmandrus/caching-middleware-refactor branch April 12, 2023 16:30
alexmobo pushed a commit that referenced this pull request Apr 14, 2023
…ce (#65616)

* define initial service and add to wire

* update caching service interface

* add skipQueryCache header handler and update metrics query function to use it

* add caching service as a dependency to query service

* working caching impl

* propagate cache status to frontend in response

* beginning of improvements suggested by Lean - separate caching logic from query logic.

* more changes to simplify query function

* Decided to revert renaming of function

* Remove error status from cache request

* add extra documentation

* Move query caching duration metric to query package

* add a little bit of documentation

* wip: convert resource caching

* Change return type of query service QueryData to a QueryDataResponse with Headers

* update codeowners

* change X-Cache value to const

* use resource caching in endpoint handlers

* write resource headers to response even if it's not a cache hit

* fix panic caused by lack of nil check

* update unit test

* remove NONE header - shouldn't show up in OSS

* Convert everything to use the plugin middleware

* revert a few more things

* clean up unused vars

* start reverting resource caching, start to implement in plugin middleware

* revert more, fix typo

* Update caching interfaces - resource caching now has a separate cache method

* continue wiring up new resource caching conventions - still in progress

* add more safety to implementation

* remove some unused objects

* remove some code that I left in by accident

* add some comments, fix codeowners, fix duplicate registration

* fix source of panic in resource middleware

* Update client decorator test to provide an empty response object

* create tests for caching middleware

* fix unit test

* Update pkg/services/caching/service.go

Co-authored-by: Arati R. <33031346+suntala@users.noreply.github.com>

* improve error message in error log

* quick docs update

* Remove use of mockery. Update return signature to return an explicit hit/miss bool

* create unit test for empty request context

* rename caching metrics to make it clear they pertain to caching

* Update pkg/services/pluginsintegration/clientmiddleware/caching_middleware.go

Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>

* Add clarifying comments to cache skip middleware func

* Add comment pointing to the resource cache update call

* fix unit tests (missing dependency)

* try to fix mystery syntax error

* fix a panic

* Caching: Introduce feature toggle to caching service refactor (#66323)

* introduce new feature toggle

* hide calls to new service behind a feature flag

* remove licensing flag from toggle (misunderstood what it was for)

* fix unit tests

* rerun toggle gen

---------

Co-authored-by: Arati R. <33031346+suntala@users.noreply.github.com>
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
@zerok zerok modified the milestones: 10.0.0, 10.0.0-preview May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants