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
Monitoring: Fix graph refresh on alert and rule details pages #6881
Conversation
frontend/public/reducers/ui.ts
Outdated
@@ -120,7 +120,7 @@ export default (state: UIState, action: UIAction): UIState => { | |||
}), | |||
queryBrowser: ImmutableMap({ | |||
metrics: [], | |||
pollInterval: null, | |||
pollInterval: undefined, |
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.
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.
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.
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 ?? {}; |
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.
You might want ||
instead of ??
in most of these cases. If you ever get annotations: null
, could that cause an error?
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.
Thanks @spadgett. After looking at this again, I ended up refactoring in a way that removes the need for these 2 ??
anyway.
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`.
b28adf9
to
c92fb26
Compare
@spadgett Rebased and addressed your feedback |
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
[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 |
/retest Please review the full test history for this PR and help us cut down flakes. |
4 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
Pass
query
andruleDuration
toGraph
instead of the wholerule
object to prevent some unnecessary re-rendering. This also removes the
need to memoize
queries
.Memoize
labels
inAlertsDetailsPage
to avoid triggering unnecessaryre-renders of
Graph
.Initialize
pollInterval
toundefined
instead ofnull
.null
indicates that polling was disabled, whereas
undefined
indicates thatit is not specified and the
QueryBrowser
should use its default pollinterval.