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

[Alerting UI] Display a banner to users when some alerts have failures, added alert statuses column and filters #79038

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ export async function loadAlerts({
searchText,
typesFilter,
actionTypesFilter,
alertStatusesFilter,
}: {
http: HttpSetup;
page: { index: number; size: number };
searchText?: string;
typesFilter?: string[];
actionTypesFilter?: string[];
alertStatusesFilter?: string[];
}): Promise<{
page: number;
perPage: number;
Expand All @@ -97,6 +99,9 @@ export async function loadAlerts({
].join('')
);
}
if (alertStatusesFilter && alertStatusesFilter.length) {
filters.push(`alert.attributes.executionStatus.status:(${alertStatusesFilter.join(' or ')})`);
Copy link
Member

Choose a reason for hiding this comment

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

TIL! Didn't realize you could do the ORs like this in KQL! Of course, I don't know KQL very well :-)

Actually, I thought KQL was sensitive to the case, and it had to be OR and not or, but maybe the rules are different outside of parenthesis ... or I'm just wrong on the case sensitivity.

}
return await http.get(`${BASE_ALERT_API_PATH}/_find`, {
query: {
page: page.index + 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EuiSwitch,
EuiBetaBadge,
EuiButtonEmpty,
EuiText,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { ViewInApp } from './view_in_app';
Expand Down Expand Up @@ -142,6 +143,38 @@ describe('alert_details', () => {
).toBeTruthy();
});

it('renders the alert error banner with error message, when alert status is an error', () => {
const alert = mockAlert({
executionStatus: {
status: 'error',
lastExecutionDate: new Date('2020-08-20T19:23:38Z'),
error: {
reason: 'unknown',
message: 'test',
},
},
});
const alertType = {
id: '.noop',
name: 'No Op',
actionGroups: [{ id: 'default', name: 'Default' }],
actionVariables: { context: [], state: [], params: [] },
defaultActionGroupId: 'default',
producer: ALERTS_FEATURE_ID,
authorizedConsumers,
};

expect(
shallow(
<AlertDetails alert={alert} alertType={alertType} actionTypes={[]} {...mockAlertApis} />
).containsMatchingElement(
<EuiText size="s" color="danger" data-test-subj="alertErrorMessageText">
{'test'}
</EuiText>
)
).toBeTruthy();
});

describe('actions', () => {
it('renders an alert action', () => {
const alert = mockAlert({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ import {
EuiSpacer,
EuiBetaBadge,
EuiButtonEmpty,
EuiButton,
EuiTextColor,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { AlertExecutionStatusValues } from '../../../../../../alerts/common';
import { useAppDependencies } from '../../../app_context';
import { hasAllPrivilege, hasExecuteActionsCapability } from '../../../lib/capabilities';
import { getAlertingSectionBreadcrumb, getAlertDetailsBreadcrumb } from '../../../lib/breadcrumb';
Expand Down Expand Up @@ -105,6 +108,7 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
const [isEnabled, setIsEnabled] = useState<boolean>(alert.enabled);
const [isMuted, setIsMuted] = useState<boolean>(alert.muteAll);
const [editFlyoutVisible, setEditFlyoutVisibility] = useState<boolean>(false);
const [dissmissAlertErrors, setDissmissAlertErrors] = useState<boolean>(false);

const setAlert = async () => {
history.push(routeToAlertDetails.replace(`:alertId`, alert.id));
Expand Down Expand Up @@ -275,6 +279,49 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
{!dissmissAlertErrors &&
alert.executionStatus.status === AlertExecutionStatusValues[2] ? (
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
<EuiFlexGroup>
<EuiFlexItem>
<EuiCallOut
color="danger"
data-test-subj="alertErrorBanner"
size="s"
title={
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertDetails.alertInstances.attentionBannerTitle"
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
defaultMessage="This alert has an error caused by the {errorReason} reason."
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
values={{
errorReason: alert.executionStatus.error?.reason,
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
}
iconType="alert"
>
<EuiTitle size="m">
<h3>
<EuiTextColor color="danger">
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertDetails.alertInstances.alertErrorMessageTitle"
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
defaultMessage="Error message:"
/>
</EuiTextColor>
</h3>
</EuiTitle>
<EuiText size="s" color="danger" data-test-subj="alertErrorMessageText">
{alert.executionStatus.error?.message}
</EuiText>
<EuiSpacer size="s" />
<EuiButton color="danger" onClick={() => setDissmissAlertErrors(true)}>
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertDetails.alertInstances.dismissButtonTitle"
defaultMessage="Dismiss"
Copy link
Contributor

Choose a reason for hiding this comment

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

@mdefazio did we decide to keep or remove the dismiss button? When dismissing, the banner returns next time I refresh the page.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's coming back after each refresh, then I don't think we include the dismiss option. It would be more annoying to dismiss it and it keep coming back as opposed to always seeing and not being able to do anything with it (until the errors are fixed)

/>
</EuiButton>
</EuiCallOut>
</EuiFlexItem>
</EuiFlexGroup>
) : null}
<EuiFlexGroup>
<EuiFlexItem>
{alert.enabled ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useEffect, useState } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import {
EuiFilterGroup,
EuiPopover,
EuiFilterButton,
EuiFilterSelectItem,
EuiHealth,
} from '@elastic/eui';
import { AlertExecutionStatusValues } from '../../../../../../alerts/common';

interface AlertStatusFilterProps {
onChange?: (selectedAlertStatusesIds: string[]) => void;
}

export const AlertStatusFilter: React.FunctionComponent<AlertStatusFilterProps> = ({
onChange,
}: AlertStatusFilterProps) => {
const [selectedValues, setSelectedValues] = useState<string[]>([]);
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);

useEffect(() => {
if (onChange) {
onChange(selectedValues);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedValues]);

return (
<EuiFilterGroup>
<EuiPopover
isOpen={isPopoverOpen}
closePopover={() => setIsPopoverOpen(false)}
button={
<EuiFilterButton
iconType="arrowDown"
hasActiveFilters={selectedValues.length > 0}
numActiveFilters={selectedValues.length}
numFilters={selectedValues.length}
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
>
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertsList.alertStatusFilterLabel"
defaultMessage="Status"
/>
</EuiFilterButton>
}
>
<div className="euiFilterSelect__items">
{[...AlertExecutionStatusValues].sort().map((item: string) => {
const healthColor = getHealthColor(item);
return (
<EuiFilterSelectItem
key={item}
style={{ textTransform: 'capitalize' }}
onClick={() => {
const isPreviouslyChecked = selectedValues.includes(item);
if (isPreviouslyChecked) {
setSelectedValues(selectedValues.filter((val) => val !== item));
} else {
setSelectedValues(selectedValues.concat(item));
}
}}
checked={selectedValues.includes(item) ? 'on' : undefined}
>
<EuiHealth color={healthColor}>{item}</EuiHealth>
</EuiFilterSelectItem>
);
})}
</div>
</EuiPopover>
</EuiFilterGroup>
);
};

export function getHealthColor(status: string) {
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
switch (status) {
case 'active':
return 'primary';
case 'error':
return 'danger';
case 'ok':
return 'subdued';
case 'pending':
return 'success';
default:
return 'warning';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ describe('alerts_list component with items', () => {
throttle: '1m',
muteAll: false,
mutedInstanceIds: [],
executionStatus: {
status: 'active',
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
lastExecutionDate: new Date('2020-08-20T19:23:38Z'),
error: null,
},
},
{
id: '2',
Expand All @@ -185,6 +190,14 @@ describe('alerts_list component with items', () => {
throttle: '1m',
muteAll: false,
mutedInstanceIds: [],
executionStatus: {
status: 'error',
lastExecutionDate: new Date('2020-08-20T19:23:38Z'),
error: {
reason: 'unknown',
message: 'test',
},
},
},
],
});
Expand Down Expand Up @@ -246,6 +259,7 @@ describe('alerts_list component with items', () => {
await setup();
expect(wrapper.find('EuiBasicTable')).toHaveLength(1);
expect(wrapper.find('EuiTableRow')).toHaveLength(2);
expect(wrapper.find('[data-test-subj="alertsTableCell-status"]')).toHaveLength(4);
});
});

Expand Down Expand Up @@ -351,6 +365,11 @@ describe('alerts_list with show only capability', () => {
throttle: '1m',
muteAll: false,
mutedInstanceIds: [],
executionStatus: {
status: 'active',
lastExecutionDate: new Date('2020-08-20T19:23:38Z'),
error: null,
},
},
{
id: '2',
Expand All @@ -368,6 +387,11 @@ describe('alerts_list with show only capability', () => {
throttle: '1m',
muteAll: false,
mutedInstanceIds: [],
executionStatus: {
status: 'active',
lastExecutionDate: new Date('2020-08-20T19:23:38Z'),
error: null,
},
},
],
});
Expand Down
Loading