-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Monitoring] Out of the box alerting (#68805)
* First draft, not quite working but a good start * More working * Support configuring throttle * Get the other alerts working too * More * Separate into individual files * Menu support as well as better integration in existing UIs * Red borders! * New overview style, and renamed alert * more visual updates * Update cpu usage and improve settings configuration in UI * Convert cluster health and license expiration alert to use legacy data model * Remove most of the custom UI and use the flyout * Add the actual alerts * Remove more code * Fix formatting * Fix up some errors * Remove unnecessary code * Updates * add more links here * Fix up linkage * Added nodes changed alert * Most of the version mismatch working * Add kibana mismatch * UI tweaks * Add timestamp * Support actions in the enable api * Move this around * Better support for changing legacy alerts * Add missing files * Update alerts * Enable alerts whenever any page is visited in SM * Tweaks * Use more practical default * Remove the buggy renderer and ensure setup mode can show all alerts * Updates * Remove unnecessary code * Remove some dead code * Cleanup * Fix snapshot * Fixes * Fixes * Fix test * Add alerts to kibana and logstash listing pages * Fix test * Add disable/mute options * Tweaks * Fix linting * Fix i18n * Adding a couple tests * Fix localization * Use http * Ensure we properly handle when an alert is resolved * Fix tests * Hide legacy alerts if not the right license * Design tweaks * Fix tests * PR feedback * Moar tests * Fix i18n * Ensure we have a control over the messaging * Fix translations * Tweaks * More localization * Copy changes * Type
- Loading branch information
1 parent
8da80fe
commit 06b1820
Showing
149 changed files
with
7,524 additions
and
5,861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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 { Alert } from '../../alerts/common'; | ||
import { AlertParamType } from './enums'; | ||
|
||
export interface CommonBaseAlert { | ||
type: string; | ||
label: string; | ||
paramDetails: CommonAlertParamDetails; | ||
rawAlert: Alert; | ||
isLegacy: boolean; | ||
} | ||
|
||
export interface CommonAlertStatus { | ||
exists: boolean; | ||
enabled: boolean; | ||
states: CommonAlertState[]; | ||
alert: CommonBaseAlert; | ||
} | ||
|
||
export interface CommonAlertState { | ||
firing: boolean; | ||
state: any; | ||
meta: any; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface CommonAlertFilter {} | ||
|
||
export interface CommonAlertCpuUsageFilter extends CommonAlertFilter { | ||
nodeUuid: string; | ||
} | ||
|
||
export interface CommonAlertParamDetail { | ||
label: string; | ||
type: AlertParamType; | ||
} | ||
|
||
export interface CommonAlertParamDetails { | ||
[name: string]: CommonAlertParamDetail; | ||
} | ||
|
||
export interface CommonAlertParams { | ||
[name: string]: string | number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
* 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, { Fragment } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
EuiContextMenu, | ||
EuiPopover, | ||
EuiBadge, | ||
EuiFlexGrid, | ||
EuiFlexItem, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { CommonAlertStatus, CommonAlertState } from '../../common/types'; | ||
import { AlertSeverity } from '../../common/enums'; | ||
// @ts-ignore | ||
import { formatDateTimeLocal } from '../../common/formatting'; | ||
import { AlertState } from '../../server/alerts/types'; | ||
import { AlertPanel } from './panel'; | ||
import { Legacy } from '../legacy_shims'; | ||
import { isInSetupMode } from '../lib/setup_mode'; | ||
|
||
function getDateFromState(states: CommonAlertState[]) { | ||
const timestamp = states[0].state.ui.triggeredMS; | ||
const tz = Legacy.shims.uiSettings.get('dateFormat:tz'); | ||
return formatDateTimeLocal(timestamp, false, tz === 'Browser' ? null : tz); | ||
} | ||
|
||
export const numberOfAlertsLabel = (count: number) => `${count} alert${count > 1 ? 's' : ''}`; | ||
|
||
interface Props { | ||
alerts: { [alertTypeId: string]: CommonAlertStatus }; | ||
} | ||
export const AlertsBadge: React.FC<Props> = (props: Props) => { | ||
const [showPopover, setShowPopover] = React.useState<AlertSeverity | boolean | null>(null); | ||
const inSetupMode = isInSetupMode(); | ||
const alerts = Object.values(props.alerts).filter(Boolean); | ||
|
||
if (alerts.length === 0) { | ||
return null; | ||
} | ||
|
||
const badges = []; | ||
|
||
if (inSetupMode) { | ||
const button = ( | ||
<EuiBadge | ||
iconType="bell" | ||
onClickAriaLabel={numberOfAlertsLabel(alerts.length)} | ||
onClick={() => setShowPopover(true)} | ||
> | ||
{numberOfAlertsLabel(alerts.length)} | ||
</EuiBadge> | ||
); | ||
const panels = [ | ||
{ | ||
id: 0, | ||
title: i18n.translate('xpack.monitoring.alerts.badge.panelTitle', { | ||
defaultMessage: 'Alerts', | ||
}), | ||
items: alerts.map(({ alert }, index) => { | ||
return { | ||
name: <EuiText>{alert.label}</EuiText>, | ||
panel: index + 1, | ||
}; | ||
}), | ||
}, | ||
...alerts.map((alertStatus, index) => { | ||
return { | ||
id: index + 1, | ||
title: alertStatus.alert.label, | ||
width: 400, | ||
content: <AlertPanel alert={alertStatus} />, | ||
}; | ||
}), | ||
]; | ||
|
||
badges.push( | ||
<EuiPopover | ||
id="monitoringAlertMenu" | ||
button={button} | ||
isOpen={showPopover === true} | ||
closePopover={() => setShowPopover(null)} | ||
panelPaddingSize="none" | ||
withTitle | ||
anchorPosition="downLeft" | ||
> | ||
<EuiContextMenu initialPanelId={0} panels={panels} /> | ||
</EuiPopover> | ||
); | ||
} else { | ||
const byType = { | ||
[AlertSeverity.Danger]: [] as CommonAlertStatus[], | ||
[AlertSeverity.Warning]: [] as CommonAlertStatus[], | ||
[AlertSeverity.Success]: [] as CommonAlertStatus[], | ||
}; | ||
|
||
for (const alert of alerts) { | ||
for (const alertState of alert.states) { | ||
const state = alertState.state as AlertState; | ||
byType[state.ui.severity].push(alert); | ||
} | ||
} | ||
|
||
const typesToShow = [AlertSeverity.Danger, AlertSeverity.Warning]; | ||
for (const type of typesToShow) { | ||
const list = byType[type]; | ||
if (list.length === 0) { | ||
continue; | ||
} | ||
|
||
const button = ( | ||
<EuiBadge | ||
iconType="bell" | ||
color={type} | ||
onClickAriaLabel={numberOfAlertsLabel(list.length)} | ||
onClick={() => setShowPopover(type)} | ||
> | ||
{numberOfAlertsLabel(list.length)} | ||
</EuiBadge> | ||
); | ||
|
||
const panels = [ | ||
{ | ||
id: 0, | ||
title: `Alerts`, | ||
items: list.map(({ alert, states }, index) => { | ||
return { | ||
name: ( | ||
<Fragment> | ||
<EuiText size="s"> | ||
<h4>{getDateFromState(states)}</h4> | ||
</EuiText> | ||
<EuiText>{alert.label}</EuiText> | ||
</Fragment> | ||
), | ||
panel: index + 1, | ||
}; | ||
}), | ||
}, | ||
...list.map((alertStatus, index) => { | ||
return { | ||
id: index + 1, | ||
title: getDateFromState(alertStatus.states), | ||
width: 400, | ||
content: <AlertPanel alert={alertStatus} />, | ||
}; | ||
}), | ||
]; | ||
|
||
badges.push( | ||
<EuiPopover | ||
id="monitoringAlertMenu" | ||
button={button} | ||
isOpen={showPopover === type} | ||
closePopover={() => setShowPopover(null)} | ||
panelPaddingSize="none" | ||
withTitle | ||
anchorPosition="downLeft" | ||
> | ||
<EuiContextMenu initialPanelId={0} panels={panels} /> | ||
</EuiPopover> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<EuiFlexGrid> | ||
{badges.map((badge, index) => ( | ||
<EuiFlexItem key={index} grow={false}> | ||
{badge} | ||
</EuiFlexItem> | ||
))} | ||
</EuiFlexGrid> | ||
); | ||
}; |
Oops, something went wrong.