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

Add Notifications coloumn in alerts table #5943

Merged
merged 2 commits into from Jul 27, 2020

Conversation

vikram-raj
Copy link
Member

@vikram-raj vikram-raj commented Jul 10, 2020

Story - https://issues.redhat.com/browse/ODC-4119

Description
This PR

  • Adds the Notification column to the Alerts table and switch button to silence the notification for the alert.
  • Adds the kebab action menu to view the alerting rule detail page.

Screenshots
Screenshot 2020-07-10 at 6 48 47 PM

Screenshot 2020-07-10 at 6 49 05 PM

Screenshot 2020-07-22 at 9 55 21 AM

Screenshot 2020-07-10 at 6 50 18 PM

Screenshot 2020-07-21 at 9 42 16 AM

Test setup:

  1. oc apply -f https://gist.githubusercontent.com/vikram-raj/c14c080f33c5bdd4125f3ba9e9096509/raw/6ae3bd8cb2aff873aad76b6edb9d893117d0bf55/prometheus-example-app.yaml
  2. oc apply -f https://gist.githubusercontent.com/vikram-raj/d1b220d43e219829da9045d72ef5a580/raw/d5ca2f0a616068f0c8f7023757ccb5626dee26bc/user-workload-config.yaml
    It will create a rule and an alert for the same rule in ns1 namespace

@openshift-ci-robot openshift-ci-robot added component/dev-console Related to dev-console component/monitoring Related to monitoring labels Jul 10, 2020
@vikram-raj
Copy link
Member Author

/hold
Depend on PR #5785

@openshift-ci-robot openshift-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 10, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 21, 2020
@vikram-raj
Copy link
Member Author

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 21, 2020
@vikram-raj
Copy link
Member Author

/cc @cshinn

};

const SILENCE_FOR = 'Silence for ';
const durations = [SILENCE_FOR, '30m', '1h', '2h', '6h', '12h', '1d', '2d', '1w'];
Copy link
Member

Choose a reason for hiding this comment

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

Mocks have dropdown labels like 30 minutes, 1 hour, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

isOpen: rls.state === RuleStates.Firing && !_.includes(collapsedRowsIds, rls.name),
isOpen:
(rls.state === RuleStates.Firing && !_.includes(collapsedRowsIds, rls.name)) ||
(rls.state !== RuleStates.Firing && _.includes(collapsedRowsIds, rls.name)),
Copy link
Member

Choose a reason for hiding this comment

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

Is this right? Shouldn't collapsed rows always be isOpen = false?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, collapsed rows always be isOpen = false. But when the user expands it should be expanded to handle this scenario I added this. I missed this scenario in my last PR.

const rows = [];
_.forEach(alertrules, (rls) => {
rows.push({
...(rls.state !== RuleStates.Inactive && {
isOpen: rls.state === RuleStates.Firing && !_.includes(collapsedRowsIds, rls.name),
isOpen:
(rls.state === RuleStates.Firing && !_.includes(collapsedRowsIds, rls.name)) ||
Copy link
Member

Choose a reason for hiding this comment

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

Not introduced by this PR, but it now occurs to me that using the rule name as row key will fail if we have two rules with the same name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't alertname is going to be unique for a namespace?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I forgot this was constrained by namespace.

So, this is the same situation as our silence rule discussion. alertname is not technically guaranteed to be unique even within a namespace, but in practice it almost certainly will be. I think this is acceptable for now, but we should probably have a more robust solution at some point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed it, now I am using rules id instead of the name.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@kyoto
Copy link
Member

kyoto commented Jul 21, 2020

Noticed that the Notifications switch state is getting switched back to on when the poller fetches fresh data.

Also, the alignment is off at narrow screen widths:
screenshot

<Switch
aria-label="Silence switch"
className="odc-silence-alert"
label="On"
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just omit the label prop. Then you don't need the .pf-c-switch__label.pf-m-on display: none CSS.

Copy link
Member Author

Choose a reason for hiding this comment

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

To add labelOff prop label prop is required.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like you can set label to null, then you can still use labelOff without needing the CSS.

@vikram-raj vikram-raj force-pushed the alerts-silence branch 5 times, most recently from 7d8967e to 83c6ab3 Compare July 22, 2020 07:07
const { alertManagerBaseURL } = window.SERVER_FLAGS;

const SilenceUntil = ({ rule }) => {
if (alert && !_.isEmpty(rule.silencedBy)) {
Copy link
Member

Choose a reason for hiding this comment

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

This alert && looks unnecessary

const SilenceAlert: React.FC<SilenceAlertProps> = ({ rule, namespace }) => {
const [isChecked, setIsChecked] = React.useState(true);
React.useEffect(
() => (rule.state === RuleStates.Silenced ? setIsChecked(false) : setIsChecked(true)),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
() => (rule.state === RuleStates.Silenced ? setIsChecked(false) : setIsChecked(true)),
() => setIsChecked(rule.state !== RuleStates.Silenced)

const SilenceDurationDropDown: React.FC<SilenceDurationDropDownProps> = ({ rule, namespace }) => {
const createdBy = useSelector((state: RootState) => state.UI.get('user')?.metadata?.name);

const matchers = [
Copy link
Member

Choose a reason for hiding this comment

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

Should also add matchers for any additional labels found in rule.labels.

@@ -59,6 +59,26 @@ const silenceFiringAlerts = (firingAlerts, silences) => {
});
};

const silenceFiringRules = (firingRules, silences) => {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we can make this much simper by removing silenceFiringRules and leaving MonitoringSetRules unchanged. Then modify silenceFiringAlerts instead.

silenceFiringAlerts is already being run when the rules are imported, and already does much of the work to determine which alerts are silenced.

Modify silenceFiringAlerts by adding the following (or something similar) inside the if (a.silencedBy.length) { ... } block.

if (!_.isEmpty(a.rule.alerts) && _.every(a.rule.alerts, isSilenced)) {
  a.rule.state = RuleStates.Silenced;
  a.rule.silencedBy = _.filter(
    silences?.data,
    (s) => s.status.state === SilenceStates.Active && _.some(a.rule.alerts, isSilenced),
  );
}

(briefly tested, but not properly)

Comment on lines 29 to 33
const ruleLabelKeys = _.keys(rule?.labels);
const ruleLabelValues = _.values(rule?.labels);
const ruleMatchers = _.zipWith(ruleLabelKeys, ruleLabelValues, (key, value) => {
return { name: key, value, isRegex: false };
});
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const ruleLabelKeys = _.keys(rule?.labels);
const ruleLabelValues = _.values(rule?.labels);
const ruleMatchers = _.zipWith(ruleLabelKeys, ruleLabelValues, (key, value) => {
return { name: key, value, isRegex: false };
});
const ruleMatchers = _.map(rule?.labels, (value, key) => ({ isRegex: false, name: key, value }));

@kyoto
Copy link
Member

kyoto commented Jul 27, 2020

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kyoto, vikram-raj

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-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 27, 2020
@openshift-merge-robot openshift-merge-robot merged commit f1fc779 into openshift:master Jul 27, 2020
@vikram-raj vikram-raj deleted the alerts-silence branch July 27, 2020 12:13
@spadgett spadgett added this to the v4.6 milestone Jul 28, 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/dev-console Related to dev-console 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