Skip to content

Commit 449de1d

Browse files
fix(ci-visibility): revert ITR to using DD_CIVISIBILITY_ITR_ENABLED env var [backport 1.18] (#6699)
Backport 9d651f0 from #6684 to 1.18. Reverts the Intelligent Test Runner to use `DD_CIVISIBILITY_ITR_ENABLED`. This makes it conform with tracers in other languages that already use this environment variable. Also in this PR (for some reason): a bunch of formatting checks. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] 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) --------- Co-authored-by: Romain Komorn <[email protected]> Co-authored-by: Romain Komorn <[email protected]>
1 parent 112f8f0 commit 449de1d

File tree

7 files changed

+134
-237
lines changed

7 files changed

+134
-237
lines changed

ddtrace/internal/ci_visibility/recorder.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class CIVisibility(Service):
9292
enabled = False
9393
_test_suites_to_skip = None # type: Optional[List[str]]
9494
_tests_to_skip = defaultdict(list) # type: DefaultDict[str, List[str]]
95-
_itr_test_skipping_is_enabled = False
9695

9796
def __init__(self, tracer=None, config=None, service=None):
9897
# type: (Optional[Tracer], Optional[IntegrationConfig], Optional[str]) -> None
@@ -137,15 +136,25 @@ def __init__(self, tracer=None, config=None, service=None):
137136
self._requests_mode = REQUESTS_MODE.AGENTLESS_EVENTS
138137
elif self._agent_evp_proxy_is_available():
139138
self._requests_mode = REQUESTS_MODE.EVP_PROXY_EVENTS
139+
140140
self._code_coverage_enabled_by_api, self._test_skipping_enabled_by_api = self._check_enabled_features()
141141

142142
self._collect_coverage_enabled = self._should_collect_coverage(self._code_coverage_enabled_by_api)
143143

144144
self._configure_writer(coverage_enabled=self._collect_coverage_enabled)
145-
self._git_client = None # type: Optional[CIVisibilityGitClient]
146-
147-
self._configure_itr(self._api_key, self._app_key, self._requests_mode)
145+
self._git_client = None
148146

147+
if ddconfig._ci_visibility_intelligent_testrunner_enabled:
148+
if self._app_key is None:
149+
log.warning("Environment variable DD_APP_KEY not set, so no git metadata will be uploaded.")
150+
elif self._requests_mode == REQUESTS_MODE.TRACES:
151+
log.warning("Cannot start git client if mode is not agentless or evp proxy")
152+
else:
153+
if not self._test_skipping_enabled_by_api:
154+
log.warning("Intelligent Test Runner test skipping disabled by API")
155+
self._git_client = CIVisibilityGitClient(
156+
api_key=self._api_key or "", app_key=self._app_key, requests_mode=self._requests_mode
157+
)
149158
try:
150159
from ddtrace.internal.codeowners import Codeowners
151160

@@ -232,29 +241,6 @@ def _check_enabled_features(self):
232241
attributes = parsed["data"]["attributes"]
233242
return attributes["code_coverage"], attributes["tests_skipping"]
234243

235-
def _configure_itr(self, api_key, app_key, requests_mode):
236-
# type: (Optional[str], Optional[str], REQUESTS_MODE) -> None
237-
if not self._test_skipping_enabled_by_api:
238-
log.debug("Test skipping is not enabled by API")
239-
return
240-
if not app_key:
241-
log.debug("Test skipping disabled: required environment variable DD_APPLICATION_KEY is not set.")
242-
return
243-
if ddconfig._ci_visibility_intelligent_testrunner_disabled:
244-
log.warning(
245-
"Test skipping disabled: Intelligent Test Runner is enabled for this service, but "
246-
"disabled by DD_CIVISIBILITY_ITR_DISABLED environment variable or tracer configuration."
247-
)
248-
return
249-
250-
if requests_mode == REQUESTS_MODE.TRACES:
251-
log.warning("Test skipping disabled: cannot start git client if mode is not agentless or evp proxy.")
252-
return
253-
254-
log.info("Datadog Intelligent Test Runner is enabled.")
255-
self._itr_test_skipping_is_enabled = True
256-
self._git_client = CIVisibilityGitClient(api_key=api_key or "", app_key=app_key, requests_mode=requests_mode)
257-
258244
def _configure_writer(self, coverage_enabled=False, requests_mode=None):
259245
writer = None
260246
if requests_mode is None:
@@ -295,7 +281,7 @@ def _agent_evp_proxy_is_available(self):
295281
def test_skipping_enabled(cls):
296282
if not cls.enabled:
297283
return False
298-
return cls._instance and cls._instance._itr_test_skipping_is_enabled
284+
return cls._instance and cls._instance._test_skipping_enabled_by_api
299285

300286
def _fetch_tests_to_skip(self, skipping_mode):
301287
# Make sure git uploading has finished

ddtrace/settings/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ def __init__(self):
329329

330330
self._ci_visibility_agentless_enabled = asbool(os.getenv("DD_CIVISIBILITY_AGENTLESS_ENABLED", default=False))
331331
self._ci_visibility_agentless_url = os.getenv("DD_CIVISIBILITY_AGENTLESS_URL", default="")
332-
self._ci_visibility_intelligent_testrunner_disabled = asbool(
333-
os.getenv("DD_CIVISIBILITY_ITR_DISABLED", default=False)
332+
self._ci_visibility_intelligent_testrunner_enabled = asbool(
333+
os.getenv("DD_CIVISIBILITY_ITR_ENABLED", default=False)
334334
)
335335
self._otel_enabled = asbool(os.getenv("DD_TRACE_OTEL_ENABLED", False))
336336
if self._otel_enabled:

docs/configuration.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,14 @@ The following environment variables for the tracer are supported:
501501
version_added:
502502
v1.13.0:
503503

504-
DD_CIVISIBILITY_ITR_DISABLED:
504+
DD_CIVISIBILITY_ITR_ENABLED:
505505
type: Boolean
506506
default: False
507507
description: |
508-
Prevents the Intelligent Test Runner from skipping tests, and disables configuring the ``CIVisibility`` service
509-
to generate and upload git packfiles in support of the Intelligent Test Runner.
508+
Configures the ``CIVisibility`` service to generate and upload git packfiles in support
509+
of the Datadog Intelligent Test Runner. This configuration has no effect if ``DD_CIVISIBILITY_AGENTLESS_ENABLED`` is false.
510510
version_added:
511-
v1.18.0:
511+
v1.13.0:
512512

513513
DD_APPSEC_AUTOMATED_USER_EVENTS_TRACKING:
514514
type: String
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
CI Visibility: revert to using DD_CIVISIBILITY_ITR_ENABLED (instead of _DISABLED) to conform with other tracers.

0 commit comments

Comments
 (0)