Skip to content
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

[Response Ops][Alerting] Install framework alerts-as-data resources on startup #145100

Closed
ymao1 opened this issue Nov 14, 2022 · 6 comments · Fixed by #145581
Closed

[Response Ops][Alerting] Install framework alerts-as-data resources on startup #145100

ymao1 opened this issue Nov 14, 2022 · 6 comments · Fixed by #145581
Assignees
Labels
Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@ymao1
Copy link
Contributor

ymao1 commented Nov 14, 2022

As part of Phase 2 of framework alerts-as-data, we need to install alerts as data index resources on startup. Using the best practices outlined here, we should install an ILM policy, component template, index template and concrete write index. The FAAD schema should be a superset of all ECS field and the initial default set of framework fields.

Implementation details to iron out as part of this issue:

  • Are we allowing only additive or additive and non-additive changes to the FAAD mappings between versions?
  • Because we are allowing all ECS fields to be part of FAAD, should we use a script to auto-generate the ECS mappings based on the latest version of ECS, similar to what the event log generator currently does.
  • Because we anticipate solutions adding fields to the schema, we should ensure the process for adding a field is well documented and triggers a CODEOWNERS review from Response Ops.

POC for possible implementation here. This issue would cover the AlertsService portion of the POC but does not contain any of the best practices linked in the above issue.

@botelastic botelastic bot added the needs-team Issues missing a team label label Nov 14, 2022
@ymao1 ymao1 added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework labels Nov 14, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@ymao1
Copy link
Contributor Author

ymao1 commented Nov 14, 2022

This issue can be started but complete implementation is blocked on final approval of the standard FAAD schema (TTL Nov 18).

@ymao1 ymao1 self-assigned this Nov 14, 2022
@ymao1
Copy link
Contributor Author

ymao1 commented Dec 21, 2022

With the recent change in direction for alerts-as-data, we will want to install multiple indices on startup, one for each existing rule registry registration context and a new one for stack rules. Each registration context will be able to register custom index mappings on top of the default framework mappings and a concrete write index will be created for the default space. I will create a followup issue for space-specific indices.

Current registration contexts:
observability.apm
observability.slo
observability.logs
observability.metrics
observability.uptime
security

@sophiec20
Copy link
Contributor

Have we discussed if O11y can consolidate? This granular rule registry grouping is legacy as far as I understand it.

@ymao1
Copy link
Contributor Author

ymao1 commented Dec 22, 2022

Yes, combining registration contexts was discussed and since we are pivoting to having solutions manage their own mappings again, they wanted to keep the separation that registration contexts provide

@lucabelluccini
Copy link
Contributor

Please let's ensure the existing indices or data streams are not modified and everything is handled purely by index templates to avoid situations like #139969.

ymao1 added a commit that referenced this issue Jan 24, 2023
…s-as-data (#145581)

Resolves #145100

## Summary

* Adds alerting config for `enableFrameworkAlerts`
* When `xpack.alerting.enableFrameworkAlerts=true`, `AlertsService` is
initialized during the alerting plugin setup phase
* Adds optional `alerts` definition to the `RuleType` definition which
allows a rule type to specify a context and a field mapping for that
context
* `AlertsService.initialize()` 
* installs an ILM policy that will be used by all alerts-as-data indices
- `alerts-default-ilm-policy`
* installs a component template that will be used by all alerts-as-data
indices - `alerts-common-component-template`, including all the mappings
for fields needed by the framework
* Rule type registration - when a rule type with an `alerts` definition
is registered, the context and field map are registered with the
`AlertService`. When `AlertsService` initialization is completed
successfully, context specific resources are installed.
* Context specific resources:
* installs context specific component template that reflects the
registered field map - `alerts-${context}-component-template`
* installs context specific index template for the default namespace -
`.alerts-${context}-default-template`
* creates context specific concrete write index for the default
namespace - `.alerts-${context}-default-000001`
* Resource installation retries for transient ES errors and
short-circuits when a timeout value is reached

## Notes
* We explore the possibility of creating a single index template per
context and re-using it for space-aware concrete indices but a rollover
alias (which must be space-aware) must be attached to an index template
so it is not feasible to only have a single index template
* There will be a followup issue for create space-specific index
templates/indices as needed to support detection rules desire to
separate alerts by space.

## To Verify

* set `xpack.alerting.enableFrameworkAlerts: true` in your kibana.yml
* modify
`x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type.ts` to
define a custom field mapping for the `stack` context

```
--- a/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type.ts
+++ b/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type.ts
@@ -187,5 +187,14 @@ export function getRuleType(
     },
     producer: STACK_ALERTS_FEATURE_ID,
     doesSetRecoveryContext: true,
+    alerts: {
+      context: 'stack',
+      fieldMap: {
+        'kibana.alert.threshold': {
+          required: false,
+          type: 'long',
+        },
+      },
+    },
   };
 }

```
* start up ES and Kibana and verify that the correct resources are
installed. The following should be created:
  * ILM policy - `alerts-default-ilm-policy`
  * Common component template - `alerts-common-component-template`
  * Stack component template - `alerts-stack-component-template`
* Stack index template for default space -
`.alerts-stack-default-template`
  * Stack write index for default space - `.alerts-stack-default-000001`
* verify that the index template uses both component templates and that
the expected mappings are applied to the index
* try making non-destructive, additive only changes to the common
component template or the stack context field mapping and verify that
the concrete index mappings are updated.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants