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

internal/civisibility/utils/net: a new http client for rapid endpoints #2869

Merged
merged 11 commits into from
Sep 19, 2024

Conversation

tonyredondo
Copy link
Member

@tonyredondo tonyredondo commented Sep 16, 2024

What does this PR do?

This PR adds a new http client for specific use on rapid endpoints used by ci visibility with json support, exponential backoff, rate-limiting status code, gzip compression and multipart bodies (attachments).

Motivation

Some CI Visibility features require getting, posting and sending multipart form data to the backend. Features like:

  • Early Flake detection
  • Git upload
  • Intelligent test runner
  • Settings api
  • Retry failed tests

Code Coverage

image

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!

@pr-commenter
Copy link

pr-commenter bot commented Sep 16, 2024

Benchmarks

Benchmark execution time: 2024-09-19 11:56:47

Comparing candidate commit d2119cb in PR branch tony/civisibility-rapid-http-client with baseline commit b94c2c3 in branch main.

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

@tonyredondo tonyredondo marked this pull request as ready for review September 17, 2024 14:45
@tonyredondo tonyredondo requested a review from a team as a code owner September 17, 2024 14:45
Copy link

@romainkomorndatadog romainkomorndatadog left a comment

Choose a reason for hiding this comment

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

Maybe I just don't know Go but I find the amount of omitempty in JSON struct definitions a bit concerning.

Doesn't that mean we could unmarshal unexpectedly formatted JSON responses, and then crash later when we try to use them? Or does the compiler make sure we never try to access something that might be empty?

internal/civisibility/utils/net/client_test.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/efd_api.go Show resolved Hide resolved
internal/civisibility/utils/net/efd_api.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/http.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/http.go Show resolved Hide resolved
internal/civisibility/utils/net/searchcommits_api.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/settings_api.go Outdated Show resolved Hide resolved
@tonyredondo
Copy link
Member Author

t mean we could unmarshal unexpectedly formatted JSON responses, and then crash later when we try to use them? Or does the compiler make sure we never try to access something that might be empty?

omitempty is only used on serialization, so if the value of that omitempty field is nil or empty(default value) then is omitted on serialization. it doesn't affect unmarshalling.

@romainkomorndatadog
Copy link

romainkomorndatadog commented Sep 18, 2024

it doesn't affect unmarshalling.

Oh, carry on then. :)

Edit: although if it doesn't affect unmarshalling, why use omitempty on things like the JSON response from the API endpoints? We never marshal those anyway, right?

internal/civisibility/utils/net/sendpackfiles_api_test.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/client.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/client.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/client.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/client.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/client.go Outdated Show resolved Hide resolved
internal/civisibility/utils/net/client.go Outdated Show resolved Hide resolved
@tonyredondo
Copy link
Member Author

it doesn't affect unmarshalling.

Oh, carry on then. :)

Edit: although if it doesn't affect unmarshalling, why use omitempty on things like the JSON response from the API endpoints? We never marshal those anyway, right?

Yes I removed a lot of omitempty here: 7c60549

@tonyredondo tonyredondo force-pushed the tony/civisibility-rapid-http-client branch from f0c2d4c to c2ee372 Compare September 18, 2024 21:25
@tonyredondo tonyredondo merged commit 054d19d into main Sep 19, 2024
145 checks passed
@tonyredondo tonyredondo deleted the tony/civisibility-rapid-http-client branch September 19, 2024 11:59
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.

4 participants