-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Metrics UI] Fixes for editing alerts in alert management #64597
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ | |||||||||||||||||||||||||||||||||||||||||
* you may not use this file except in compliance with the Elastic License. | ||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
import React, { useCallback, useMemo, useEffect, useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||
import React, { ChangeEvent, useCallback, useMemo, useEffect, useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||||
EuiFlexGroup, | ||||||||||||||||||||||||||||||||||||||||||
EuiFlexItem, | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -13,6 +13,7 @@ import { | |||||||||||||||||||||||||||||||||||||||||
EuiText, | ||||||||||||||||||||||||||||||||||||||||||
EuiFormRow, | ||||||||||||||||||||||||||||||||||||||||||
EuiButtonEmpty, | ||||||||||||||||||||||||||||||||||||||||||
EuiFieldSearch, | ||||||||||||||||||||||||||||||||||||||||||
} from '@elastic/eui'; | ||||||||||||||||||||||||||||||||||||||||||
import { IFieldType } from 'src/plugins/data/public'; | ||||||||||||||||||||||||||||||||||||||||||
import { FormattedMessage } from '@kbn/i18n/react'; | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -211,14 +212,24 @@ export const Expressions: React.FC<Props> = props => { | |||||||||||||||||||||||||||||||||||||||||
setAlertParams('filterQuery', filter); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
setAlertParams('groupBy', md.currentOptions.groupBy); | ||||||||||||||||||||||||||||||||||||||||||
setAlertParams('groupBy', md.currentOptions.groupBy || ''); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
setAlertParams('sourceId', source?.id); | ||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||
setAlertParams('criteria', [defaultExpression]); | ||||||||||||||||||||||||||||||||||||||||||
if (!alertParams.criteria) { | ||||||||||||||||||||||||||||||||||||||||||
setAlertParams('criteria', [defaultExpression]); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
if (!alertParams.sourceId) { | ||||||||||||||||||||||||||||||||||||||||||
setAlertParams('sourceId', source?.id || 'default'); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
}, [alertsContext.metadata, defaultExpression, source]); // eslint-disable-line react-hooks/exhaustive-deps | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const handleFieldSearchChange = useCallback( | ||||||||||||||||||||||||||||||||||||||||||
(e: ChangeEvent<HTMLInputElement>) => onFilterQuerySubmit(e.target.value), | ||||||||||||||||||||||||||||||||||||||||||
[onFilterQuerySubmit] | ||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||
<> | ||||||||||||||||||||||||||||||||||||||||||
<EuiSpacer size={'m'} /> | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -273,48 +284,52 @@ export const Expressions: React.FC<Props> = props => { | |||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
<EuiSpacer size={'m'} /> | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
{alertsContext.metadata && ( | ||||||||||||||||||||||||||||||||||||||||||
<> | ||||||||||||||||||||||||||||||||||||||||||
<EuiFormRow | ||||||||||||||||||||||||||||||||||||||||||
label={i18n.translate('xpack.infra.metrics.alertFlyout.filterLabel', { | ||||||||||||||||||||||||||||||||||||||||||
defaultMessage: 'Filter (optional)', | ||||||||||||||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||||||||||||||
helpText={i18n.translate('xpack.infra.metrics.alertFlyout.filterHelpText', { | ||||||||||||||||||||||||||||||||||||||||||
defaultMessage: 'Use a KQL expression to limit the scope of your alert trigger.', | ||||||||||||||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||||||||||||||
fullWidth | ||||||||||||||||||||||||||||||||||||||||||
compressed | ||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||
<MetricsExplorerKueryBar | ||||||||||||||||||||||||||||||||||||||||||
derivedIndexPattern={derivedIndexPattern} | ||||||||||||||||||||||||||||||||||||||||||
onSubmit={onFilterQuerySubmit} | ||||||||||||||||||||||||||||||||||||||||||
value={alertParams.filterQuery} | ||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||
</EuiFormRow> | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
<EuiSpacer size={'m'} /> | ||||||||||||||||||||||||||||||||||||||||||
<EuiFormRow | ||||||||||||||||||||||||||||||||||||||||||
label={i18n.translate('xpack.infra.metrics.alertFlyout.createAlertPerText', { | ||||||||||||||||||||||||||||||||||||||||||
defaultMessage: 'Create alert per (optional)', | ||||||||||||||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||||||||||||||
helpText={i18n.translate('xpack.infra.metrics.alertFlyout.createAlertPerHelpText', { | ||||||||||||||||||||||||||||||||||||||||||
defaultMessage: | ||||||||||||||||||||||||||||||||||||||||||
'Create an alert for every unique value. For example: "host.id" or "cloud.region".', | ||||||||||||||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||||||||||||||
<EuiFormRow | ||||||||||||||||||||||||||||||||||||||||||
label={i18n.translate('xpack.infra.metrics.alertFlyout.filterLabel', { | ||||||||||||||||||||||||||||||||||||||||||
defaultMessage: 'Filter (optional)', | ||||||||||||||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||||||||||||||
helpText={i18n.translate('xpack.infra.metrics.alertFlyout.filterHelpText', { | ||||||||||||||||||||||||||||||||||||||||||
defaultMessage: 'Use a KQL expression to limit the scope of your alert trigger.', | ||||||||||||||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||||||||||||||
fullWidth | ||||||||||||||||||||||||||||||||||||||||||
compressed | ||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||
{(alertsContext.metadata && ( | ||||||||||||||||||||||||||||||||||||||||||
<MetricsExplorerKueryBar | ||||||||||||||||||||||||||||||||||||||||||
derivedIndexPattern={derivedIndexPattern} | ||||||||||||||||||||||||||||||||||||||||||
onSubmit={onFilterQuerySubmit} | ||||||||||||||||||||||||||||||||||||||||||
value={alertParams.filterQuery} | ||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||
)) || ( | ||||||||||||||||||||||||||||||||||||||||||
<EuiFieldSearch | ||||||||||||||||||||||||||||||||||||||||||
simianhacker marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
onChange={handleFieldSearchChange} | ||||||||||||||||||||||||||||||||||||||||||
value={alertParams.filterQuery} | ||||||||||||||||||||||||||||||||||||||||||
fullWidth | ||||||||||||||||||||||||||||||||||||||||||
compressed | ||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||
<MetricsExplorerGroupBy | ||||||||||||||||||||||||||||||||||||||||||
onChange={onGroupByChange} | ||||||||||||||||||||||||||||||||||||||||||
fields={derivedIndexPattern.fields} | ||||||||||||||||||||||||||||||||||||||||||
options={{ | ||||||||||||||||||||||||||||||||||||||||||
...options, | ||||||||||||||||||||||||||||||||||||||||||
groupBy: alertParams.groupBy || undefined, | ||||||||||||||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||
</EuiFormRow> | ||||||||||||||||||||||||||||||||||||||||||
</> | ||||||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||||||||||||||
</EuiFormRow> | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
<EuiSpacer size={'m'} /> | ||||||||||||||||||||||||||||||||||||||||||
<EuiFormRow | ||||||||||||||||||||||||||||||||||||||||||
label={i18n.translate('xpack.infra.metrics.alertFlyout.createAlertPerText', { | ||||||||||||||||||||||||||||||||||||||||||
defaultMessage: 'Create alert per (optional)', | ||||||||||||||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||||||||||||||
helpText={i18n.translate('xpack.infra.metrics.alertFlyout.createAlertPerHelpText', { | ||||||||||||||||||||||||||||||||||||||||||
defaultMessage: | ||||||||||||||||||||||||||||||||||||||||||
'Create an alert for every unique value. For example: "host.id" or "cloud.region".', | ||||||||||||||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||||||||||||||
fullWidth | ||||||||||||||||||||||||||||||||||||||||||
compressed | ||||||||||||||||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||||||||||||||
<MetricsExplorerGroupBy | ||||||||||||||||||||||||||||||||||||||||||
onChange={onGroupByChange} | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's actually a bug in the underlying alert library that won't let us kibana/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx Lines 151 to 152 in 0db04a7
setAlertParams('groupBy', group || ''); .
The bug in alerting is here: kibana/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_reducer.ts Lines 78 to 95 in daf6226
|
||||||||||||||||||||||||||||||||||||||||||
fields={derivedIndexPattern.fields} | ||||||||||||||||||||||||||||||||||||||||||
options={{ | ||||||||||||||||||||||||||||||||||||||||||
...options, | ||||||||||||||||||||||||||||||||||||||||||
groupBy: alertParams.groupBy || undefined, | ||||||||||||||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||
</EuiFormRow> | ||||||||||||||||||||||||||||||||||||||||||
</> | ||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||
|
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.
This call was actually not the problem. The one that needs to be updated is the
onGroupByChange
here:kibana/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx
Lines 148 to 153 in 12aae67