-
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
[RAC] Rename occurrences of alert_type to rule_type in Infra #120455
Changes from 1 commit
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 |
---|---|---|
|
@@ -8,16 +8,15 @@ | |
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { METRIC_ANOMALY_ALERT_TYPE_ID } from '../../../common/alerting/metrics'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { AlertTypeModel } from '../../../../triggers_actions_ui/public/types'; | ||
import { AlertTypeParams } from '../../../../alerting/common'; | ||
import { AlertTypeModel } from '../../../../triggers_actions_ui/public'; | ||
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 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. I am not sure if we should rename this now? Because we will refactor triggers_actions_ui too, then we can tackle these imports by searching by the usages. |
||
import { AlertTypeParams as RuleTypeParams } from '../../../../alerting/common'; | ||
import { validateMetricAnomaly } from './components/validation'; | ||
|
||
interface MetricAnomalyAlertTypeParams extends AlertTypeParams { | ||
interface MetricAnomalyRuleTypeParams extends RuleTypeParams { | ||
hasInfraMLCapabilities: boolean; | ||
} | ||
|
||
export function createMetricAnomalyAlertType(): AlertTypeModel<MetricAnomalyAlertTypeParams> { | ||
export function createMetricAnomalyRuleType(): AlertTypeModel<MetricAnomalyRuleTypeParams> { | ||
return { | ||
id: METRIC_ANOMALY_ALERT_TYPE_ID, | ||
description: i18n.translate('xpack.infra.metrics.anomaly.alertFlyout.alertDescription', { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,14 @@ import { AlertStates } from './types'; | |
import { | ||
ActionGroupIdsOf, | ||
ActionGroup, | ||
AlertInstanceContext, | ||
AlertInstanceState, | ||
AlertInstanceContext as AlertContext, | ||
AlertInstanceState as AlertState, | ||
RecoveredActionGroup, | ||
} from '../../../../../alerting/common'; | ||
import { AlertInstance, AlertTypeState } from '../../../../../alerting/server'; | ||
import { | ||
AlertInstance as Alert, | ||
AlertTypeState as RuleTypeState, | ||
} from '../../../../../alerting/server'; | ||
import { SnapshotMetricType } from '../../../../common/inventory_models/types'; | ||
import { InfraBackendLibs } from '../../infra_types'; | ||
import { METRIC_FORMATTERS } from '../../../../common/formatters/snapshot_metric_formats'; | ||
|
@@ -39,34 +42,34 @@ type InventoryMetricThresholdAllowedActionGroups = ActionGroupIdsOf< | |
typeof FIRED_ACTIONS | typeof WARNING_ACTIONS | ||
>; | ||
|
||
export type InventoryMetricThresholdAlertTypeState = AlertTypeState; // no specific state used | ||
export type InventoryMetricThresholdAlertInstanceState = AlertInstanceState; // no specific state used | ||
export type InventoryMetricThresholdAlertInstanceContext = AlertInstanceContext; // no specific instance context used | ||
export type InventoryMetricThresholdRuleState = RuleTypeState; // no specific state used | ||
ersin-erdal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export type InventoryMetricThresholdAlertState = AlertState; // no specific state used | ||
export type InventoryMetricThresholdAlertContext = AlertContext; // no specific instance context used | ||
|
||
type InventoryMetricThresholdAlertInstance = AlertInstance< | ||
InventoryMetricThresholdAlertInstanceState, | ||
InventoryMetricThresholdAlertInstanceContext, | ||
type InventoryMetricThresholdAlert = Alert< | ||
InventoryMetricThresholdAlertState, | ||
InventoryMetricThresholdAlertContext, | ||
InventoryMetricThresholdAllowedActionGroups | ||
>; | ||
type InventoryMetricThresholdAlertInstanceFactory = ( | ||
type InventoryMetricThresholdAlertFactory = ( | ||
id: string, | ||
reason: string, | ||
threshold?: number | undefined, | ||
value?: number | undefined | ||
) => InventoryMetricThresholdAlertInstance; | ||
) => InventoryMetricThresholdAlert; | ||
|
||
export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) => | ||
libs.metricsRules.createLifecycleRuleExecutor< | ||
InventoryMetricThresholdParams & Record<string, unknown>, | ||
InventoryMetricThresholdAlertTypeState, | ||
InventoryMetricThresholdAlertInstanceState, | ||
InventoryMetricThresholdAlertInstanceContext, | ||
InventoryMetricThresholdRuleState, | ||
ersin-erdal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
InventoryMetricThresholdAlertState, | ||
InventoryMetricThresholdAlertContext, | ||
InventoryMetricThresholdAllowedActionGroups | ||
>(async ({ services, params }) => { | ||
const { criteria, filterQuery, sourceId, nodeType, alertOnNoData } = params; | ||
if (criteria.length === 0) throw new Error('Cannot execute an alert with 0 conditions'); | ||
const { alertWithLifecycle, savedObjectsClient } = services; | ||
const alertInstanceFactory: InventoryMetricThresholdAlertInstanceFactory = (id, reason) => | ||
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. The task_runner of the alerting framework exposes an alertInstanceFactory method https://github.com/elastic/kibana/blob/main/x-pack/plugins/alerting/server/task_runner/task_runner.ts#L321 This |
||
const alertFactory: InventoryMetricThresholdAlertFactory = (id, reason) => | ||
alertWithLifecycle({ | ||
id, | ||
fields: { | ||
|
@@ -82,8 +85,8 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) = | |
} catch (e) { | ||
const actionGroupId = FIRED_ACTIONS.id; // Change this to an Error action group when able | ||
const reason = buildInvalidQueryAlertReason(params.filterQueryText); | ||
const alertInstance = alertInstanceFactory('*', reason); | ||
alertInstance.scheduleActions(actionGroupId, { | ||
const alert = alertFactory('*', reason); | ||
alert.scheduleActions(actionGroupId, { | ||
group: '*', | ||
alertState: stateToAlertMessage[AlertStates.ERROR], | ||
reason, | ||
|
@@ -191,8 +194,8 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) = | |
? WARNING_ACTIONS.id | ||
: FIRED_ACTIONS.id; | ||
|
||
const alertInstance = alertInstanceFactory(`${group}`, reason); | ||
alertInstance.scheduleActions( | ||
const alert = alertFactory(`${group}`, reason); | ||
alert.scheduleActions( | ||
/** | ||
* TODO: We're lying to the compiler here as explicitly calling `scheduleActions` on | ||
* the RecoveredActionGroup isn't allowed | ||
|
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.
And this is just until things change on the alerting side?
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.
Ys exactly. We also talked with them, they will use these names too, so we (or they) can just remove " .... as" part once they did the refactoring on their side.