Skip to content

Commit 2eacfea

Browse files
Merge pull request #607 from PeterYurkovich/ou-1031
OU-1031: Show the alert request error to the user
2 parents ad63db6 + e3d917d commit 2eacfea

File tree

6 files changed

+35
-67
lines changed

6 files changed

+35
-67
lines changed

web/src/components/alerting/AlertRulesPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ const AlertRulesPage_: FC = () => {
202202
onFilterChange={onFilterChange}
203203
rowFilters={rowFilters}
204204
/>
205-
{silences?.loadError && <SilencesNotLoadedWarning silencesLoadError={silences.loadError} />}
205+
{silences?.loadError && !rulesAlertLoading?.loadError && (
206+
<SilencesNotLoadedWarning silencesLoadError={silences.loadError} />
207+
)}
206208
<div id="alert-rules-table-scroll">
207209
<VirtualizedTable<Rule>
208210
aria-label={t('Alerting rules')}

web/src/components/alerting/AlertsPage.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import {
2828
severityRowFilter,
2929
SilencesNotLoadedWarning,
3030
} from './AlertUtils';
31-
import Error from './Error';
3231
import useSelectedFilters from './useSelectedFilters';
3332
import { MonitoringProvider } from '../../contexts/MonitoringContext';
3433
import { useAlerts } from '../../hooks/useAlerts';
34+
import { AccessDenied } from '../console/console-shared/src/components/empty-state/AccessDenied';
3535

3636
const AlertsPage_: FC = () => {
3737
const { t } = useTranslation(process.env.I18N_NAMESPACE);
@@ -115,7 +115,7 @@ const AlertsPage_: FC = () => {
115115

116116
const filteredAggregatedAlerts = getAggregateAlertsLists(filteredData);
117117
const loaded = !!rulesAlertLoading?.loaded;
118-
const loadError = rulesAlertLoading?.loadError ? rulesAlertLoading.loadError : null;
118+
const loadError = rulesAlertLoading?.loadError ? rulesAlertLoading.loadError : undefined;
119119

120120
return (
121121
<>
@@ -135,10 +135,11 @@ const AlertsPage_: FC = () => {
135135
<DownloadCSVButton loaded={loaded} filteredData={filteredAggregatedAlerts} />
136136
)}
137137
</Flex>
138-
{silences?.loadError && (
138+
{/* Only show the silences error when the alerts have loaded, since failing to load the
139+
silences doesn't matter if the alerts haven't loaded*/}
140+
{silences?.loadError && !loadError && (
139141
<SilencesNotLoadedWarning silencesLoadError={silences?.loadError} />
140142
)}
141-
142143
{filteredAggregatedAlerts?.length > 0 && loaded && (
143144
<Table gridBreakPoint={TableGridBreakpoint.none} role="presentation">
144145
<Thead>
@@ -159,8 +160,7 @@ const AlertsPage_: FC = () => {
159160
))}
160161
</Table>
161162
)}
162-
163-
{loadError && <Error error={loadError} />}
163+
{loadError && <AccessDenied message={loadError.message} />}
164164
{loaded && filteredAggregatedAlerts?.length === 0 && !loadError && (
165165
<EmptyBox label={t('Alerts')} />
166166
)}

web/src/components/alerting/Error.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
1-
import type { FC } from 'react';
2-
import { Alert, Flex, FlexItem } from '@patternfly/react-core';
1+
import { Alert, EmptyState, Flex, FlexItem } from '@patternfly/react-core';
32
import { useTranslation } from 'react-i18next';
4-
import { ConsoleEmptyState } from './ConsoleEmptyState';
5-
import * as restrictedSignImg from '../../../../imgs/restricted-sign.svg';
3+
import RestrictedSignImg from '../../../../imgs/restricted-sign.svg';
64

75
const RestrictedSignIcon = () => {
86
const { t } = useTranslation(process.env.I18N_NAMESPACE);
97

10-
return <img src={restrictedSignImg} alt={t('Restricted access')} />;
8+
return <img src={RestrictedSignImg} alt={t('Restricted access')} />;
119
};
1210

13-
export const AccessDenied: FC = ({ children }) => {
11+
export const AccessDenied = ({ message }: { message: string }) => {
1412
const { t } = useTranslation(process.env.I18N_NAMESPACE);
1513

1614
return (
17-
<ConsoleEmptyState
18-
data-test="access-denied"
19-
Icon={RestrictedSignIcon}
20-
title={t('Restricted access')}
21-
>
15+
<EmptyState data-test="access-denied" icon={RestrictedSignIcon} title={t('Restricted access')}>
2216
<Flex direction={{ default: 'column' }}>
2317
<FlexItem>{t("You don't have access to this section due to cluster policy")}</FlexItem>
24-
{children && (
25-
<FlexItem>
26-
<Alert variant="danger" title={t('Error details')}>
27-
{children}
28-
</Alert>
29-
</FlexItem>
30-
)}
18+
<FlexItem>
19+
<Alert variant="danger" title={t('Error details')}>
20+
{message}
21+
</Alert>
22+
</FlexItem>
3123
</Flex>
32-
</ConsoleEmptyState>
24+
</EmptyState>
3325
);
3426
};
35-
AccessDenied.displayName = 'AccessDenied';

web/src/components/console/console-shared/src/components/status/StatusBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const StatusBox: FC<StatusBoxProps> = (props) => {
5454
);
5555
}
5656
if (status === 403) {
57-
return <AccessDenied>{loadError.message}</AccessDenied>;
57+
return <AccessDenied message={loadError.message} />;
5858
}
5959

6060
if (loadError instanceof IncompleteDataError && !_.isEmpty(data)) {

web/src/store/thunks.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,27 @@ export const fetchAlertingData =
3333
]);
3434

3535
if (rulesResponse.status === 'rejected') {
36+
if (rulesResponse.reason?.response) {
37+
// Set the error message to be the RBAC denial reason
38+
const responseText = await rulesResponse.reason?.response?.text();
39+
if (responseText) {
40+
rulesResponse.reason.message = responseText;
41+
}
42+
}
3643
dispatch(alertingSetErrored(prometheus, namespace, rulesResponse.reason));
3744
} else {
3845
const { alerts, rules } = getAlertsAndRules(rulesResponse.value.data);
3946
dispatch(alertingSetRulesLoaded(prometheus, namespace, rules, alerts));
4047
}
4148

4249
if (silencesResponse.status === 'rejected') {
50+
if (silencesResponse.reason?.response) {
51+
// Set the error message to be the RBAC denial reason
52+
const responseText = await silencesResponse.reason?.response?.text();
53+
if (responseText) {
54+
silencesResponse.reason.message = responseText;
55+
}
56+
}
4357
dispatch(alertingSetSilencesErrored(prometheus, namespace, silencesResponse.reason));
4458
} else {
4559
const silences = silencesResponse.value.map((silence) => ({

0 commit comments

Comments
 (0)