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

feat(feature-flagged-query-cache): Added a feature flagged query cache #19072

Merged
merged 25 commits into from
Aug 4, 2020

Conversation

asalem1
Copy link
Contributor

@asalem1 asalem1 commented Jul 24, 2020

Closes #18791

NOTE

This is a preliminary version of the query cache that has a feature flag wrapped around every place where it's being invoked so that we can work off of it. It resolves the windowPeriod issue that created the incident on Friday. This issue was resolved by specifically getting the windowPeriod variable from the query text, a pattern that we use here:

https://github.com/influxdata/influxdb/pull/19072/files#diff-4399ae26b73db6259e86e2dea60efd3dR224-R225

This was added here before running the query:

https://github.com/influxdata/influxdb/pull/19072/files?file-filters%5B%5D=.go&file-filters%5B%5D=.ts&file-filters%5B%5D=.tsx#diff-0be90b2f69a877941cc79979e2747aadR177-R180

What

This PR introduces the concept of a QueryCache to dashboards in order to reduce the number of API requests generated by the UI when toggling between the Cell Configuration Overlay (known as VEO), and the cells on a dashboard.

How

Before each cells runs its respective query, it checks for a matching hashed version of that query in the local cache instance. If one is found, then the data from the cache is returned as promise and runQuery is never run. If one is not found (or if there is a mismatch in variables, or the data is stale), then the operation will continue to runQuery.

Similarly, when the VEO is toggled open, the same operation will occur.

When the cache is instantiated, a watch dog is triggered to clean up any stale data that is currently in the cache.

@asalem1 asalem1 requested a review from drdelambre July 24, 2020 20:35
public componentWillUnmount() {
this.props.resetCachedQueryResults()
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this need to called if the flag is disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not since the file has been removed and we're no longer caching things. Even if the feature flag is implemented the previous caching system has been ripped out in this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

that's what i'm trying to call attention to. doesn't that mean that we have interface changes being deployed that aren't captured / contained by the feature flag?

@@ -101,10 +110,6 @@ const mstp = (state: AppState) => {
}
}

const mdtp = {
resetCachedQueryResults: resetCachedQueryResults,
Copy link
Contributor

Choose a reason for hiding this comment

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

and this added back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not unless we want to integrate the old system back in before we end up removing it later?

hashedVariables: string,
values: RunQueryResult
): void => {
event('query_cache_miss', {context: 'queryCache'})
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the context for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷 I just went based off of what was going on in the other usages. Is there a doc somewhere on event reporting that we should stick to?

Copy link
Contributor

Choose a reason for hiding this comment

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

we might want to add the queryID into that object so that we can separate parallelized queries

orgID: string,
query: string,
state: AppState
): CancelBox<RunQueryResult> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

throw an event up here too so that we can split questions like "how many queries did the cache save?" and it'd be queries requested vs query cache set

Copy link
Contributor Author

@asalem1 asalem1 Jul 24, 2020

Choose a reason for hiding this comment

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

i think this should be taken care of already in the sense that we already report events for the executeQueries (and TimeSeries.tsx) which this inevitably call this

Copy link
Contributor

Choose a reason for hiding this comment

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

i dont understand this. feels like an gap between intent vs implementation. explicitly defining the event at the intent (as opposed to using a proxy event rooted in implementation to estimate the intent) helps keep a consistent history to the event, even through implementation changes. if we rewrite all of executeQueries, and forget to put in the eventing, or change the definition of the submodule's eventing structure, our dashboards for cache hits vs missus shouldn't change right? isn't the event you're planning on proxying already invalid because we don't use executeQueries for dashboards?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right in that the TimeSeries component does not depend on the executeQueries thunk to run a query, it does, however, a duplicate event. I do see what you're saying though. I'll add it in

const windowVars = getWindowVars(query, allVars)

// otherwise query & set results
const extern = buildVarsOption([...variableAssignments, ...windowVars])
Copy link
Contributor

Choose a reason for hiding this comment

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

flagging this for the thread's sake as the fix for the outage... generating a windowPeriod variable from the query and adding it to the AST partial for the query

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@ebb-tide ebb-tide left a comment

Choose a reason for hiding this comment

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

it looks good to me..

@asalem1 asalem1 requested a review from drdelambre August 3, 2020 22:20
asalem1 added 17 commits August 4, 2020 06:07
…tion and restructured the way that Cached data was being stored

Still need to:

- create a filterUnusedVars without a view context to pass into the query
- explicitly reset & set the query when the VEO is submitted
… is submitted

filtering out unused vars before setting them to query cache
…ay funcs were being imported and updated a few comments
…y & removed comments from tests to reduce confusion
…ry and added a comment to TIME_INVALIDATION const
@asalem1 asalem1 merged commit fdea2c6 into master Aug 4, 2020
@asalem1 asalem1 deleted the fix/query-cache branch August 4, 2020 13:56
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.

Cache queries made in dashboard and VEO
3 participants