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

dyngo: dynamically register listeners only if they're needed #2394

Merged
merged 14 commits into from
Feb 6, 2024

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Nov 28, 2023

What does this PR do?

With a somewhat significant refactor, and use of Go generics, it is possible to have AppSec listeners self-install if, and only if a contrib that may emit events they listen to is loaded.

Motivation

This avoid logging uncanny messages in debug mode, where we previously claimed to register all available listeners (GraphQL, gRPC, HTTP), despite some of them being nonsensical in the user's application context.

It also allows the compiler to perform better dead code elimination, or even entirely skipping packages corresponding to the unneeded listeners.

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.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@pr-commenter
Copy link

pr-commenter bot commented Nov 28, 2023

Benchmarks

Benchmark execution time: 2024-02-05 14:00:11

Comparing candidate commit b0160e2 in PR branch romain.marcadier/innovation-week with baseline commit 7595b2d in branch main.

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

scenario:BenchmarkSingleSpanRetention/with-rules/match-all-24

  • 🟩 execution_time [-6.839µs; -5.448µs] or [-2.620%; -2.087%]

scenario:BenchmarkStartRequestSpan-24

  • 🟥 execution_time [+13.574ns; +16.386ns] or [+3.449%; +4.163%]

@RomainMuller RomainMuller force-pushed the romain.marcadier/innovation-week branch 2 times, most recently from da82cfe to 3d6b5e6 Compare November 30, 2023 16:59
@RomainMuller RomainMuller changed the title feat(dyngo): major refactor of dyngo package dyngo: dynamically register listeners only if they're needed Dec 20, 2023
With a somewhat significant refactor, and use of Go generics, it is possible to have AppSec listeners self-install if, and only if a contrib that may emit events they listen to is loaded.

This avoid logging uncanny messages in debug mode, where we previously claimed to register all available listeners (GraphQL, gRPC, HTTP), despite some of them being nonsensical in the user's application context.

It also allows the compiler to perform better dead code elimination, or even entirely skipping packages corresponding to the unneeded listeners.
@RomainMuller RomainMuller force-pushed the romain.marcadier/innovation-week branch from 6f9f8bb to 9814dc4 Compare December 20, 2023 16:53
@RomainMuller RomainMuller marked this pull request as ready for review December 21, 2023 09:37
@RomainMuller RomainMuller requested a review from a team as a code owner December 21, 2023 09:37
@RomainMuller RomainMuller requested a review from a team December 21, 2023 09:37
@RomainMuller RomainMuller requested a review from a team as a code owner January 10, 2024 09:11
@katiehockman katiehockman added the apm:ecosystem contrib/* related feature requests or bugs label Jan 10, 2024
Copy link
Contributor

@Hellzy Hellzy left a comment

Choose a reason for hiding this comment

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

Cool rework!

̶I̶'̶m̶ ̶t̶h̶i̶n̶k̶i̶n̶g̶ ̶w̶e̶ ̶c̶a̶n̶ ̶g̶e̶t̶ ̶r̶i̶d̶ ̶o̶f̶ ̶I̶s̶A̶r̶g̶O̶r̶f̶/̶I̶s̶R̶e̶s̶u̶l̶t̶O̶f̶ ̶i̶m̶p̶l̶e̶m̶s̶ ̶o̶v̶e̶r̶a̶l̶l̶ ̶a̶n̶d̶ ̶j̶u̶s̶t̶ ̶u̶s̶e̶ ̶t̶h̶e̶ ̶i̶n̶t̶e̶r̶f̶a̶c̶e̶s̶ ̶t̶o̶ ̶e̶n̶f̶o̶r̶c̶e̶ ̶t̶y̶p̶e̶ ̶c̶o̶n̶s̶t̶r̶a̶i̶n̶t̶,̶ ̶l̶e̶t̶ ̶m̶e̶ ̶k̶n̶o̶w̶ ̶w̶h̶a̶t̶ ̶y̶o̶u̶ ̶t̶h̶i̶n̶k̶.̶ ̶M̶a̶i̶n̶l̶y̶ ̶i̶t̶ ̶j̶u̶s̶t̶ ̶r̶e̶m̶o̶v̶e̶s̶ ̶t̶h̶e̶ ̶n̶e̶e̶d̶ ̶t̶o̶ ̶i̶m̶p̶l̶e̶m̶e̶n̶t̶ ̶t̶h̶o̶s̶e̶ ̶e̶m̶p̶t̶y̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶s̶ ̶f̶o̶r̶ ̶e̶a̶c̶h̶ ̶a̶r̶g̶/̶r̶e̶s̶ ̶t̶y̶p̶e̶

Other than that LGTM, spotted a few exported funcs that could use a description for consistency.

EDIT: scratch that first part, making it work would do more harm than good

internal/appsec/dyngo/operation.go Show resolved Hide resolved
internal/appsec/dyngo/operation.go Show resolved Hide resolved
internal/appsec/waf.go Show resolved Hide resolved
internal/appsec/listener/grpcsec/grpc.go Show resolved Hide resolved
internal/appsec/dyngo/operation.go Show resolved Hide resolved
Copy link
Contributor

@katiehockman katiehockman left a comment

Choose a reason for hiding this comment

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

Didn't review the appsec code, but I don't see any major changes in contrib other than using a different package, so I'll trust that others have reviewed the rest.

@RomainMuller RomainMuller enabled auto-merge (squash) February 5, 2024 10:53
internal/appsec/waf.go Show resolved Hide resolved
internal/appsec/listener/graphqlsec/graphql.go Outdated Show resolved Hide resolved
internal/appsec/dyngo/operation.go Outdated Show resolved Hide resolved
auto-merge was automatically disabled February 5, 2024 13:20

Pull Request is not mergeable

auto-merge was automatically disabled February 5, 2024 13:20

Pull Request is not mergeable

@RomainMuller RomainMuller force-pushed the romain.marcadier/innovation-week branch from 4eb7fdd to b0160e2 Compare February 5, 2024 13:45
@Julio-Guerra
Copy link
Contributor

Congrats - major API change embracing the Go generics the right way 👏 This was envisioned in the original PR design as a major improvement :-)

@RomainMuller
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Feb 6, 2024

🚂 MergeQueue

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.

Use /merge -c to cancel this operation!

@dd-devflow
Copy link

dd-devflow bot commented Feb 6, 2024

🚂 MergeQueue

Added to the queue.

This build is going to start soon! (estimated merge in less than 0s)

Use /merge -c to cancel this operation!

@RomainMuller RomainMuller merged commit 01bb802 into main Feb 6, 2024
335 of 336 checks passed
@RomainMuller RomainMuller deleted the romain.marcadier/innovation-week branch February 6, 2024 08:55
@dd-devflow
Copy link

dd-devflow bot commented Feb 6, 2024

🚂 MergeQueue

This pull request was merged directly.

@Julio-Guerra Julio-Guerra added appsec and removed apm:ecosystem contrib/* related feature requests or bugs mergequeue-status: done labels Feb 6, 2024
@github-actions github-actions bot added the apm:ecosystem contrib/* related feature requests or bugs label Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs appsec
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants