Fix: Add comprehensive unit tests for non-ecs-schema.json and clean up data (#2322)#5879
Open
chidoziemanagwu wants to merge 1 commit intoelastic:mainfrom
Open
Fix: Add comprehensive unit tests for non-ecs-schema.json and clean up data (#2322)#5879chidoziemanagwu wants to merge 1 commit intoelastic:mainfrom
chidoziemanagwu wants to merge 1 commit intoelastic:mainfrom
Conversation
|
💚 CLA has been signed |
6ee545d to
d7fc99f
Compare
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 #2322
Summary - What I changed
This PR resolves Issue #2322 by constructing a robust constraint unit-test specifically for the
non-ecs-schema.jsonmapping dictionary. Historically, this file lacked isolated structure validation—leaving the main rule engine vulnerable to schema bugs. Any contributor could accidentally introduce duplicate fields, assign mismatched datatypes across indices, or define fields that actually belong in canonical ECS, causing potential cross-index mapping explosions.To prevent this permanently, I built a new 6-part unit test suite in
tests/test_non_ecs_schema.py.⚡️ Key Test Snippet - Finding canonical ECS overlaps:
🔧 Data Integrity Cleanup:
While building these tests, the suite correctly identified 8 fields inside
non-ecs-schema.jsonthat had secretly been added upstream to the canonical ECS system in recent versions (likehttp.request.methodandfile.size). Instead of ignoring these test failures, I directly purged these overlapping variables to clear up technical debt, ensuring the new suite passes 100%.⚡️ Schema Fix Example (
detection_rules/etc/non-ecs-schema.json):"logs-network_traffic.http*": { - "data_stream.dataset": "keyword", - "url.path": "keyword", - "http.request.referrer": "keyword", "http.request.headers.content-type": "keyword", - "network.direction": "keyword", - "http.request.method": "keyword", "request": "keyword", - "http.request.body.bytes": "long", - "http.request.body.content": "keyword", "http.response.headers.server": "keyword" },How To Test
You can manually verify the infrastructure changes locally using the built-in testing commands.
1. Run the targeted new test suite:
Output Details:
2. Verify 0 regressions against the entire repository:
Because we removed fields from
non-ecs-schema.json, test the entire platform to ensure zero rule regressions:python -m detection_rules testChecklist
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