[DaC] [Bug] Raw rule loading fails when deprecated and active rules share a name#6309
Open
eric-forte-elastic wants to merge 1 commit into
Conversation
5 tasks
Contributor
Bug - GuidelinesThese guidelines serve as a reminder set of considerations when addressing a bug in the code. Documentation and Context
Code Standards and Practices
Testing
Additional Checks
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes DaC --load-rule-loading failures caused by name collisions when an active rule and a deprecated stub share the same name, by splitting raw-loaded deprecated rules into a separate namespace (mirroring RuleCollection’s active/deprecated structure).
Changes:
- Added
RawDeprecatedCollectionand introducedRawRuleCollection.deprecatedto store raw deprecated rules separately. - Updated
RawRuleCollectionloading/add logic to route deprecated rules (bymetadata.maturity == "deprecated") into the deprecated collection, preventing name-map collisions. - Bumped package version to
1.6.54.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pyproject.toml | Bumps the project version for the bugfix release. |
| detection_rules/rule_loader.py | Splits raw rule loading into active vs deprecated collections to avoid rule-name collisions during DaC raw loading. |
Comment on lines
281
to
333
| @@ -288,10 +316,20 @@ def add_rule(self, rule: DictRule) -> None: | |||
| self.name_map[rule.name] = rule | |||
| self.rules.append(rule) | |||
|
|
|||
| def add_deprecated_rule(self, rule: DictRule) -> None: | |||
| """Add a deprecated rule to the collection.""" | |||
| self._assert_new(rule, is_deprecated=True) | |||
| self.deprecated.id_map[rule.id] = rule | |||
| self.deprecated.name_map[rule.name] = rule | |||
| self.deprecated.rules.append(rule) | |||
|
|
|||
| def load_dict(self, obj: dict[str, Any], path: Path | None = None) -> DictRule: | |||
| """Load a rule from a dictionary.""" | |||
| rule = DictRule(contents=obj, path=path) | |||
| self.add_rule(rule) | |||
| if self.is_deprecated_rule(rule): | |||
| self.add_deprecated_rule(rule) | |||
| else: | |||
| self.add_rule(rule) | |||
| return rule | |||
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.
Pull Request
Issue link(s):
Resolves #6308
Summary - What I changed
Fixes
--load-rule-loadingfailures when an active rule and a deprecated rule share the same name.RawRuleCollectionnow separates deprecated raw rules intocollection.deprecated, matching the active/deprecated split already used byRuleCollection. This preserves the intended DaC behavior of using active local rules for path preservation while allowing deprecated stubs to reuse names without colliding.RawRuleCollectionis only used in existing DaC commands. These logical paths are the ones impacted by this change.How To Test
Run the kibana export DaC command with the
--load-rule-loadingflag. The error would fire when building the local rule directory map keying off of rule names, so one does not need to have rules in the specified testing Kibana instance to see the error prior, or see the fix.The command should now not throw an error.
E.g.
Checklist
bug,enhancement,schema,maintenance,Rule: New,Rule: Deprecation,Rule: Tuning,Hunt: New, orHunt: Tuningso guidelines can be generatedmeta:rapid-mergelabel if planning to merge within 24 hoursContributor checklist