Introduce ddwaf_(context|subcontext)_multieval to evaluate multiple batches in sequence#494
Introduce ddwaf_(context|subcontext)_multieval to evaluate multiple batches in sequence#494Anilm3 wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #494 +/- ##
==========================================
+ Coverage 84.71% 84.76% +0.04%
==========================================
Files 190 190
Lines 9670 9332 -338
Branches 4186 4196 +10
==========================================
- Hits 8192 7910 -282
+ Misses 577 532 -45
+ Partials 901 890 -11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Dynamic Artifact Size Comparison 📦
Static Artifact Size Comparison 📦
|
df4a13d to
47ed904
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47ed904d18
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…atches in sequence
christophe-papazian
left a comment
There was a problem hiding this comment.
The serializer now always writes evaluated into the result object, but schema/result.json still has additionalProperties: false and doesn't list it. Worth updating the schema, or will this silently break consumers doing strict validation?
Overview
This PR adds two new public entrypoints,
ddwaf_context_multievalandddwaf_subcontext_multieval, that evaluate multiple input batches in sequence within a single call and return one combined result. Functionally each entrypoint behaves like its_evalcounterpart, except thatdatais an array of maps where every element is treated as a separate input batch and evaluated in order.To support this, insertions to the object store now result in the batch being added to a queue, which then has to be explicitly applied before it's ready to be evaluated:
insert_batch/insert_batchesenqueue input (a single map, or an array of maps) without applying it.next_batchpops and applies the next queued batch, marking its targets as new.flush_input_queuedrains any batches left unevaluated (e.g. after a timeout) on every exit path, applying them as "existing" targets targets so they carry over to subsequent calls and resets the new-target set for the next evaluation.The evaluation engine now loops over batches, running pre-processors, filters, rules, and post-processors per batch, accumulating events/actions/attributes into the single result.
A new field has been added to the result object:
evaluated: an unsigned integer reporting how many batches were fully evaluated. In the normal case this equals the number of non-empty batches; on timeout/error during batchi(0-based, counting non-empty batches) it equalsI, i.e. the index of the batch where the problem occurred. Empty batches are skipped and don't count.This field is present on the regular
_evalresults too (the result schema is shared), where it's simply1for a non-empty evaluated batch or0otherwise.Files to review (
src/)src/object_store.hpp/src/object_store.cpp: core change: the batch queue,insert_batch/insert_batches/insert_target/next_batch/flush_input_queue/enqueue_batch/apply_batch, and theinsert_and_applytest helper. Worth the closest look for the queue lifetime and new-target semantics.src/evaluation_engine.cpp: the per-batch evaluation loop,flush_input_queueon exit, and theevaluatedcounter.src/evaluation_engine.hpp:insert_batch/insert_batchesforwarding and thenext_batch/insert_and_applytest internals.src/interface.cpp: the two new public functions plus the array-vs-map dispatch added toddwaf_context_eval/ddwaf_subcontext_eval.src/context.hpp:context/subcontextforwarding for the new store methods and test internals.src/serializer.hpp/src/serializer.cpp: theevaluatedfield added toresult_componentsandinitialise_result_object.src/processor/base.hpp: processor output switched frominserttoinsert_target.