Skip to content

contrib/net/http: support for path params from go 1.22 proposal#3079

Merged
eliottness merged 8 commits into
mainfrom
eliottness/net-http-path-params
Jan 15, 2025
Merged

contrib/net/http: support for path params from go 1.22 proposal#3079
eliottness merged 8 commits into
mainfrom
eliottness/net-http-path-params

Conversation

@eliottness

@eliottness eliottness commented Jan 10, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR add support for importing path params into dd-trace-go/contrib/internal/httptrace data pipeline as multiple other contribs already do.

In details I did:

  • Import the code that parses path patterns from net/http into dd-trace-go
  • Setup a cache for the results of this operation
  • Once the names have been extracted, loop over them and run (*http.Request).PathValue(name) and build a map[string]string with it

Motivation

  • Better coverage for ASM WAF.
  • Enabling a big bunch for tests in the system-tests that work with path params

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.
  • For internal contributors, a matching PR should be created to the v2-dev branch and reviewed by @DataDog/apm-go.

Unsure? Have a question? Request a review!

@eliottness eliottness added apm:ecosystem contrib/* related feature requests or bugs appsec labels Jan 10, 2025
@eliottness
eliottness force-pushed the eliottness/net-http-path-params branch from deb7177 to 9727b94 Compare January 10, 2025 16:48
@DataDog DataDog deleted a comment from datadog-datadog-prod-us1 Bot Jan 10, 2025
Signed-off-by: Eliott Bouhana <[email protected]>
@eliottness
eliottness marked this pull request as ready for review January 10, 2025 17:11
@eliottness
eliottness requested review from a team as code owners January 10, 2025 17:11
@pr-commenter

pr-commenter Bot commented Jan 10, 2025

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2025-01-14 17:24:34

Comparing candidate commit 697c5c0 in PR branch eliottness/net-http-path-params with baseline commit 471d723 in branch main.

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

scenario:BenchmarkHttpServeTrace-24

  • 🟥 execution_time [+345.543ns; +470.657ns] or [+2.188%; +2.981%]

Comment thread contrib/net/http/http.go Outdated
Comment thread contrib/net/http/pattern.go

@rarguelloF rarguelloF left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! just left a small nit to improve readability 🙇

Comment thread contrib/net/http/pattern.go Outdated
Comment on lines +85 to +86
// Wildcard names in a path must be distinct.
func patternNames(pattern string) ([]string, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I had to dig into the implementation and tests to understand what this function returns (since the type []string doesn't give much information). I think it would be nice if this was added to the doc string for future readers to quickly understand what this function does.

Adding something at the end like:

Given a pattern like "GET /foo/{bar}/{baz}", it returns []string{"bar", "baz"}

Also having 2 functions getPatternNames and patternNames with almost the same function signature doesn't help much (the difference is the first one uses the cache first). WDYT about renaming this one to parsePattern or parsePatternNames? (ideally I think it should be parsePattern, because if we want to parse other stuff from it in the future we would likely want to do it only once).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied all your comments (I believe) 👍

Signed-off-by: Eliott Bouhana <[email protected]>
@eliottness
eliottness merged commit c8fce21 into main Jan 15, 2025
@eliottness
eliottness deleted the eliottness/net-http-path-params branch January 15, 2025 08:44
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.

3 participants