8000 ci(serverless): force reimport of modules during serverless test by purple4reina · Pull Request #11888 · DataDog/dd-trace-py · GitHub
[go: up one dir, main page]

Skip to content

ci(serverless): force reimport of modules during serverless test #11888

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

Merged
merged 13 commits into from
Feb 27, 2025

Conversation

purple4reina
Copy link
Contributor
@purple4reina purple4reina commented Jan 9, 2025

Commit 12655ee removed the @pytest.mark.subprocess() from the serverless slow imports test. This effectively rendered the test useless as ddtrace and all required modules had already been imported in the parent process.

Adding the subprocess mark back will ensure that the sys modules are fresh. We must still go through and delete entries because @pytest.mark.subprocess() relies on multiprocessing, so it must be removed so as to ensure it can be reimported if needed.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

@purple4reina purple4reina requested a review from a team as a code owner January 9, 2025 22:11
Copy link
Contributor
github-actions bot commented Jan 9, 2025

CODEOWNERS have been resolved as:

tests/internal/test_serverless.py                                       @DataDog/apm-core-python @DataDog/apm-serverless

@datadog-dd-trace-py-rkomorn
Copy link
datadog-dd-trace-py-rkomorn bot commented Jan 9, 2025

Datadog Report

Branch report: rey.abolofia/fix-sls-test
Commit report: 111226c
Test service: dd-trace-py

✅ 0 Failed, 130 Passed, 1468 Skipped, 4m 38.31s Total duration (35m 39.08s time saved)

@pr-commenter
Copy link
pr-commenter bot commented Jan 9, 2025

Benchmarks

Benchmark execution time: 2025-02-20 20:24:44

Comparing candidate commit 2657a25 in PR branch rey.abolofia/fix-sls-test with baseline commit 043afbf in branch main.

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

scenario:iast_aspects-ospathbasename_aspect

  • 🟥 execution_time [+285.040ns; +324.664ns] or [+8.624%; +9.823%]

scenario:iast_aspects-ospathjoin_aspect

  • 🟥 execution_time [+538.128ns; +599.836ns] or [+10.320%; +11.504%]

scenario:iast_aspects-ospathsplit_aspect

  • 🟥 execution_time [+294.282ns; +355.842ns] or [+7.455%; +9.015%]

@purple4reina purple4reina added the changelog/no-changelog A changelog entry is not required for this PR. label Jan 10, 2025
@emmettbutler emmettbutler changed the title Force reimport of modules during serverless test. ci(serverless): force reimport of modules during serverless test Jan 10, 2025
@purple4reina purple4reina force-pushed the rey.abolofia/fix-sls-test branch from 07c753d to 6977fcd Compare January 10, 2025 20:58
@purple4reina purple4reina requested a review from a team as a code owner January 10, 2025 20:58
@purple4reina purple4reina force-pushed the rey.abolofia/fix-sls-test branch from 6977fcd to ee55cae Compare January 10, 2025 21:14
@purple4reina purple4reina enabled auto-merge (squash) January 22, 2025 21:07
@datadog-dd-trace-py-rkomorn
Copy link
datadog-dd-trace-py-rkomorn bot commented Jan 28, 2025

Datadog Report

Branch report: rey.abolofia/fix-sls-test
Commit report: 6e18fe2
Test service: dd-trace-py

✅ 0 Failed, 130 Passed, 1184 Skipped, 3m 24.55s Total duration (25m 24.67s time saved)

@emmettbutler emmettbutler self-assigned this Jan 31, 2025
@emmettbutler
Copy link
Collaborator

This change is especially tough to merge because the change to tests.yml causes the entire test suite to run, even stuff that a human can tell is clearly unrelated.

@emmettbutler
Copy link
Collaborator

fixing the profile suite issue here #12187

@emmettbutler
Copy link
Collaborator

here's a fix for the llmobs failures #12191

purple4reina and others added 5 commits February 13, 2025 08:57
…le (#12035)

## Motivation

Refactors all web server integrations still using `tracer.trace` to
instead use `core.context_with_data`. This is in preparation for
supporting AWS API Gateway to ensure all web servers share the same code
path.

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
…t config (#12089)

This PR makes a change to our shared distributed tracing header
injection method to dispatch signals/events instead of relying on the
global config settings, which is only modifiable via env vars. This
fixes distributed tracing for users that might rely solely on the
`LLMObs.enable()` setup config.

Programmatic `LLMObs.enable()/disable()` calls do not set the global
`config._llmobs_enabled` boolean setting, which is only controlled by
the `DD_LLMOBS_ENABLED` env var. This was problematic for users that
relied on manual `LLMObs.enable()` setup (i.e. no env vars) because our
distributed tracing injection code only checks the global config to
inject llmobs parent IDs into request headers. If users manually enabled
LLMObs without any env vars, then this would not be reflected in the
global config value and thus LLMObs parent IDs would never be injected
into the request headers.

We can't check directly if LLMObs is enabled in the http injection
module because:
1. This would require us to import significant product-specific
LLMObs-code into the shared http injector helper module which would
impact non-LLMObs users' app performance
2. Circular imports in LLMObs which imports http injector logic to use
in its own helpers

Instead of doing our check based on the global `config._llmobs_enabled`
setting, we now send a tracing event to our shared product listeners,
and register a corresponding `LLMObs._inject_llmobs_context()` hook to
be called for all inject() calls if LLMObs is enabled (we check the
LLMObs instance, not the global config setting value).

~One risk and why I don't like changing global config settings is
because this then implies that it is no longer global or tied to an env
var (I want to push for env var configuration where possible over manual
overriding/enabling). If a global enabled config can be toggled
indiscriminately then this could open a can of worms for
enabling/disabling logic in our LLMObs service, which isn't really
designed to be toggled on/off multiple times in the app's lifespan.
However if some users cannot rely on env vars, then I don't see any
other solution that does not couple tracer internal code with LLMObs
code which is a no-option.~ (UPDATE: we avoided this issue by using
signal dispatching)

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
ddtrace v3.0 is set to remove `ddtrace.providers` module from the public
API. However we should still allow users to use their own
ContextProviders. This PR ensures the BaseContextProvider remains in the
public API and can be used in `tracer.configure(...)`.

- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

- [x] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
@emmettbutler emmettbutler force-pushed the rey.abolofia/fix-sls-test branch from 3618be1 to 502a4fb Compare February 13, 2025 16:58
Copy link
Member
@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

#12314 was merged, so the rewriting of version file should not be necessary anymore.

purple4reina and others added 5 commits February 13, 2025 10:18
Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
There are several binary files that are removed from ddtrace when it is
packaged as a AWS Lambda Layer (see
https://github.com/DataDog/datadog-lambda-python/blob/main/Dockerfile).
This PR adds testing to ensure that none of those files are imported in
certain cases.

Note that the `ddtrace.contrib.requests` package currently attempts to
import a removed file. This test has been marked xfail.
@purple4reina purple4reina requested a review from a team as a code owner February 20, 2025 19:36
@purple4reina purple4reina force-pushed the rey.abolofia/fix-sls-test branch from 87fcee0 to 2657a25 Compare February 20, 2025 19:42
@purple4reina purple4reina merged commit 8c4d62d into main Feb 27, 2025
213 of 214 checks passed
@purple4reina purple4reina deleted the rey.abolofia/fix-sls-test branch February 27, 2025 19:33
emmettbutler pushed a commit that referenced this pull request Feb 28, 2025
…est" (#12564)

The test added is flaky and fails sometimes with `ModuleNotFoundError:
No module named 'ddtrace'`

- [x] Reverts #11888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0