feat(provisioning): provision correlation rules from KEEP_CORRELATION_RULES - #6632
Open
aditya-786 wants to merge 1 commit into
Open
feat(provisioning): provision correlation rules from KEEP_CORRELATION_RULES#6632aditya-786 wants to merge 1 commit into
aditya-786 wants to merge 1 commit into
Conversation
…_RULES Correlation (rules-engine) rules were the only alerting resource the startup provisioner did not cover: providers, workflows, dashboards, deduplication rules, and mapping rules can all be declared in Helm values, but correlation rules could only be created via the UI, the SDK, or POST /rules. Add provision_correlation_rules_from_env, mirroring the deduplication provisioner. KEEP_CORRELATION_RULES holds a JSON array (or a path to a .json file) of rule specs in the POST /rules schema. On every startup the DB is reconciled to the env: upsert by ruleName, delete provisioned rules no longer present, and leave UI-created rules untouched, so rolling restarts stay idempotent. Each celQuery is compiled at provision time and invalid specs are skipped so one bad rule does not block the rest. Add an is_provisioned column to Rule (with migration) to track which rules the provisioner owns. Closes keephq#6563
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
The startup provisioner (
keep/api/config.py:provision_resources) configures providers, workflows, dashboards, deduplication rules, and mapping rules from Helm values, but correlation (rules-engine) rules were left out. Today the only ways to create one are the UI, the SDK, orPOST /rules, so a GitOps deployment cannot declare the alert grouping rule next to the workflow that uses the same CEL filter, and operators have toPOST /rulesafter every cluster bootstrap.This adds
provision_correlation_rules_from_env, giving correlation rules the same env-driven provisioning the other resources already have. Closes #6563.What changed
keep/api/bl/correlation_rules_provisioning.py(new):provision_correlation_rules_from_env(tenant_id), mirroringprovision_deduplication_rules_from_env.KEEP_CORRELATION_RULESholds a JSON array (or a path to a.jsonfile, dispatched by the same regex the dedup provisioner uses) of rule specs in thePOST /rulesschema (ruleName,celQuery,sqlQuery,timeframeInSeconds,timeUnit,groupingCriteria,createOn,resolveOn,incidentNameTemplate,incidentPrefix,threshold,requireApprove).ruleName, delete provisioned rules that are no longer present, and never touch UI-created rules (is_provisioned=False). Unsetting the env var deprovisions everything the provisioner owns. Rolling restarts are idempotent.celQueryis compiled at provision time; a spec that is missing a required field or has an unparseable CEL is logged and skipped, so one bad rule does not block the others.is_provisionedcolumn onRule+ Alembic migrationb3f1c9a24d70(on the current head67ff7efffed4), tracking which rules the provisioner owns. Mirrors the flag added toMappingRule.db.create_rulegains anis_provisioned=Falseparameter (same shapecreate_deduplication_rulealready has).provision_resources()calls the new function right afterprovision_mapping_rules_from_env.Example
values.yaml:Notes on scope
keephq/helm-chartsrepo, so exposing acorrelationRuleskey in the chart templates is a companion change there; this PR is the backend that reads the env var (same split as the existing dedup/mapping provisioning).matches()footgun the issue raises: the pinnedcel-pythonin this repo does evaluatename.matches('^Foo')(returns a bool), so that specific case does not reproduce here. Provision-time validation therefore compiles the CEL to catch genuine parse errors rather than attempting a trial evaluation, which would false-negative on any rule referencing fields absent from a synthetic payload.Checks
tests/test_correlation_rules_provisioning.py(11 tests, mirroring the mapping/dedup provisioning tests): create, multiple, idempotent, update-in-place, deprovision-on-removal, deprovision-on-unset, leave-UI-rules-untouched, skip-invalid-CEL, skip-missing-field, load-from-.json-file, and clean no-op. All pass locally; the rules-engine suite (tests/test_rules_engine.py) stays green.