Make the alerts plugin support generics#72716
Conversation
| type: `alerting:${alertType.id}`, | ||
| createTaskRunner: (context: RunContext) => | ||
| this.taskRunnerFactory.create(alertType, context), | ||
| this.taskRunnerFactory.create({ ...alertType } as AlertType, context), |
There was a problem hiding this comment.
{ ...alertType } is a "while I'm here" for shallow clones that was missed in #65309.
|
Pinging @elastic/kibana-alerting-services (Team:Alerting Services) |
chrisronline
left a comment
There was a problem hiding this comment.
LGTM for stack monitoring
|
@elasticmachine merge upstream |
| import { State, Context } from '../types'; | ||
| import { parseDuration } from '../lib'; | ||
|
|
||
| interface ScheduledExecutionOptions { |
There was a problem hiding this comment.
+1 on an interface removal - that's neat!
There was a problem hiding this comment.
For sure, for this one here I had to move it within the AlertInstance class in order to use the generics passed to the class.
| return result; | ||
| } | ||
|
|
||
| function getPatternFiringAlertType() { |
There was a problem hiding this comment.
eh, we'll have a merge conflict here with https://github.com/elastic/kibana/pull/68437/files#diff-753fd9a204535630ddf989cebd2a4a76 - I had to make the patternFiring alert a little more interesting, to handle multiple instances.
There was a problem hiding this comment.
Ah thanks for the heads up! If your PR merges soon, I'll wait until then as the changes I made aren't hard to redo.
gmmorris
left a comment
There was a problem hiding this comment.
LGTM 👍
Great work Mike!
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export type AlertTypeState = Record<string, any>; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export type AlertTypeParams = Record<string, any>; | ||
|
|
There was a problem hiding this comment.
Can't this be a generic type with a default of unknown instead of any?
There was a problem hiding this comment.
Converting these types to Record<string, unknown> caused over 130 type check failures. Most of these were outside of the alerting team's code and would cause us to change a lot of external code. I'm thinking we enforce this at some other time and have created #74897 to track this.
…ana into alerting/implement-generics
shahzad31
left a comment
There was a problem hiding this comment.
Uptime changes LGTM !!
|
Pinging @elastic/uptime (Team:uptime) |
💚 Build SucceededBuild metricspage load bundle size
History
To update your PR or re-run it, just comment with: |
* Initial work * Expand generic support to alert instances * Convert index threshold to use generics * Make fixture alert types use generics * Make alert instance related types use unknown * Fix typecheck failures * Cleanup + add instance generic support to registry.get API * Shallow clone * Rename some TS variables * Fix failing api integration tests * Change code for easier review and keep more history * Fix Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
* master: (24 commits) [ML] Functional tests - skip regression and classification tests [Ingest Manager] fix removing ingest pipelines from elasticsearch (elastic#75092) move tests for placeholder indices to setup (elastic#75096) [jest] temporarily extend default test timeout (elastic#75118) [cli] remove reference to removed --optimize flag (elastic#75083) skip flaky suite (elastic#75044) Adding /etc/rc.d/init.d/functions to the init script when present to … (elastic#22985) [jenkins] add pipeline for hourly security solution cypress tests (elastic#75087) [Reporting/Flaky Test] Skip test for paging list of reports (elastic#75075) remove .kbn-optimizer-cache upload (elastic#75086) skip flaky suite (elastic#74814) Actions add proxy support (elastic#74289) [ILM] TS conversion of Edit policy components (elastic#74747) [Resolver] simulator tests select elements directly instead of using descendant selectors. (elastic#75058) [Enterprise Search] Add Workplace Search side navigation (elastic#74894) [Security solution] Sourcerer: Kibana index pattern selector for security views (elastic#74706) [Logs UI] Remove apollo deps from log link-to routes (elastic#74502) [Maps] add map configurations to docker list (elastic#75035) [functional test][saved objects] update tests for additional copy saved objects to space (elastic#74907) Make the alerts plugin support generics (elastic#72716) ...
* Initial work * Expand generic support to alert instances * Convert index threshold to use generics * Make fixture alert types use generics * Make alert instance related types use unknown * Fix typecheck failures * Cleanup + add instance generic support to registry.get API * Shallow clone * Rename some TS variables * Fix failing api integration tests * Change code for easier review and keep more history * Fix Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Solves the alerts portion of #64147.
Resolves #64147 now that all portions are complete after this PR.
In this PR, I'm adding support for generics in the alerts plugin to the following types:
AlertServices<InstanceState, InstanceContext>AlertExecutorOptions<Params, State, InstanceState, InstanceContext>AlertType<Params, State, InstanceState, InstanceContext>Example