Skip to content

Commit

Permalink
Detect rule param changes for rolling upgrades and rollback assessment (
Browse files Browse the repository at this point in the history
elastic#173936)

In this PR, I'm adding a test in the alerting framework to detect
changes in a rule type's params schema that will require a snapshot to
be updated. This snapshot will provide a centralized place to view
history on alerting rule params in case we need to asses risk for
rolling upgrades or rollbacks of a release (serverless). The only rule
types affected are those running in serverless in any of the three
project types.

When a rule type is used in serverless, it must provide one of the
following configuration to their rule type on top of everything else:

```
// Zod schema
schemas: {
  params: {
    type: 'zod',
    schema: UnifiedQueryRuleParams
  },
},

// config-schema
schemas: {
  params: {
    type: 'config-schema',
    schema: EsQueryRuleParamsSchema,
  },
},
```

We are working on documenting guidelines so engineers and response ops
can ensure a change to rule parameters will work properly in rolling
upgrade and rollback scenarios and be part of the PR review process.

NOTE to rule type owners: I pass the same schema used to validate to the
`schemas.params` attribute in the rule type. It will be important to
keep them in sync. Down the road, we plan to make `validate.params`
optional and use the schema as a starting point so it's easier to have a
single variable passed in.

## To verify
1. Make changes to the params schema of the ES query rule type.
```
diff --git a/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type_params.ts b/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type_params.ts
index 73e8eae32cf..09ec74104ec 100644
--- a/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type_params.ts
+++ b/x-pack/plugins/stack_alerts/server/rule_types/es_query/rule_type_params.ts
@@ -39,6 +39,7 @@ export type EsQueryRuleParamsExtractedParams = Omit<EsQueryRuleParams, 'searchCo
 };

 const EsQueryRuleParamsSchemaProperties = {
+  foo: schema.boolean(),
   size: schema.number({ min: 0, max: ES_QUERY_MAX_HITS_PER_EXECUTION }),
   timeWindowSize: schema.number({ min: 1 }),
   excludeHitsFromPreviousRun: schema.boolean({ defaultValue: true }),
```
2. Run the jest integration test to update the snapshot file
```
node scripts/jest_integration.js x-pack/plugins/alerting/server/integration_tests/serverless_upgrade_and_rollback_checks.test.ts -u
```
3. Notice the
`x-pack/plugins/alerting/server/integration_tests/__snapshots__/serverless_upgrade_and_rollback_checks.test.ts.snap`
file got updated
```
    "foo": Object {
      "flags": Object {
        "error": [Function],
      },
      "type": "boolean",
    },
```

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
2 people authored and fkanout committed Mar 4, 2024
1 parent d3e64d7 commit f293207
Show file tree
Hide file tree
Showing 27 changed files with 10,022 additions and 51 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,8 @@
"xml-crypto": "^5.0.0",
"xmlbuilder": "13.0.2",
"yargs": "^15.4.1",
"yarn-deduplicate": "^6.0.2"
"yarn-deduplicate": "^6.0.2",
"zod-to-json-schema": "^3.22.3"
},
"packageManager": "[email protected]"
}
Loading

0 comments on commit f293207

Please sign in to comment.