-
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] Missing data alert (#78208)
* WIP for alert * Surface alert most places * Fix up alert placement * Fix tests * Type fix * Update copy * Add alert presence to APM in the UI * Fetch data a little differently * We don't need moment * Add tests * PR feedback * Update copy * Fix up bug around grabbing old data * PR feedback * PR feedback * Fix tests
- Loading branch information
1 parent
198c5d9
commit a61f4d4
Showing
59 changed files
with
2,303 additions
and
89 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
23 changes: 23 additions & 0 deletions
23
x-pack/plugins/monitoring/public/alerts/filter_alert_states.ts
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,23 @@ | ||
/* | ||
* 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 { CommonAlertState, CommonAlertStatus } from '../../common/types'; | ||
|
||
export function filterAlertStates( | ||
alerts: { [type: string]: CommonAlertStatus }, | ||
filter: (type: string, state: CommonAlertState) => boolean | ||
) { | ||
return Object.keys(alerts).reduce( | ||
(accum: { [type: string]: CommonAlertStatus }, type: string) => { | ||
accum[type] = { | ||
...alerts[type], | ||
states: alerts[type].states.filter((state) => filter(type, state)), | ||
}; | ||
return accum; | ||
}, | ||
{} | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/monitoring/public/alerts/missing_monitoring_data_alert/expression.tsx
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,61 @@ | ||
/* | ||
* 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 { EuiForm, EuiSpacer } from '@elastic/eui'; | ||
import { CommonAlertParamDetails } from '../../../common/types'; | ||
import { AlertParamDuration } from '../flyout_expressions/alert_param_duration'; | ||
import { AlertParamType } from '../../../common/enums'; | ||
import { AlertParamPercentage } from '../flyout_expressions/alert_param_percentage'; | ||
|
||
export interface Props { | ||
alertParams: { [property: string]: any }; | ||
setAlertParams: (property: string, value: any) => void; | ||
setAlertProperty: (property: string, value: any) => void; | ||
errors: { [key: string]: string[] }; | ||
paramDetails: CommonAlertParamDetails; | ||
} | ||
|
||
export const Expression: React.FC<Props> = (props) => { | ||
const { alertParams, paramDetails, setAlertParams, errors } = props; | ||
|
||
const alertParamsUi = Object.keys(alertParams).map((alertParamName) => { | ||
const details = paramDetails[alertParamName]; | ||
const value = alertParams[alertParamName]; | ||
|
||
switch (details.type) { | ||
case AlertParamType.Duration: | ||
return ( | ||
<AlertParamDuration | ||
key={alertParamName} | ||
name={alertParamName} | ||
duration={value} | ||
label={details.label} | ||
errors={errors[alertParamName]} | ||
setAlertParams={setAlertParams} | ||
/> | ||
); | ||
case AlertParamType.Percentage: | ||
return ( | ||
<AlertParamPercentage | ||
key={alertParamName} | ||
name={alertParamName} | ||
label={details.label} | ||
percentage={value} | ||
errors={errors[alertParamName]} | ||
setAlertParams={setAlertParams} | ||
/> | ||
); | ||
} | ||
}); | ||
|
||
return ( | ||
<Fragment> | ||
<EuiForm component="form">{alertParamsUi}</EuiForm> | ||
<EuiSpacer /> | ||
</Fragment> | ||
); | ||
}; |
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/monitoring/public/alerts/missing_monitoring_data_alert/index.ts
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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { createMissingMonitoringDataAlertType } from './missing_monitoring_data_alert'; |
28 changes: 28 additions & 0 deletions
28
.../monitoring/public/alerts/missing_monitoring_data_alert/missing_monitoring_data_alert.tsx
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,28 @@ | ||
/* | ||
* 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 from 'react'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { AlertTypeModel } from '../../../../triggers_actions_ui/public/types'; | ||
import { validate } from './validation'; | ||
import { ALERT_MISSING_MONITORING_DATA } from '../../../common/constants'; | ||
import { Expression } from './expression'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { MissingMonitoringDataAlert } from '../../../server/alerts'; | ||
|
||
export function createMissingMonitoringDataAlertType(): AlertTypeModel { | ||
const alert = new MissingMonitoringDataAlert(); | ||
return { | ||
id: ALERT_MISSING_MONITORING_DATA, | ||
name: alert.label, | ||
iconClass: 'bell', | ||
alertParamsExpression: (props: any) => ( | ||
<Expression {...props} paramDetails={MissingMonitoringDataAlert.paramDetails} /> | ||
), | ||
validate, | ||
defaultActionMessage: '{{context.internalFullMessage}}', | ||
requiresAppContext: true, | ||
}; | ||
} |
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/monitoring/public/alerts/missing_monitoring_data_alert/validation.tsx
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,35 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { ValidationResult } from '../../../../triggers_actions_ui/public/types'; | ||
|
||
export function validate(opts: any): ValidationResult { | ||
const validationResult = { errors: {} }; | ||
|
||
const errors: { [key: string]: string[] } = { | ||
duration: [], | ||
limit: [], | ||
}; | ||
if (!opts.duration) { | ||
errors.duration.push( | ||
i18n.translate('xpack.monitoring.alerts.missingData.validation.duration', { | ||
defaultMessage: 'A valid duration is required.', | ||
}) | ||
); | ||
} | ||
if (!opts.limit) { | ||
errors.limit.push( | ||
i18n.translate('xpack.monitoring.alerts.missingData.validation.limit', { | ||
defaultMessage: 'A valid limit is required.', | ||
}) | ||
); | ||
} | ||
|
||
validationResult.errors = errors; | ||
return validationResult; | ||
} |
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
Oops, something went wrong.