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

Monitoring: Fix graph refresh on alert and rule details pages #6881

Conversation

kyoto
Copy link
Member

@kyoto kyoto commented Oct 9, 2020

Pass query and ruleDuration to Graph instead of the whole rule
object to prevent some unnecessary re-rendering. This also removes the
need to memoize queries.

Memoize labels in AlertsDetailsPage to avoid triggering unnecessary
re-renders of Graph.

Initialize pollInterval to undefined instead of null. null
indicates that polling was disabled, whereas undefined indicates that
it is not specified and the QueryBrowser should use its default poll
interval.

@openshift-ci-robot openshift-ci-robot added component/core Related to console core functionality component/monitoring Related to monitoring approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 9, 2020
@@ -120,7 +120,7 @@ export default (state: UIState, action: UIAction): UIState => {
}),
queryBrowser: ImmutableMap({
metrics: [],
pollInterval: null,
pollInterval: undefined,
Copy link
Member

Choose a reason for hiding this comment

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

I try to avoid code that differentiates between undefined and null, which isn't very obvious and can be a source of bugs. I think this at least deserves a comment explaining.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, the null / undefined distinction was not a great solution 😬

I'm now thinking that a better approach is to force the polling interval (pollInterval={Math.round(timespan / 120)}) instead of using QueryBrowser's default polling interval logic. This removes the need for the null / undefined change.

@@ -596,10 +593,15 @@ const alertStateToProps = (state: RootState, { match }): AlertsDetailsPageProps
export const AlertsDetailsPage = withFallback(
connect(alertStateToProps)((props: AlertsDetailsPageProps) => {
const { alert, loaded, loadError, namespace, rule, silencesLoaded } = props;
const { annotations = {}, labels = {}, silencedBy = [] } = alert || {};
const { alertname, severity } = labels as any;
const annotations = alert?.annotations ?? {};
Copy link
Member

Choose a reason for hiding this comment

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

You might want || instead of ?? in most of these cases. If you ever get annotations: null, could that cause an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @spadgett. After looking at this again, I ended up refactoring in a way that removes the need for these 2 ?? anyway.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 24, 2020
Use a fixed polling interval based on the alerting rule's duration.

Pass `query` and `ruleDuration` to `Graph` instead of the whole `rule`
object to prevent some unnecessary re-rendering. This also removes the
need to memoize `queries`.

Memoize `labels` in `AlertsDetailsPage` to avoid triggering unnecessary
re-renders of `Graph`.
@kyoto kyoto force-pushed the monitoring-alert-details-graph-refresh branch from b28adf9 to c92fb26 Compare October 30, 2020 03:23
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 30, 2020
@kyoto
Copy link
Member Author

kyoto commented Oct 30, 2020

@spadgett Rebased and addressed your feedback

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 30, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kyoto, spadgett

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

4 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 323136a into openshift:master Oct 30, 2020
@kyoto kyoto deleted the monitoring-alert-details-graph-refresh branch November 1, 2020 23:49
@spadgett spadgett added this to the v4.7 milestone Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality component/monitoring Related to monitoring lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants