-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] Alerting rule for Anomaly Detection jobs monitoring #106084
Merged
darnautov
merged 42 commits into
elastic:master
from
darnautov:ml-101028-operational-alerting-rule
Jul 22, 2021
Merged
Changes from 10 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
3be0912
[ML] init job health alerting rule type
darnautov 56f7c27
[ML] add health checks selection ui
darnautov 7fbee4e
[ML] define schema
darnautov ea4b8eb
[ML] support all jobs selection
darnautov 6e2de45
[ML] jobs health service
darnautov 69e3559
[ML] add logger
darnautov 5837710
[ML] add context message
darnautov 098f890
[ML] fix default message for i18n
darnautov 7d3963e
Merge remote-tracking branch 'upstream/master' into ml-101028-operati…
darnautov 3ec6274
[ML] check response size
darnautov d3832a1
[ML] add exclude jobs control
darnautov 4c6d17e
[ML] getResultJobsHealthRuleConfig
darnautov 5f886cb
[ML] change naming for shared services
darnautov 2022054
[ML] fix excluded jobs filtering
darnautov 17e45e1
[ML] check for execution results
darnautov 576d006
[ML] update context fields
darnautov 353e495
[ML] unit tests for getResultJobsHealthRuleConfig
darnautov f752dc2
[ML] refactor and job ids check
darnautov b08031e
[ML] rename datafeed
darnautov 29f547a
[ML] fix translation messages
darnautov f756df2
[ML] hide non-implemented tests
darnautov 2a1eb82
[ML] remove jod ids join from the getJobs call
darnautov bd96959
[ML] add validation for the tests config
darnautov b552dda
[ML] fix excluded jobs udpate
darnautov c391133
[ML] update jobIdsDescription message
darnautov ff5db7e
[ML] allow selection all jobs only for include
darnautov 8c7b6e6
[ML] better ux for excluded jobs setup
darnautov b74005d
[ML] change rule type name
darnautov bc86e23
[ML] fix typo
darnautov 817fd62
[ML] change instances names
darnautov 9c0b3ec
[ML] fix messages
darnautov 2ada9eb
[ML] hide error callout, show health checks error in EuiFormRow
darnautov 599d122
[ML] add check for job state
darnautov 37865f6
[ML] add alertingRules key to the doc links
darnautov 541140f
Merge remote-tracking branch 'upstream/master' into ml-101028-operati…
darnautov 23e74e6
[ML] update types
darnautov 8c3b9dd
[ML] remove redundant type
darnautov a6e0f92
[ML] fix job and datafeed states check
darnautov 65dbb89
[ML] fix job and datafeed states check, add comments
darnautov 584bcbf
Merge branch 'master' into ml-101028-operational-alerting-rule
kibanamachine af0e7c1
[ML] add unit tests
darnautov 9334f32
Merge remote-tracking branch 'origin/ml-101028-operational-alerting-r…
darnautov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
75 changes: 75 additions & 0 deletions
75
...lugins/ml/public/alerting/jobs_health_rule/anomaly_detection_jobs_health_rule_trigger.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,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { FC, useCallback, useMemo } from 'react'; | ||
import { EuiForm, EuiSpacer } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { AlertTypeParamsExpressionProps } from '../../../../triggers_actions_ui/public'; | ||
import { MlAnomalyDetectionJobsHealthRuleParams } from '../../../common/types/alerts'; | ||
import { JobSelectorControl } from '../job_selector'; | ||
import { jobsApiProvider } from '../../application/services/ml_api_service/jobs'; | ||
import { HttpService } from '../../application/services/http_service'; | ||
import { useMlKibana } from '../../application/contexts/kibana'; | ||
import { TestsSelectionControl } from './tests_selection_control'; | ||
|
||
export type MlAnomalyAlertTriggerProps = AlertTypeParamsExpressionProps<MlAnomalyDetectionJobsHealthRuleParams>; | ||
|
||
const AnomalyDetectionJobsHealthRuleTrigger: FC<MlAnomalyAlertTriggerProps> = ({ | ||
alertParams, | ||
setAlertParams, | ||
errors, | ||
}) => { | ||
const { | ||
services: { http }, | ||
} = useMlKibana(); | ||
const mlHttpService = useMemo(() => new HttpService(http), [http]); | ||
const adJobsApiService = useMemo(() => jobsApiProvider(mlHttpService), [mlHttpService]); | ||
|
||
const jobsAndGroupIds: string[] = useMemo( | ||
() => (Object.values(alertParams.includeJobs ?? {}) as string[][]).flat(), | ||
[alertParams.includeJobs] | ||
); | ||
|
||
const onAlertParamChange = useCallback( | ||
<T extends keyof MlAnomalyDetectionJobsHealthRuleParams>(param: T) => ( | ||
update: MlAnomalyDetectionJobsHealthRuleParams[T] | ||
) => { | ||
setAlertParams(param, update); | ||
}, | ||
[] | ||
); | ||
|
||
return ( | ||
<EuiForm data-test-subj={'mlJobsHealthAlertingRuleForm'}> | ||
<JobSelectorControl | ||
jobsAndGroupIds={jobsAndGroupIds} | ||
adJobsApiService={adJobsApiService} | ||
onChange={useCallback(onAlertParamChange('includeJobs'), [])} | ||
errors={Array.isArray(errors.includeJobs) ? errors.includeJobs : []} | ||
multiSelect | ||
label={ | ||
<FormattedMessage | ||
id="xpack.ml.alertTypes.jobsHealthAlertingRule.includeJobs.label" | ||
defaultMessage="Include jobs or groups" | ||
/> | ||
} | ||
/> | ||
|
||
<EuiSpacer size="m" /> | ||
|
||
<TestsSelectionControl | ||
config={alertParams.testsConfig} | ||
onChange={useCallback(onAlertParamChange('testsConfig'), [])} | ||
/> | ||
</EuiForm> | ||
); | ||
}; | ||
|
||
// Default export is required for React.lazy loading | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default AnomalyDetectionJobsHealthRuleTrigger; |
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,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { registerJobsHealthAlertingRule } from './register_jobs_health_alerting_rule'; |
57 changes: 57 additions & 0 deletions
57
x-pack/plugins/ml/public/alerting/jobs_health_rule/register_jobs_health_alerting_rule.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,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { lazy } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { TriggersAndActionsUIPublicPluginSetup } from '../../../../triggers_actions_ui/public'; | ||
import { PluginSetupContract as AlertingSetup } from '../../../../alerting/public'; | ||
import { ML_ALERT_TYPES } from '../../../common/constants/alerts'; | ||
import { MlAnomalyDetectionJobsHealthRuleParams } from '../../../common/types/alerts'; | ||
|
||
export function registerJobsHealthAlertingRule( | ||
triggersActionsUi: TriggersAndActionsUIPublicPluginSetup, | ||
alerting?: AlertingSetup | ||
) { | ||
triggersActionsUi.alertTypeRegistry.register({ | ||
id: ML_ALERT_TYPES.AD_JOBS_HEALTH, | ||
description: i18n.translate('xpack.ml.alertTypes.jobsHealthAlertingRule.description', { | ||
defaultMessage: 'Alert when anomaly detection jobs experiencing realtime issues.', | ||
}), | ||
iconClass: 'bell', | ||
documentationUrl(docLinks) { | ||
return `${docLinks.ELASTIC_WEBSITE_URL}guide/en/machine-learning/${docLinks.DOC_LINK_VERSION}/ml-configuring-alerts.html`; | ||
lcawl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
alertParamsExpression: lazy(() => import('./anomaly_detection_jobs_health_rule_trigger')), | ||
validate: (alertParams: MlAnomalyDetectionJobsHealthRuleParams) => { | ||
darnautov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const validationResult = { | ||
darnautov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
errors: { | ||
includeJobs: new Array<string>(), | ||
} as Record<keyof MlAnomalyDetectionJobsHealthRuleParams, string[]>, | ||
}; | ||
|
||
if (!alertParams.includeJobs?.jobIds?.length && !alertParams.includeJobs?.groupIds?.length) { | ||
validationResult.errors.includeJobs.push( | ||
i18n.translate('xpack.ml.alertTypes.jobsHealthAlertingRule.includeJobs.errorMessage', { | ||
defaultMessage: 'Job selection is required', | ||
lcawl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
); | ||
} | ||
|
||
return validationResult; | ||
}, | ||
requiresAppContext: false, | ||
defaultActionMessage: i18n.translate( | ||
'xpack.ml.alertTypes.jobsHealthAlertingRule.defaultActionMessage', | ||
{ | ||
defaultMessage: `Anomaly detection jobs health check result: | ||
\\{\\{context.message\\}\\} | ||
- Job IDs: \\{\\{context.jobIds\\}\\} | ||
`, | ||
} | ||
), | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all of the conditions will affect real-time jobs, so I think this should read
Alert when anomaly detection jobs experience operational issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 9c0b3ec