Skip to content

Introduce ddwaf_(context|subcontext)_multieval to evaluate multiple batches in sequence#494

Open
Anilm3 wants to merge 3 commits into
masterfrom
anilm3/multieval
Open

Introduce ddwaf_(context|subcontext)_multieval to evaluate multiple batches in sequence#494
Anilm3 wants to merge 3 commits into
masterfrom
anilm3/multieval

Conversation

@Anilm3

@Anilm3 Anilm3 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Overview

This PR adds two new public entrypoints, ddwaf_context_multieval and ddwaf_subcontext_multieval, that evaluate multiple input batches in sequence within a single call and return one combined result. Functionally each entrypoint behaves like its _eval counterpart, except that data is 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_batches enqueue input (a single map, or an array of maps) without applying it.
  • next_batch pops and applies the next queued batch, marking its targets as new.
  • flush_input_queue drains 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 batch i (0-based, counting non-empty batches) it equals I, 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 _eval results too (the result schema is shared), where it's simply 1 for a non-empty evaluated batch or 0 otherwise.

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 the insert_and_apply test helper. Worth the closest look for the queue lifetime and new-target semantics.
  • src/evaluation_engine.cpp: the per-batch evaluation loop, flush_input_queue on exit, and the evaluated counter.
  • src/evaluation_engine.hpp: insert_batch/insert_batches forwarding and the next_batch/insert_and_apply test internals.
  • src/interface.cpp: the two new public functions plus the array-vs-map dispatch added to ddwaf_context_eval / ddwaf_subcontext_eval.
  • src/context.hpp: context/subcontext forwarding for the new store methods and test internals.
  • src/serializer.hpp / src/serializer.cpp: the evaluated field added to result_components and initialise_result_object.
  • src/processor/base.hpp: processor output switched from insert to insert_target.

@Anilm3 Anilm3 requested a review from a team as a code owner June 9, 2026 19:02
@datadog-datadog-prod-us1-2

This comment has been minimized.

@codecov-commenter

codecov-commenter commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.00000% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.76%. Comparing base (e71d0da) to head (ee8b4b4).

Files with missing lines Patch % Lines
src/interface.cpp 64.00% 15 Missing and 3 partials ⚠️
src/object_store.cpp 81.81% 3 Missing and 5 partials ⚠️
src/context.hpp 82.75% 5 Missing ⚠️
src/evaluation_engine.hpp 76.47% 2 Missing and 2 partials ⚠️
src/processor/base.hpp 0.00% 0 Missing and 3 partials ⚠️
src/evaluation_engine.cpp 89.47% 0 Missing and 2 partials ⚠️
src/object_store.hpp 77.77% 1 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
waf_test 84.76% <76.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Dynamic Artifact Size Comparison 📦

Artifact Previous Release This PR Difference
darwin-arm64::libddwaf.dylib 2004032 2021104 0.85%
darwin-universal::libddwaf.dylib 4215872 4232944 0.40%
darwin-x86_64::libddwaf.dylib 2195712 2204464 0.39%
linux-aarch64::libddwaf.so 2378224 2383472 0.22%
linux-armv7::libddwaf.so 2046280 2053144 0.33%
linux-i386::libddwaf.so 2300828 2306956 0.26%
linux-x86_64::libddwaf.so 2571120 2576912 0.22%
windows-arm64::ddwaf.dll 6686208 6711808 0.38%
windows-win32::ddwaf.dll 3315712 3328512 0.38%
windows-x64::ddwaf.dll 4045824 4058112 0.30%

Static Artifact Size Comparison 📦

Artifact Previous Release This PR Difference
darwin-arm64::libddwaf.a 92215128 93026048 0.87%
darwin-arm64::libddwaf.a.stripped 4707464 4718512 0.23%
darwin-universal::libddwaf.a 185945888 187569904 0.87%
darwin-universal::libddwaf.a.stripped 10023864 10046632 0.22%
darwin-x86_64::libddwaf.a 93730712 94543808 0.86%
darwin-x86_64::libddwaf.a.stripped 5316352 5328072 0.22%
linux-aarch64::libddwaf.a 75161592 75264822 0.13%
linux-aarch64::libddwaf.a.stripped 12162860 12188114 0.20%
linux-armv7::libddwaf.a 66399138 66494498 0.14%
linux-armv7::libddwaf.a.stripped 11168358 11189438 0.18%
linux-i386::libddwaf.a 64591428 64681938 0.14%
linux-i386::libddwaf.a.stripped 9661240 9679654 0.19%
linux-x86_64::libddwaf.a 75652672 75755662 0.13%
linux-x86_64::libddwaf.a.stripped 11966124 11988786 0.18%
windows-arm64::ddwaf.lib 16410 16902 2.99%
windows-arm64::ddwaf_static.lib 134528158 134808924 0.20%
windows-win32::ddwaf.lib 16726 17228 3.00%
windows-win32::ddwaf_static.lib 47564214 47684490 0.25%
windows-x64::ddwaf.lib 16410 16902 2.99%
windows-x64::ddwaf_static.lib 55369970 55516012 0.26%

@Anilm3 Anilm3 force-pushed the anilm3/multieval branch 4 times, most recently from df4a13d to 47ed904 Compare June 10, 2026 08:58
@DataDog DataDog deleted a comment from chatgpt-codex-connector Bot Jun 10, 2026
@Anilm3

Anilm3 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/object_store.cpp Outdated
@Anilm3 Anilm3 force-pushed the anilm3/multieval branch from 47ed904 to 41ad8b7 Compare June 10, 2026 10:27

@christophe-papazian christophe-papazian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread src/evaluation_engine.cpp
Comment thread tests/integration/interface/context/multieval/test.cpp Outdated
Comment thread tests/integration/interface/context/multieval/test.cpp Outdated
Comment thread tests/unit/evaluation_engine_test.cpp Outdated
Comment thread src/evaluation_engine.cpp Outdated
Comment thread src/object_store.hpp Outdated
Comment thread src/evaluation_engine.cpp Outdated
Comment thread src/evaluation_engine.cpp Outdated
Comment thread src/object_store.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants