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

contrib: add validation tests using test-agent #2047

Merged
merged 28 commits into from
Sep 18, 2023
Merged

Conversation

rarguelloF
Copy link
Contributor

@rarguelloF rarguelloF commented Jun 14, 2023

Draft PR for PoC of Adding Datadog APM Test Agent alongside Go Tracer contrib tests

Two integrations were added as examples of implementing the new testing interface.

A CI step to show all Datadog APM Test Agent logs for traces received, trace checks run, failing trace checks, etc.

What does this PR do?

This PR adds the APM Test Agent to run alongside unit / contrib tests in CI testing. A testing interface is created in contrib/internal/validationtest, which can be implemented by each contrib integration in order to generate test traces which are emitted to the APM Test Agent using the real Golang tracer. These traces are tested against a number of centrally located checks written within the Test-Agent, including:

  • Service naming checks
  • Peer.service checks
  • Trace header checks

The APM Test Agent is being added to every DD APM Tracer with the primary purpose of providing a centralized location for writing tests which will subsequently be used for asserting on handled traces. This strategy will help bring consistency to Datadog APM Tagging/ integration support.

Motivation
We're currently working on integrating the test agent into each tracer's test suites, and for the test agent to handle traces produced by integrations during testing. Within the Test-Agent, we are then creating checks for Service Naming, Unified Naming Conventions tagging, etc in order to be a centralized location for asserting on integration traces. Allows us to leverage traces produced from integrations during testing.

Testing
See above for passing / non passing integration tests

Reviewer's Checklist

  • Changed code has unit tests for its functionality.
  • If this interacts with the agent in a new way, a system test has been added.

@pr-commenter
Copy link

pr-commenter bot commented Jun 14, 2023

Benchmarks

Benchmark execution time: 2023-09-18 14:23:23

Comparing candidate commit e5706ea in PR branch rarguelloF/test-agent with baseline commit 2ac90e1 in branch main.

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

@wconti27 wconti27 self-assigned this Jun 16, 2023
ddtrace/tracer/option.go Outdated Show resolved Hide resolved
ddtrace/tracer/option.go Outdated Show resolved Hide resolved
ddtrace/tracer/option.go Outdated Show resolved Hide resolved
.github/workflows/unit-integration-tests.yml Outdated Show resolved Hide resolved
docker-compose.yaml Outdated Show resolved Hide resolved
ddtrace/tracer/option.go Outdated Show resolved Hide resolved
@wconti27 wconti27 requested a review from ahmed-mez June 22, 2023 18:33
Comment on lines 15 to 16
memcachetest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/integrations/gomemcache/memcache"
dnstest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/integrations/miekg/dns"
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of these super long paths and instead of creating a new contrib/internal/validationtest/integrations directory, how about putting the test utils of each contrib in an internal dir under the corresponding and existing contrib package (i.e contrib/<path>/<to>/<dir>/internal) ?

Suggested change
memcachetest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/integrations/gomemcache/memcache"
dnstest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/integrations/miekg/dns"
memcachetest "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomemcache/memcache/internal"
dnstest "gopkg.in/DataDog/dd-trace-go.v1/contrib/miekg/dns/internal"

Copy link
Contributor

Choose a reason for hiding this comment

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

Doing this results in a use of internal package ... not allowed to compile error when trying to import the tests within the validationtest file.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about putting the test utils in contrib/<path>/<to>/<dir>/internal/test instead of contrib/<path>/<to>/<dir>/internal ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Bumping this thread as I believe we can avoid re-creating individual and long contrib folders.
e.g contrib/internal/validationtest/contrib/miekg/dns/integration.go should be moved to contrib/miekg/dns/internal/test/integration.go. The contrib/miekg/dns dir already exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is we cannot import an internal sub-package from here since the Go compiler doesn't allow so:

When the go command sees an import of a package with internal in its path, it verifies that the package doing the import is within the tree rooted at the parent of the internal directory. For example, a package .../a/b/c/internal/d/e/f can be imported only by code in the directory tree rooted at .../a/b/c. It cannot be imported by code in .../a/b/g or in any other repository.

So in this case we have:

contrib/internal/validationtest

And the proposed internal subpackages would be:

contrib/miekg/dns/internal/test

So since the only common root from both directories is contrib/, this wouldn't be possible and any shared internal code needs to be placed under contrib/internal (sadly for us 😢 ).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An extra alternative would be to have these sub-packages not being internal, like contrib/miekg/dns/test - not sure how we feel about this approach...

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation @rarguelloF !

I think an alternative to have shorter paths would be to have a big package contrib/internal/, where each integration is in its own file, like miekg_dns.go, net_http.go, etc.

I like the idea! We can do it this way for now and move files to separate packages per integration in the future if necessary.

Copy link
Contributor

@ahmed-mez ahmed-mez Sep 12, 2023

Choose a reason for hiding this comment

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

miekg_dns.go, net_http.go, etc can live under contrib/internal/validationtest or even contrib/internal/validationtest/contribs, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we redeclare the Integration struct for each contrib test file, they need to have separate packages and therefore live in separate folders, otherwise I was getting errors trying to put everything in the same directory. I changed the structure to be: contrib/internal/validationtest/miekg/dns.go, contrib/internal/validationtest/bradfitz/memcache.go ... etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wconti27 if we follow the big package approach, each struct needs to be named differently as they share the same namespace. e.g. NetHTTP, etc.

contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ahmed-mez ahmed-mez left a comment

Choose a reason for hiding this comment

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

3rd round of comments, thanks for applying and responding to the previous comments! Lmk if you have questions and happy to review again when all comments are resolved.

.github/workflows/unit-integration-tests.yml Outdated Show resolved Hide resolved
@ahmed-mez
Copy link
Contributor

@wconti27 & @rarguelloF I won't be available for the next few weeks! @dianashevchenko will own the review of this PR and help move it forward. Thanks!

@knusbaum knusbaum assigned knusbaum and unassigned knusbaum Jun 29, 2023
Copy link
Contributor

@ahmed-mez ahmed-mez left a comment

Choose a reason for hiding this comment

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

Added a few more comments! Please address the linter errors and mark the PR as ready for review. Happy to review again when ready!

contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
contrib/internal/validationtest/validation_test.go Outdated Show resolved Hide resolved
Comment on lines 162 to 165
componentName := ig.Name()
if componentName == "jmoiron/sqlx" {
componentName = "database/sql"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind explaining this special case? Why should the jmoiron/sqlx contrib return database/sql as name?

Copy link
Contributor

@wconti27 wconti27 Sep 12, 2023

Choose a reason for hiding this comment

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

Removing this, I honestly cant remember why I added this but I can cross that bridge once those integrations are added.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove it

Comment on lines 15 to 16
memcachetest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/integrations/gomemcache/memcache"
dnstest "gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/validationtest/integrations/miekg/dns"
Copy link
Contributor

Choose a reason for hiding this comment

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

Bumping this thread as I believe we can avoid re-creating individual and long contrib folders.
e.g contrib/internal/validationtest/contrib/miekg/dns/integration.go should be moved to contrib/miekg/dns/internal/test/integration.go. The contrib/miekg/dns dir already exists.

@wconti27 wconti27 marked this pull request as ready for review September 12, 2023 14:50
@wconti27 wconti27 requested a review from a team September 12, 2023 14:50
@wconti27 wconti27 requested a review from a team as a code owner September 12, 2023 14:50
@ahmed-mez ahmed-mez removed the request for review from dianashevchenko September 13, 2023 08:23
@ahmed-mez ahmed-mez changed the title WIP: contrib: add validation tests using test-agent contrib: add validation tests using test-agent Sep 18, 2023
@ahmed-mez ahmed-mez merged commit 992bbaf into main Sep 18, 2023
52 checks passed
@ahmed-mez ahmed-mez deleted the rarguelloF/test-agent branch September 18, 2023 14:37
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.

5 participants