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

profiler: deduplicate test profiler setup logic #2428

Merged
merged 2 commits into from
Dec 14, 2023

Conversation

nsrip-dd
Copy link
Contributor

@nsrip-dd nsrip-dd commented Dec 12, 2023

What does this PR do?

Create a common helper for setting up a profiler hooked up to a mock backend
for testing.

This PR doesn't touch every single test, since some such as TestTryUpload and
TestProfilerPassthrough rely on manipulating profiler-internal stuff and would
be better handled in separate commits.

Motivation

Many tests do the same thing: create an HTTP server running our mock backend
with a channel for receving profile uploads, start a profiler pointing to the
mock backend plus whatever other options we're testing, and then receive some
profile uploads, make assertions about them, and clean up at the end.

In general, I think this is a good pattern for testing the profiler. We should
ideally only test it using the public API, and only make assertions about the
observable output (i.e. what we send to our backend). Having a helper that
makes this easy to do this is a step in that direction.

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!

Many tests do the same thing: create an HTTP server running our mock
backend with a channel for receving profile uploads, start a profiler
pointing to the mock backend plus whatever other options we're testing,
and then receive some profiles and clean up at the end. Pull most of
this common setup code into some helpers, so that test cases can be
focused primarliy on the specific contents of the profile uploads
they're validating.

This commit doesn't touch every single test, since some such as
TestTryUpload and TestProfilerPassthrough rely on manipulating
profiler-internal stuff and would be better handled in separate commits.
@nsrip-dd nsrip-dd marked this pull request as ready for review December 12, 2023 18:41
@nsrip-dd nsrip-dd requested a review from a team as a code owner December 12, 2023 18:41
@pr-commenter
Copy link

pr-commenter bot commented Dec 12, 2023

Benchmarks

Benchmark execution time: 2023-12-12 18:48:31

Comparing candidate commit 068bc75 in PR branch nick.ripley/common-up-profiler-unit-tests with baseline commit 2c3a644 in branch main.

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

Copy link
Member

@felixge felixge left a comment

Choose a reason for hiding this comment

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

LGTM, this is great! Thank you so much ❤️

@nsrip-dd nsrip-dd enabled auto-merge (squash) December 14, 2023 15:22
@nsrip-dd nsrip-dd merged commit 5a92f7b into main Dec 14, 2023
53 checks passed
@nsrip-dd nsrip-dd deleted the nick.ripley/common-up-profiler-unit-tests branch December 14, 2023 15:27
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.

None yet

2 participants