Skip to content

Commit

Permalink
Merge pull request #6460 from kyoto/monitoring-filter-rules-by-alert-…
Browse files Browse the repository at this point in the history
…state

Bug 1871676: Monitoring: Change rules list to filter by alert state, not rule state
  • Loading branch information
openshift-merge-robot committed Sep 1, 2020
2 parents bbdefb2 + 395682a commit f089866
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
6 changes: 3 additions & 3 deletions frontend/public/components/factory/table-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../../module/k8s';
import {
alertDescription,
alertingRuleIsActive,
alertingRuleHasAlertState,
alertingRuleSource,
alertSource,
alertState,
Expand Down Expand Up @@ -64,8 +64,8 @@ export const tableFilters: TableFilterMap = {
'alert-state': (filter, alert: Alert) =>
filter.selected.has(alertState(alert)) || _.isEmpty(filter.selected),

'alerting-rule-active': (filter, rule: Rule) =>
filter.selected.has(alertingRuleIsActive(rule)) || _.isEmpty(filter.selected),
'alerting-rule-has-alert-state': (filter, rule: Rule) =>
alertingRuleHasAlertState(rule, filter.selected) || _.isEmpty(filter.selected),

'alerting-rule-name': (filter, rule: Rule) => fuzzyCaseInsensitive(filter, rule.name),

Expand Down
1 change: 1 addition & 0 deletions frontend/public/components/factory/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ export type TableProps = {
loaded?: boolean;
reduxID?: string;
reduxIDs?: string[];
rowFilters?: any[];
label?: string;
columnManagementID?: string;
};
Expand Down
7 changes: 5 additions & 2 deletions frontend/public/components/filter-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const getDropdownItems = (rowFilters: RowFilter[], selectedItems, data, props) =
</span>
<span className="co-filter-dropdown-item__name">{item.title}</span>
<Badge key={item.id} isRead>
{_.countBy(data, grp.reducer)?.[item.id] ?? '0'}
{grp.isMatch
? _.filter(data, (d) => grp.isMatch(d, item.id)).length
: _.countBy(data, grp.reducer)?.[item.id] ?? '0'}
</Badge>
</div>
</DropdownItem>
Expand Down Expand Up @@ -379,12 +381,13 @@ type FilterToolbarProps = {
export type RowFilter<R = any> = {
defaultSelected?: string[];
filterGroupName: string;
isMatch?: (param: R, id: string) => boolean;
type: string;
items?: {
[key: string]: string;
}[];
itemsGenerator?: (...args) => { [key: string]: string }[];
reducer: (param: R) => React.ReactText;
reducer?: (param: R) => React.ReactText;
filter?: any;
};

Expand Down
21 changes: 15 additions & 6 deletions frontend/public/components/monitoring/alerting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
import { K8sKind } from '../../module/k8s';
import {
alertDescription,
alertingRuleIsActive,
alertingRuleSource,
alertSource,
alertState,
Expand Down Expand Up @@ -1273,6 +1272,7 @@ const MonitoringListPage_: React.FC<ListPageProps> = ({
loadError={loadError}
reduxID={reduxID}
Row={Row}
rowFilters={rowFilters}
virtualize
/>
</div>
Expand Down Expand Up @@ -1301,15 +1301,24 @@ const AlertsPage_: React.FC<Alerts> = ({ data, loaded, loadError }) => (
);
const AlertsPage = withFallback(connect(alertsToProps)(AlertsPage_));

const ruleHasAlertState = (rule: Rule, state: AlertStates): boolean =>
_.some(rule.alerts, { state });

const ruleAlertStateFilter = (filter, rule: Rule) =>
_.some(rule.alerts, (a) => filter.selected.has(a.state)) || _.isEmpty(filter.selected);

const rulesRowFilters: RowFilter[] = [
{
filterGroupName: 'Rule State',
filter: ruleAlertStateFilter,
filterGroupName: 'Alert State',
isMatch: ruleHasAlertState,
items: [
{ id: 'true', title: 'Active' },
{ id: 'false', title: 'Inactive' },
{ id: AlertStates.Firing, title: 'Firing' },
{ id: AlertStates.Pending, title: 'Pending' },
{ id: AlertStates.Silenced, title: 'Silenced' },
{ id: AlertStates.NotFiring, title: 'Not Firing' },
],
reducer: alertingRuleIsActive,
type: 'alerting-rule-active',
type: 'alerting-rule-has-alert-state',
},
severityRowFilter,
{
Expand Down
1 change: 1 addition & 0 deletions frontend/public/components/monitoring/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const enum AlertSource {

export const enum AlertStates {
Firing = 'firing',
NotFiring = 'not-firing',
Pending = 'pending',
Silenced = 'silenced',
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/public/reducers/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
export const alertState = (a: Alert): AlertStates => a?.state;
export const silenceState = (s: Silence): SilenceStates => s?.status?.state;

export const alertingRuleIsActive = (rule: Rule): string =>
rule.state === 'inactive' ? 'false' : 'true';
export const alertingRuleHasAlertState = (rule: Rule, state: AlertStates) =>
state === AlertStates.NotFiring ? rule.alerts.length === 0 : _.some(rule.alerts, { state });

export const alertingRuleSource = (rule: Rule): AlertSource =>
rule.labels?.prometheus === 'openshift-monitoring/k8s' ? AlertSource.Platform : AlertSource.User;
Expand Down

0 comments on commit f089866

Please sign in to comment.