-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Explore: Update Loki labels when label selector is opened #16131
Conversation
return Promise.all( | ||
labelKeys.filter(key => DEFAULT_KEYS.indexOf(key) > -1).map(key => this.fetchLabelValues(key)) | ||
).then(values => { | ||
this.logLabelFetchTs = Date.now(); |
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.
Race condition: logLabelFetchTs
must be set before the requests start, otherwise a lot of requests can be started if refreshLogLabels
is called quickly, assuming logLabelFetchTs
has been set once (Date.now() - this.logLabelFetchTs > LABEL_REFRESH_INTERVAL
with this.logLabelFetchTs
being undefined
masks this on the first run.
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.
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.
Small nits, but otherwise looks very good!
Using this PR as an entry example for hooks was a bit ambitious though 😉
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!
I like the separation of concerns and that it's makes tests easier/more accessible. But I'm also to inexperienced with hooks to say if this issue justifies the use of hooks or not.
}); | ||
setLogLabelOptions(nextOptions); // to set loading | ||
fetchOptionValues(targetOption.value); | ||
}, [activeOption]); |
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.
Maybe this should also fire when languageProviderInitialised
is changed to true?
Fixes #15402
This PR introduces possibility to refresh labels in Loki's language provider as well as enables refresh on UI level
Assumptions:
LABEL_REFRESH_INTERVAL
const).rc-cascader
exposes, that is related to the UI interaction. What we can do to refresh not only on UI interaction is to implement effect inuseLokiLabels
hook (see details below) that would refresh the labels in the background.Other changes:
LokiQueryField
state, thus made it a stateless component.useLokiLabels
- performs missing options fetching and delegates refresh to language provideruseLokiSyntax
- provides Loki's syntax to component that uses it, along with labels delivered byuseLokiLabels
Since this is a first time we are trying to use hooks in our code, the hooks implementation may not be the best on, just so you know;)
TODO:
LokiQueryField
componentLokiQueryField