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

Explore: Update Loki labels when label selector is opened #16131

Merged
merged 14 commits into from
Mar 25, 2019

Conversation

dprokop
Copy link
Member

@dprokop dprokop commented Mar 21, 2019

Fixes #15402

This PR introduces possibility to refresh labels in Loki's language provider as well as enables refresh on UI level

Assumptions:

  • Refresh happens only if 30s interval has passed (specified via LABEL_REFRESH_INTERVAL const).
  • Labels are refreshed(or tried to be refreshed) when Loki's label selector is opened. This is a conscious decision driven by the fact, that this is the only event that 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 in useLokiLabels hook (see details below) that would refresh the labels in the background.

Other changes:

  • Removed the logLabelsOptions and syntax logic from LokiQueryField state, thus made it a stateless component.
  • State handling for log labels and delivering Loki's lang syntax is now performed by two React hooks:
    • useLokiLabels - performs missing options fetching and delegates refresh to language provider
    • useLokiSyntax - provides Loki's syntax to component that uses it, along with labels delivered by useLokiLabels

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:

  • Remove state from LokiQueryField component
  • Implement hooks to deliver loki's syntax and labels to LokiQueryField
  • Implement hooks' tests

@dprokop dprokop added this to the 6.1 milestone Mar 21, 2019
@dprokop dprokop self-assigned this Mar 21, 2019
@dprokop dprokop marked this pull request as ready for review March 21, 2019 12:09
return Promise.all(
labelKeys.filter(key => DEFAULT_KEYS.indexOf(key) > -1).map(key => this.fetchLabelValues(key))
).then(values => {
this.logLabelFetchTs = Date.now();
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

@davkal this is fixed in 0b17d65

Copy link
Contributor

@davkal davkal left a 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 😉

Copy link
Contributor

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

@dprokop dprokop changed the title Explore - make sure labels are up to date Explore - make sure Loki labels are up to date Mar 22, 2019
@dprokop dprokop requested a review from torkelo March 22, 2019 13:52
});
setLogLabelOptions(nextOptions); // to set loading
fetchOptionValues(targetOption.value);
}, [activeOption]);
Copy link
Member

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?

@dprokop dprokop merged commit c2e9daa into master Mar 25, 2019
@torkelo torkelo changed the title Explore - make sure Loki labels are up to date Explore: Update Loki labels when label selector is opened Mar 26, 2019
@gotjosh gotjosh deleted the explore/keep-labels-up-to-date branch July 18, 2019 09:45
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.

5 participants