Skip to content
Closed
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion public/app/features/alerting/unified/utils/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,21 @@ export function isAsyncRequestMapSliceFulfilled<T>(slice: AsyncRequestMapSlice<T
}

export function isAsyncRequestStateFulfilled<T>(state: AsyncRequestState<T>): boolean {
return state.dispatched && !state.loading && !state.error;
return isAsyncRequestStateSettled(state) && !state.error;
}

export function isAsyncRequestStateSettled<T>(state: AsyncRequestState<T>): boolean {
return state.dispatched && !state.loading;
}

export function isAsyncRequestMapSlicePending<T>(slice: AsyncRequestMapSlice<T>): boolean {
return Object.values(slice).some(isAsyncRequestStatePending);
}

export function isAsyncRequestMapSliceSettled<T>(slice: AsyncRequestMapSlice<T>): boolean {
return Object.values(slice).every(isAsyncRequestStateSettled);
}

export function isAsyncRequestStatePending<T>(state?: AsyncRequestState<T>): boolean {
if (!state) {
return false;
Expand Down
8 changes: 4 additions & 4 deletions public/app/plugins/panel/alertlist/GroupByWithLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { useUnifiedAlertingSelector } from 'app/features/alerting/unified/hooks/
import { fetchAllPromRulesAction } from 'app/features/alerting/unified/state/actions';
import { getAllRulesSourceNames } from 'app/features/alerting/unified/utils/datasource';
import {
isAsyncRequestMapSliceFulfilled,
isAsyncRequestMapSlicePending,
isAsyncRequestMapSliceSettled,
} from 'app/features/alerting/unified/utils/redux';
import { useDispatch } from 'app/types';
import { AlertingRule } from 'app/types/unified-alerting';
Expand All @@ -33,15 +33,15 @@ export const GroupBy: FC<Props> = (props) => {
const promRulesByDatasource = useUnifiedAlertingSelector((state) => state.promRules);
const rulesDataSourceNames = useMemo(getAllRulesSourceNames, []);

const allRequestsReady = isAsyncRequestMapSliceFulfilled(promRulesByDatasource);
Copy link
Contributor

Choose a reason for hiding this comment

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

👏

const allRequestsSettled = isAsyncRequestMapSliceSettled(promRulesByDatasource);
const loading = isAsyncRequestMapSlicePending(promRulesByDatasource);

const labels = useMemo(() => {
if (isEmpty(promRulesByDatasource)) {
return [];
}

if (!allRequestsReady) {
if (!allRequestsSettled) {
return [];
}

Expand All @@ -54,7 +54,7 @@ export const GroupBy: FC<Props> = (props) => {
.flatMap((labels) => labels.filter(isPrivateLabel));

return uniq(allLabels);
}, [allRequestsReady, promRulesByDatasource, rulesDataSourceNames]);
}, [allRequestsSettled, promRulesByDatasource, rulesDataSourceNames]);

return (
<MultiSelect<string>
Expand Down
21 changes: 14 additions & 7 deletions public/app/plugins/panel/alertlist/UnifiedAlertList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,20 @@ function filterRules(props: PanelProps<UnifiedAlertListOptions>, rules: PromRule
);
}

filteredRules = filteredRules.filter((rule) => {
return (
(options.stateFilter.firing && rule.rule.state === PromAlertingRuleState.Firing) ||
(options.stateFilter.pending && rule.rule.state === PromAlertingRuleState.Pending) ||
(options.stateFilter.normal && rule.rule.state === PromAlertingRuleState.Inactive)
);
});
// skip filtering by the alert rule's state if we've selected "nodata" or "error" as a filter condition.
// the alert rule state is not reflected if we have any instances matching that state
// this means that an instance might be "nodata" or "error" but the alert rule it belongs to will be "normal"
const isInstanceStateFilter = options.stateFilter.noData || options.stateFilter.error;

if (!isInstanceStateFilter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the user selected nodata, error and e.g firing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will only show the "firing" alert rules when in "default grouping" but for "custom grouping" it will show nodata, error and firing.

I'll need to figure out how to also make it work for the "default grouping" 🤔

filteredRules = filteredRules.filter((rule) => {
return (
(options.stateFilter.firing && rule.rule.state === PromAlertingRuleState.Firing) ||
(options.stateFilter.pending && rule.rule.state === PromAlertingRuleState.Pending) ||
(options.stateFilter.normal && rule.rule.state === PromAlertingRuleState.Inactive)
);
});
}

if (options.alertInstanceLabelFilter) {
const replacedLabelFilter = replaceVariables(options.alertInstanceLabelFilter);
Expand Down