-
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
[ResponseOps] move alert UUID generation from rule registry to the alerting framework #143489
Changes from all commits
08868bd
20577b3
7fa690b
87cfa3b
20d8462
df9ecbb
6a51e52
6332280
1fb883c
d2e95d9
98de392
df620f4
b9cf89d
39639f3
a1a40dd
16e92b3
9eeed3c
65c9b90
4071334
3abea57
d271351
c835e90
fb0a00f
229a06b
433f0fe
841993a
63bb133
8974bca
bf4f2de
62cdfe9
ff1e99f
f9227f9
8fdecdf
bbbeb55
d28e83c
ad4535f
1ba4666
961651c
68a79b4
9c9ca7c
b6bd1b3
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# @kbn/alerting-state-types | ||
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. This package was added so that we can use the same types used in alerting and rule_registry, for rule task state, within task manager, for migration reasons. Alerting and rule_registry now import this package to get those types, and also task_manager. No changes were made to the types. The files are not arranged in a super-logical fashion - I left them pretty much in the same files as where they originally came from, to make it easier to diff. |
||
|
||
Contains type information for the alerting data persisted in task | ||
manager documents as state. | ||
|
||
Because task manager migrations sometimes need this data, it needs | ||
to be in a package outside of alerting. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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 type { | ||
ThrottledActions, | ||
LastScheduledActions, | ||
AlertInstanceMeta, | ||
AlertInstanceState, | ||
AlertInstanceContext, | ||
RawAlertInstance, | ||
} from './src/alert_instance'; | ||
export { rawAlertInstance } from './src/alert_instance'; | ||
|
||
export { DateFromString } from './src/date_from_string'; | ||
|
||
export type { TrackedLifecycleAlertState, WrappedLifecycleRuleState } from './src/lifecycle_state'; | ||
export { wrappedStateRt } from './src/lifecycle_state'; | ||
|
||
export type { RuleTaskState, RuleTaskParams } from './src/rule_task_instance'; | ||
export { ActionsCompletion, ruleStateSchema, ruleParamsSchema } from './src/rule_task_instance'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_node', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/x-pack/packages/kbn-alerting-state-types'], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/alerting-state-types", | ||
"owner": "@elastic/response-ops" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@kbn/alerting-state-types", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "Elastic License 2.0" | ||
} |
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 | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import * as t from 'io-ts'; | ||
|
||
const trackedAlertStateRt = t.type({ | ||
alertId: t.string, | ||
alertUuid: t.string, | ||
started: t.string, | ||
// an array used to track changes in alert state, the order is based on the rule executions | ||
// true - alert has changed from active/recovered | ||
// false - alert is new or the status has remained either active or recovered | ||
flappingHistory: t.array(t.boolean), | ||
// flapping flag that indicates whether the alert is flapping | ||
flapping: t.boolean, | ||
pendingRecoveredCount: t.number, | ||
}); | ||
|
||
export type TrackedLifecycleAlertState = t.TypeOf<typeof trackedAlertStateRt>; | ||
|
||
type RuleTypeState = Record<string, unknown>; | ||
|
||
export const alertTypeStateRt = <State extends RuleTypeState>() => | ||
t.record(t.string, t.unknown) as t.Type<State, State, unknown>; | ||
|
||
export const wrappedStateRt = <State extends RuleTypeState>() => | ||
t.type({ | ||
wrapped: alertTypeStateRt<State>(), | ||
// tracks the active alerts | ||
trackedAlerts: t.record(t.string, trackedAlertStateRt), | ||
// tracks the recovered alerts | ||
trackedAlertsRecovered: t.record(t.string, trackedAlertStateRt), | ||
}); | ||
|
||
/** | ||
* This is redefined instead of derived from above `wrappedStateRt` because | ||
* there's no easy way to instantiate generic values such as the runtime type | ||
* factory function. | ||
*/ | ||
export type WrappedLifecycleRuleState<State extends RuleTypeState> = RuleTypeState & { | ||
wrapped: State; | ||
trackedAlerts: Record<string, TrackedLifecycleAlertState>; | ||
trackedAlertsRecovered: Record<string, TrackedLifecycleAlertState>; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target/types", | ||
"types": [ | ||
"jest", | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [] | ||
} |
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 is a new package added in this PR, to hold alerting types used by task manager. More below.