Repository navigation
Conversation
…014) Validate Alerting v2 rule templates under kibana/alerting_rule_template/ (metadata, schedule, query parts, lifecycle strategy, grouping, artifacts, and state-transition values). Classic templates (engine v1 or none) are skipped and continue to use the package specification schema. Companion to elastic/elastic-package#4054, which removes the equivalent local validator from elastic-package in favor of this central check.
5544693 to
50ec175
Compare
- Read attributes.engine first so classic templates with engine null, a non-string engine, or non-string id/type are skipped instead of reported under SVR00014. Only an explicit "v2" engine is structurally validated. - Correct the header comment and docs/validations.md: package-spec has no structural schema for alerting_rule_template files, so classic templates are not content-validated (they are not covered by a schema).
teresaromero
left a comment
There was a problem hiding this comment.
Thanks!!. Details are in the inline comments; the main points:
- Rollout: the rule has no
since/warnOn, so it is a hard error for everyformat_version, including published packages, on a patch release. Is that intended? Could we gate it or start as a warning? Once CI is green, please commenttest integrationsto see the effect on real packages. - SVR00014 is also used by #1250; whichever merges second needs to renumber.
- Tests: add a good and a consolidated bad v2 fixture package, registered in
Test_ValidateFromPath. - Code: report
ReadFileerrors separately from validation errors, and replacetemplateProblemswith helpers returningerrorcombined viaerrors.Join, with parsing and the engine skip in their own helper. - Kibana reference: please link Kibana's
alerting-v2-schemaswith permalinks, and confirm whether accepting unknown fields is intended, since Kibana's schema is.strict(). - Smaller: unknown
enginehandling and docs, plus a few nits.
I only compared the limits with Kibana's v2 schema, not every rule.
We can trigger a test integrations comment so we see the impact of this changes on the current integrations.
A truncated template was reported as SVR00014 on top of the Kibana object-id parse errors. Any engine string other than "", "v1", or "v2" is rejected, and the docs now say so.
A non-object artifacts element and a non-string grouping field now say what is wrong instead of "must be an array". The header and validations.md link Kibana's alerting-v2-schemas and state that the check is intentionally looser than Kibana's strict schema.
# Conflicts: # docs/validations.md
…pes. A v2 template whose id or type is not a string now gets a normal SVR00014 finding instead of a Go decoding error. metadata.routing_tags and metadata.builder are checked against Kibana's limits, and signal rules may not set routing_tags. The duration pattern now says it follows Kibana's syntax rather than time.ParseDuration. The docs and header no longer say Kibana rejects invalid templates on install; Fleet does not validate the rule body, Kibana only does when a rule is created from the template.
good_alert_rule_templates_v2 holds a valid alert template, a valid signal template, and a classic engine v1 template, and is part of Test_ValidateFromPath. bad_alert_rule_templates_v2 holds one invalid template per failure on format_version 3.4.0, checked in every validation mode and from a zip. This replaces the test that copied good_alert_rule_templates to a temp dir and rewrote it.
|
test integrations |
|
Created or updated PR in integrations repository to test this version. Check elastic/integrations#22140 |
Kibana checks metadata.name, time_field, tags, grouping fields, the template id, and artifact id/type with min(1) and no trim, so a whitespace value is valid there and must not fail SVR00014. Check recovery.segment and recovery.query against the 10000-character ES|QL limit, durations against MAX_DURATION_LENGTH (32), and artifacts against Kibana's id, type, data key, data field count, and serialized data limits. Report every invalid artifact instead of stopping at the first, and decode the template once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rule was an error on every format version, so a published package with an invalid v2 template would start failing as soon as it picked up this package-spec. Follow the warnOn/until split used for other new rules, and move bad_alert_rule_templates_v2 to 3.8.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
test integrations |
|
Created or updated PR in integrations repository to test this version. Check elastic/integrations#22140 |
@shmsr it looks like that there are conflicts in this integrations PR, and it could not be validated the changes in that CI pipeline. The easiest way to solve this, is to close that PR and delete the branch, and then post again here the |
|
test integrations |
|
Created or updated PR in integrations repository to test this version. Check elastic/integrations#22217 |
teresaromero
left a comment
There was a problem hiding this comment.
Thanks for this work, i think this looks good from the ecosystem perspective! 🚀
integration is still running but by this point i think this is fully compatible.
|
Tick the box to add this pull request to the merge queue (same as
|
| {fn: warnOn(semantic.ValidateAlertRuleTemplates), types: []string{"integration", "content"}, until: semver.MustParse("3.8.0")}, | ||
| {fn: semantic.ValidateAlertRuleTemplates, types: []string{"integration", "content"}, since: semver.MustParse("3.8.0")}, |
There was a problem hiding this comment.
I'd set spec 3.7.0 , because 9.6.0-SNAPSHOT is the kibana supporting spec 3.7.
Moreover, I would remove the warning before 3.7 and make and error because as we found in the elastic-package PR those package cannot be installed in < 9.6 kibana versions.
| {fn: warnOn(semantic.ValidateAlertRuleTemplates), types: []string{"integration", "content"}, until: semver.MustParse("3.8.0")}, | |
| {fn: semantic.ValidateAlertRuleTemplates, types: []string{"integration", "content"}, since: semver.MustParse("3.8.0")}, | |
| {fn: semantic.ValidateAlertRuleTemplates, types: []string{"integration", "content"}, since: semver.MustParse("3.7.0")}, |
There was a problem hiding this comment.
Done in 081d451 and 2812f13. SVR00014 is now an error from format_version 3.7.0, with no warning period, and the changelog entry is under 3.7.1-next.
I also added a second rule for packages below 3.7.0. Any engine: v2 template, or any engine other than "" or v1, is an error there. It has no code, so validation.yml can't hide it. Without it, a 3.6.0 package could still ship a v2 template, and the registry would offer it to Kibana 9.4 and 9.5, which fail to install it:
flowchart LR
P36["format_version 3.6.0<br/>with a v2 template"] --> REG[Package registry]
P37["format_version 3.7.0<br/>with a v2 template"] --> REG
REG -->|"spec.max 3.6: offers only 3.6.0"| K95["Kibana 9.4 / 9.5"]
REG -->|"spec.max 3.7: offers both"| K96["Kibana 9.6+"]
K95 --> FAIL["Install fails:<br/>attributes.name expected string"]
K96 --> OK[Installs]
Both v2 test packages now use format_version: 3.7.0 and kibana.version: ^9.6.0. I've also updated the PR description, which still described the rule as ungated.
After discussing offline with Mario i think we need still some changes. I was not aware of the compatbility issue between versions. Check his comments pls
Kibana before 9.6.0 fails to install engine v2 templates, and 9.6.0 is the first Kibana that supports format_version 3.7.0. SVR00014 is now an error from 3.7.0, and an uncoded error rejects v2 templates in older packages so validation.yml cannot hide it. Blank checks now use JavaScript's trim() whitespace, and artifact data size now matches JSON.stringify(data).length exactly. The changelog entry moves to 3.7.1-next and both v2 fixtures target 3.7.0 and Kibana ^9.6.0.
|
test integrations |
|
Created or updated PR in integrations repository to test this version. Check elastic/integrations#22217 |
|
The It got five So I was wrong earlier when I said no published package ships v2 templates. That was true when I wrote it, but not anymore. The earlier run only passed because The templates themselves look good. I tried the package locally with this branch: it fails at 3.6.2, and at 3.7.0 it builds and passes I'd keep the rule as it is. This is the case @mrodm brought up, and the package already requires Kibana @teresaromero @mrodm what do you think? or would you rather wait to release until the package is updated? |
mrodm
left a comment
There was a problem hiding this comment.
LGTM the changes to use spec 3.7.0 for alert rule template v2. Thanks for these changes.
In this last review, just wondering about some errors that could be skipped and I'm not sure if they should be part of those. Could you check it ?
I'd keep the rule as it is. This is the case @mrodm brought up, and the package already requires Kibana ^9.6.0, so moving it to 3.7.0 doesn't change who can install it. The published 0.4.0 can stay as it is. The next version just needs format_version: "3.7.0", and that already works with the elastic-package integrations uses today. It has to land before integrations picks up a package-spec release with this rule; so I can take this up? Does that sound ok?
@teresaromero @mrodm what do you think? or would you rather wait to release until the package is updated?
Until the next elastic-package release containing this package-spec changes (in the next package-spec release), this gcp_cloudrun_otel package could not be updated to use format_version: 3.7.0. I think that package and if any other package (but I hope no other packages 😅 🤞 ) should be updated once elastic-package version is updated in the integrations repository. Until that, CI would fail when the package tries to update the format_version with an error of invalid spec or similar.
Separate engine parsing from Alerting v2 structural validation and remove the redundant document decode. Preserve classic template skips and add regression coverage for exclusions and malformed JSON across validation modes and zip packages.
💚 Build Succeeded
History
cc @shmsr |
teresaromero
left a comment
There was a problem hiding this comment.
🚀 thanks for the latest changes!!
What does this PR do?
Adds a semantic rule,
SVR00014, that checks the structure of Alerting v2 ruletemplates in
kibana/alerting_rule_template/. A template is Alerting v2 when it sets"engine": "v2".For v2 templates, the rule checks:
rule.kind,rule.metadata(name,description,tags,routing_tags,builder),rule.schedule,rule.time_field, andrule.query(baseandbreach.segment), withKibana's length and count limits.
recoveryandno_data. Signal rules must notset
recovery,no_data,state_transition, ormetadata.routing_tags.state_transitioncounts and timeframes,grouping.fields(1 to 16), andartifacts(1 to 100).
Blank checks use JavaScript's
trim()whitespace, string lengths count UTF-16 code units,and artifact
datasize isJSON.stringify(data).length.Which templates are checked:
engineis missing,null, not a string,"", orv1. Existing Kibana object checks, including ID andreference checks, still apply.
enginevalues, such asV2orv3, produce errors without a codeon every
format_version, so they cannot be excluded invalidation.yml.already report it.
What the rule does not check:
later Kibana does not fail an older package-spec.
The checks follow Kibana's
alerting-v2-schemas.Which format versions
flowchart TD F["kibana/alerting_rule_template/*.json"] --> J{"Valid JSON?"} J -->|no| P["Existing Kibana object checks report the error<br/>cannot be excluded"] J -->|yes| E{"attributes.engine"} E -->|"missing, null, non-string, empty, v1"| C["Skipped by the v2 validator<br/>existing Kibana object checks still apply"] E -->|"unsupported string, such as V2 or v3"| U["Unsupported engine<br/>error without a code on every format_version<br/>cannot be excluded"] E -->|v2| V{"format_version >= 3.7.0?"} V -->|no| M["Requires format_version 3.7.0 or later<br/>error without a code<br/>cannot be excluded"] V -->|yes| S["SVR00014: v2 structural validation<br/>can be excluded in validation.yml"]The checks run for
integrationandcontentpackages in every validation mode.Only v2 structural errors from
format_version3.7.0 or later receiveSVR00014andcan be excluded in
validation.yml. Unsupported-engine errors have no code on anyformat version. V2 templates below 3.7.0 also produce errors without a code. Neither
can be excluded. Malformed JSON is reported by the existing Kibana object checks
with errors that cannot be excluded.
Kibana 9.6.0 is the first version that installs v2 templates and the first that supports
format_version3.7.0. The registry only offers a package to a Kibana that supports itsformat_version, so tying v2 templates to 3.7.0 keeps them away from Kibana 9.4 and 9.5.Those versions fail the install with
[attributes.name]: expected value of type [string] but got [undefined]:Why is it important?
Kibana does not validate the rule body of a v2 template when Fleet installs a package. It
only validates it when a user creates a rule from the template. Without this check, a broken
template ships and installs cleanly, and the first person to see the error is the user.
Companion to elastic/elastic-package#4054,
which removes the equivalent local validator from
elastic-packagein favor of thiscentral check.
Validation
go test -count=1 ./code/go/...andmake checkpassed.SVR00014removes v2 structural errors butkeeps unsupported-engine and malformed-JSON errors. These cover legacy, source,
and build modes, plus zip packages.
be excluded either.
Checklist
test/packagesthat prove my change is effective.good_alert_rule_templates_v2(valid alert, signal, and classic templates) andbad_alert_rule_templates_v2(one invalid template per failure), both atformat_version: 3.7.0. A validator test setsgood_alert_rule_templates_v2to 3.6.0 and expects one error per v2 template.spec/changelog.yml, under3.7.1-next.Related issues