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

[release-4.16] OCPBUGS-44885: include external labels so silenced alerts not displayed in notifications #14530

Open
wants to merge 1 commit into
base: release-4.16
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions frontend/public/components/monitoring/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Silence,
SilenceStates,
PrometheusRulesResponse,
PerspectiveType,
} from '@console/dynamic-plugin-sdk';

import { AlertSource, MonitoringResource, Target } from './types';
Expand Down Expand Up @@ -49,6 +50,7 @@ export const alertURL = (alert: Alert, ruleID: string) =>

export const getAlertsAndRules = (
data: PrometheusRulesResponse['data'],
perspective: PerspectiveType = 'admin',
): { alerts: Alert[]; rules: Rule[] } => {
// Flatten the rules data to make it easier to work with, discard non-alerting rules since those
// are the only ones we will be using and add a unique ID to each rule.
Expand All @@ -69,6 +71,15 @@ export const getAlertsAndRules = (
return _.filter(g.rules, { type: 'alerting' }).map(addID);
});

// The console codebase and developer perspective actions don't expect the external labels to be
// included on the alerts
if (perspective !== 'dev') {
// Add external labels to all `rules[].alerts[].labels`
rules.forEach((rule) => {
rule.alerts.forEach((alert) => (alert.labels = { ...rule.labels, ...alert.labels }));
});
}

// Add `rule` object to each alert
const alerts = _.flatMap(rules, (rule) => rule.alerts.map((a) => ({ rule, ...a })));

Expand Down