Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appsec: never start a new WAF Context when one is in context #2989

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

eliottness
Copy link
Contributor

@eliottness eliottness commented Nov 25, 2024

What does this PR do?

This PR does two things:

  • Add a new FindOperation function in dyngo
  • Use it to find an existing waf.ContextOperation in the current context so we don't start more than one at a time

Motivation

For example gorilla/mux and go-chi/chi are contribs that uses net/http under the hood and since orchestrion will be instrumenting both of them, we will have multiple WAF Contexts in the Operation start

Microbenchmarks

goos: linux
goarch: amd64
pkg: gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/dyngo
cpu: 12th Gen Intel(R) Core(TM) i9-12900H
                                                  │   old.out    │               new.out                │
                                                  │    sec/op    │    sec/op     vs base                │
Events/emitting/stack=1/start_event-20              162.1n ± 19%   165.3n ± 19%        ~ (p=0.969 n=25)
Events/emitting/stack=1/start_+_finish_events-20    391.2n ±  9%   415.3n ± 12%   +6.16% (p=0.023 n=25)
Events/emitting/stack=2/start_event-20              165.0n ± 24%   182.4n ± 19%        ~ (p=0.488 n=25)
Events/emitting/stack=2/start_+_finish_events-20    413.0n ±  8%   455.1n ±  7%  +10.19% (p=0.009 n=25)
Events/emitting/stack=4/start_event-20              205.6n ± 20%   214.5n ± 22%        ~ (p=0.453 n=25)
Events/emitting/stack=4/start_+_finish_events-20    462.3n ±  8%   510.9n ±  6%  +10.51% (p=0.005 n=25)
Events/emitting/stack=8/start_event-20              260.2n ± 14%   276.9n ± 14%        ~ (p=0.255 n=25)
Events/emitting/stack=8/start_+_finish_events-20    594.3n ±  6%   664.6n ±  6%  +11.83% (p=0.000 n=25)
Events/emitting/stack=16/start_event-20             368.9n ± 10%   411.7n ± 11%  +11.60% (p=0.041 n=25)
Events/emitting/stack=16/start_+_finish_events-20   831.9n ±  4%   936.6n ±  5%  +12.59% (p=0.000 n=25)
Events/emitting/stack=32/start_event-20             611.7n ±  7%   672.7n ±  7%   +9.97% (p=0.000 n=25)
Events/emitting/stack=32/start_+_finish_events-20   1.309µ ±  3%   1.470µ ±  2%  +12.30% (p=0.000 n=25)
Events/emitting/stack=64/start_event-20             1.058µ ±  5%   1.212µ ±  3%  +14.56% (p=0.000 n=25)
Events/emitting/stack=64/start_+_finish_events-20   2.238µ ±  1%   2.539µ ±  2%  +13.45% (p=0.000 n=25)
Events/registering/start_event-20                   73.26n ± 80%   84.20n ± 54%        ~ (p=0.985 n=25)
Events/registering/finish_event-20                  81.32n ± 29%   83.94n ± 29%        ~ (p=0.497 n=25)
geomean                                             383.6n         420.4n         +9.59%

                                                  │   old.out    │                new.out                 │
                                                  │     B/op     │     B/op      vs base                  │
Events/emitting/stack=1/start_event-20              128.0 ±   0%   128.0 ±   0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=1/start_+_finish_events-20    128.0 ±   0%   144.0 ±   0%  +12.50% (p=0.000 n=25)
Events/emitting/stack=2/start_event-20              128.0 ±   0%   128.0 ±   0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=2/start_+_finish_events-20    128.0 ±   0%   144.0 ±   0%  +12.50% (p=0.000 n=25)
Events/emitting/stack=4/start_event-20              128.0 ±   0%   128.0 ±   0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=4/start_+_finish_events-20    128.0 ±   0%   144.0 ±   0%  +12.50% (p=0.000 n=25)
Events/emitting/stack=8/start_event-20              128.0 ±   0%   128.0 ±   0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=8/start_+_finish_events-20    128.0 ±   0%   144.0 ±   0%  +12.50% (p=0.000 n=25)
Events/emitting/stack=16/start_event-20             128.0 ±   0%   128.0 ±   0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=16/start_+_finish_events-20   128.0 ±   0%   144.0 ±   0%  +12.50% (p=0.000 n=25)
Events/emitting/stack=32/start_event-20             128.0 ±   0%   128.0 ±   0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=32/start_+_finish_events-20   128.0 ±   0%   144.0 ±   0%  +12.50% (p=0.000 n=25)
Events/emitting/stack=64/start_event-20             128.0 ±   0%   128.0 ±   0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=64/start_+_finish_events-20   128.0 ±   0%   144.0 ±   0%  +12.50% (p=0.000 n=25)
Events/registering/start_event-20                   16.00 ± 662%   16.00 ± 712%        ~ (p=0.962 n=25)
Events/registering/finish_event-20                  16.00 ± 644%   16.00 ± 606%        ~ (p=0.954 n=25)
geomean                                             98.70          103.9          +5.29%
¹ all samples are equal

                                                  │  old.out   │               new.out                │
                                                  │ allocs/op  │ allocs/op   vs base                  │
Events/emitting/stack=1/start_event-20              2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=1/start_+_finish_events-20    2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=25)
Events/emitting/stack=2/start_event-20              2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=2/start_+_finish_events-20    2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=25)
Events/emitting/stack=4/start_event-20              2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=4/start_+_finish_events-20    2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=25)
Events/emitting/stack=8/start_event-20              2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=8/start_+_finish_events-20    2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=25)
Events/emitting/stack=16/start_event-20             2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=16/start_+_finish_events-20   2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=25)
Events/emitting/stack=32/start_event-20             2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=32/start_+_finish_events-20   2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=25)
Events/emitting/stack=64/start_event-20             2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=25) ¹
Events/emitting/stack=64/start_+_finish_events-20   2.000 ± 0%   3.000 ± 0%  +50.00% (p=0.000 n=25)
Events/registering/start_event-20                   1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=25) ¹
Events/registering/finish_event-20                  1.000 ± 0%   1.000 ± 0%        ~ (p=1.000 n=25) ¹
geomean        

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

@eliottness eliottness marked this pull request as ready for review November 25, 2024 16:51
@eliottness eliottness requested a review from a team as a code owner November 25, 2024 16:51
@eliottness eliottness force-pushed the eliottness/deduplicated-the-right-operations branch from 46a5a23 to a4144b7 Compare November 25, 2024 16:51
@eliottness eliottness self-assigned this Nov 25, 2024
@pr-commenter
Copy link

pr-commenter bot commented Nov 25, 2024

Benchmarks

Benchmark execution time: 2024-11-26 10:33:13

Comparing candidate commit 4e23ec9 in PR branch eliottness/deduplicated-the-right-operations with baseline commit e9a64d3 in branch main.

Found 2 performance improvements and 0 performance regressions! Performance is the same for 57 metrics, 0 unstable metrics.

scenario:BenchmarkSetTagMetric-24

  • 🟩 execution_time [-5.122ns; -3.118ns] or [-4.257%; -2.591%]

scenario:BenchmarkSetTagStringer-24

  • 🟩 execution_time [-6.118ns; -3.322ns] or [-4.296%; -2.333%]

internal/appsec/dyngo/operation.go Outdated Show resolved Hide resolved
@eliottness eliottness force-pushed the eliottness/deduplicated-the-right-operations branch from 74b225d to 4e23ec9 Compare November 26, 2024 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants