Skip to content

Commit

Permalink
Merge branch '2.8' into munir/backport-9929-to-2-8
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur authored Aug 5, 2024
2 parents 036142a + edc6cac commit 73c3037
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 81 deletions.
33 changes: 18 additions & 15 deletions .riot/requirements/15235b0.txt → .riot/requirements/12974a3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/15235b0.in
# pip-compile --no-annotate .riot/requirements/12974a3.in
#
attrs==23.2.0
certifi==2023.11.17
certifi==2024.7.4
charset-normalizer==3.3.2
click==7.1.2
coverage[toml]==7.4.0
exceptiongroup==1.2.0
coverage[toml]==7.6.0
deprecated==1.2.14
exceptiongroup==1.2.2
flask==1.1.4
gunicorn==21.2.0
gunicorn==22.0.0
httpretty==1.0.5
hypothesis==6.45.0
idna==3.6
importlib-metadata==7.0.1
idna==3.7
importlib-metadata==7.0.0
iniconfig==2.0.0
itsdangerous==1.1.0
jinja2==2.11.3
markupsafe==1.1.1
mock==5.1.0
opentelemetry-api==1.24.0
opentracing==2.4.0
packaging==23.2
pluggy==1.3.0
pytest==7.4.4
pytest-cov==4.1.0
pytest-mock==3.12.0
packaging==24.1
pluggy==1.5.0
pytest==8.3.2
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
requests==2.31.0
requests==2.32.3
sortedcontainers==2.4.0
tomli==2.0.1
urllib3==2.1.0
urllib3==2.2.2
werkzeug==1.0.1
zipp==3.17.0
wrapt==1.16.0
zipp==3.19.2
29 changes: 17 additions & 12 deletions .riot/requirements/1153ad9.txt → .riot/requirements/1677649.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,36 @@
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/1153ad9.in
# pip-compile --no-annotate .riot/requirements/1677649.in
#
attrs==23.2.0
certifi==2023.11.17
certifi==2024.7.4
charset-normalizer==3.3.2
click==7.1.2
coverage[toml]==7.4.0
coverage[toml]==7.6.0
deprecated==1.2.14
flask==1.1.4
gunicorn==21.2.0
gunicorn==22.0.0
httpretty==1.0.5
hypothesis==6.45.0
idna==3.6
idna==3.7
importlib-metadata==7.0.0
iniconfig==2.0.0
itsdangerous==1.1.0
jinja2==2.11.3
markupsafe==1.1.1
mock==5.1.0
opentelemetry-api==1.24.0
opentracing==2.4.0
packaging==23.2
pluggy==1.3.0
pytest==7.4.4
pytest-cov==4.1.0
pytest-mock==3.12.0
packaging==24.1
pluggy==1.5.0
pytest==8.3.2
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
requests==2.31.0
requests==2.32.3
sortedcontainers==2.4.0
urllib3==2.1.0
urllib3==2.2.2
werkzeug==1.0.1
wrapt==1.16.0
zipp==3.19.2
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
# This file is autogenerated by pip-compile with Python 3.7
# by the following command:
#
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/427c22a.in
# pip-compile --config=pyproject.toml --no-annotate --resolver=backtracking .riot/requirements/17c4377.in
#
attrs==23.2.0
certifi==2023.11.17
certifi==2024.7.4
charset-normalizer==3.3.2
click==7.1.2
coverage[toml]==7.2.7
exceptiongroup==1.2.0
deprecated==1.2.14
exceptiongroup==1.2.2
flask==1.1.4
gunicorn==21.2.0
gunicorn==22.0.0
httpretty==1.0.5
hypothesis==6.45.0
idna==3.6
idna==3.7
importlib-metadata==6.7.0
iniconfig==2.0.0
itsdangerous==1.1.0
jinja2==2.11.3
markupsafe==1.1.1
mock==5.1.0
opentelemetry-api==1.22.0
opentracing==2.4.0
packaging==23.2
packaging==24.0
pluggy==1.2.0
pytest==7.4.4
pytest-cov==4.1.0
Expand All @@ -34,4 +36,5 @@ tomli==2.0.1
typing-extensions==4.7.1
urllib3==2.0.7
werkzeug==1.0.1
wrapt==1.16.0
zipp==3.15.0
33 changes: 18 additions & 15 deletions .riot/requirements/135aac0.txt → .riot/requirements/18589ec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --no-annotate --resolver=backtracking .riot/requirements/135aac0.in
# pip-compile --no-annotate .riot/requirements/18589ec.in
#
attrs==23.2.0
certifi==2023.11.17
certifi==2024.7.4
charset-normalizer==3.3.2
click==7.1.2
coverage[toml]==7.4.0
exceptiongroup==1.2.0
coverage[toml]==7.6.0
deprecated==1.2.14
exceptiongroup==1.2.2
flask==1.1.4
gunicorn==21.2.0
gunicorn==22.0.0
httpretty==1.0.5
hypothesis==6.45.0
idna==3.6
importlib-metadata==7.0.1
idna==3.7
importlib-metadata==7.0.0
iniconfig==2.0.0
itsdangerous==1.1.0
jinja2==2.11.3
markupsafe==1.1.1
mock==5.1.0
opentelemetry-api==1.24.0
opentracing==2.4.0
packaging==23.2
pluggy==1.3.0
pytest==7.4.4
pytest-cov==4.1.0
pytest-mock==3.12.0
packaging==24.1
pluggy==1.5.0
pytest==8.3.2
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
requests==2.31.0
requests==2.32.3
sortedcontainers==2.4.0
tomli==2.0.1
urllib3==2.1.0
urllib3==2.2.2
werkzeug==1.0.1
zipp==3.17.0
wrapt==1.16.0
zipp==3.19.2
31 changes: 18 additions & 13 deletions .riot/requirements/118cb50.txt → .riot/requirements/1a14242.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,38 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --no-annotate .riot/requirements/118cb50.in
# pip-compile --no-annotate .riot/requirements/1a14242.in
#
attrs==23.2.0
certifi==2023.11.17
certifi==2024.7.4
charset-normalizer==3.3.2
click==7.1.2
coverage[toml]==7.4.0
exceptiongroup==1.2.0
coverage[toml]==7.6.0
deprecated==1.2.14
exceptiongroup==1.2.2
flask==1.1.4
gunicorn==21.2.0
gunicorn==22.0.0
httpretty==1.0.5
hypothesis==6.45.0
idna==3.6
idna==3.7
importlib-metadata==7.0.0
iniconfig==2.0.0
itsdangerous==1.1.0
jinja2==2.11.3
markupsafe==1.1.1
mock==5.1.0
opentelemetry-api==1.24.0
opentracing==2.4.0
packaging==23.2
pluggy==1.3.0
pytest==7.4.4
pytest-cov==4.1.0
pytest-mock==3.12.0
packaging==24.1
pluggy==1.5.0
pytest==8.3.2
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
requests==2.31.0
requests==2.32.3
sortedcontainers==2.4.0
tomli==2.0.1
urllib3==2.1.0
urllib3==2.2.2
werkzeug==1.0.1
wrapt==1.16.0
zipp==3.19.2
29 changes: 17 additions & 12 deletions .riot/requirements/17a929f.txt → .riot/requirements/5c0475c.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,36 @@
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --no-annotate .riot/requirements/17a929f.in
# pip-compile --no-annotate .riot/requirements/5c0475c.in
#
attrs==23.2.0
certifi==2023.11.17
certifi==2024.7.4
charset-normalizer==3.3.2
click==7.1.2
coverage[toml]==7.4.0
coverage[toml]==7.6.0
deprecated==1.2.14
flask==1.1.4
gunicorn==21.2.0
gunicorn==22.0.0
httpretty==1.0.5
hypothesis==6.45.0
idna==3.6
idna==3.7
importlib-metadata==7.0.0
iniconfig==2.0.0
itsdangerous==1.1.0
jinja2==2.11.3
markupsafe==1.1.1
mock==5.1.0
opentelemetry-api==1.24.0
opentracing==2.4.0
packaging==23.2
pluggy==1.3.0
pytest==7.4.4
pytest-cov==4.1.0
pytest-mock==3.12.0
packaging==24.1
pluggy==1.5.0
pytest==8.3.2
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest-randomly==3.15.0
requests==2.31.0
requests==2.32.3
sortedcontainers==2.4.0
urllib3==2.1.0
urllib3==2.2.2
werkzeug==1.0.1
wrapt==1.16.0
zipp==3.19.2
8 changes: 2 additions & 6 deletions ddtrace/contrib/pytest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from ddtrace.contrib.unittest import unpatch as unpatch_unittest
from ddtrace.ext import SpanTypes
from ddtrace.ext import test
from ddtrace.ext.git import extract_workspace_path
from ddtrace.internal.ci_visibility import CIVisibility as _CIVisibility
from ddtrace.internal.ci_visibility.constants import EVENT_TYPE as _EVENT_TYPE
from ddtrace.internal.ci_visibility.constants import ITR_CORRELATION_ID_TAG_NAME
Expand Down Expand Up @@ -462,11 +461,8 @@ def pytest_sessionstart(session):
log.debug("CI Visibility enabled - starting test session")
global _global_skipped_elements
_global_skipped_elements = 0
try:
workspace_path = extract_workspace_path()
except ValueError:
log.debug("Couldn't extract workspace path from git, reverting to config rootdir")
workspace_path = session.config.rootdir

workspace_path = _CIVisibility.get_workspace_path() or session.config.rootdir

session._dd_workspace_path = workspace_path

Expand Down
17 changes: 16 additions & 1 deletion ddtrace/ext/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import random
import re
from shutil import which
import subprocess
from typing import Dict # noqa:F401
from typing import Generator # noqa:F401
Expand All @@ -18,6 +19,7 @@

from ddtrace.internal import compat
from ddtrace.internal.logger import get_logger
from ddtrace.internal.utils.cache import cached
from ddtrace.internal.utils.time import StopWatch


Expand Down Expand Up @@ -80,6 +82,16 @@ def is_ref_a_tag(ref):
return "tags/" in ref if ref else False


@cached()
def _get_executable_path(executable_name: str) -> Optional[str]:
"""Return the path to an executable.
NOTE: cached() requires an argument which is why executable_name is passed in, even though it's really only ever
used to find the git executable at this point.
"""
return which(executable_name, mode=os.X_OK)


def _git_subprocess_cmd_with_details(*cmd, cwd=None, std_in=None):
# type: (str, Optional[str], Optional[bytes]) -> _GitSubprocessDetails
"""Helper for invoking the git CLI binary
Expand All @@ -90,7 +102,10 @@ def _git_subprocess_cmd_with_details(*cmd, cwd=None, std_in=None):
- the time it took to execute the command, in milliseconds
- the exit code
"""
git_cmd = ["git"]
git_cmd = _get_executable_path("git")
if git_cmd is None:
raise FileNotFoundError("Git executable not found")
git_cmd = [git_cmd]
git_cmd.extend(cmd)

log.debug("Executing git command: %s", git_cmd)
Expand Down
11 changes: 11 additions & 0 deletions ddtrace/internal/ci_visibility/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,17 @@ def get_service(cls) -> Optional[str]:
return None
return instance._service

@classmethod
def get_workspace_path(cls) -> Optional[str]:
if not cls.enabled:
error_msg = "CI Visibility is not enabled"
log.warning(error_msg)
raise CIVisibilityError(error_msg)
instance = cls.get_instance()
if instance is None:
return None
return instance._tags.get(ci.WORKSPACE_PATH)


def _requires_civisibility_enabled(func):
def wrapper(*args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
CI Visibility: Fixes an issue where the pytest plugin would crash if the git binary was absent
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
features:
fixes:
- |
profiling: captures lock usages with ``with`` context managers, e.g. ``with lock:``
Loading

0 comments on commit 73c3037

Please sign in to comment.