Skip to content

Commit e93a6e0

Browse files
authored
fix(ci-visibility): remove extra requests performed if env var not set [backport #5872 to 1.13] (#5881)
Backport of #5872 to 1.13 CI App: Remove extra requests performed if ``DD_CIVISIBILITY_ITR_ENABLED`` env var not set or False. ## 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/contributing.html#Release-Note-Guidelines) are followed. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] OPTIONAL: PR description includes explicit acknowledgement of the performance implications of the change as reported in the benchmarks PR comment. ## 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.
1 parent df4f405 commit e93a6e0

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

ddtrace/internal/ci_visibility/recorder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def _check_enabled_features(self):
103103
# type: () -> Tuple[bool, bool]
104104
if not self._app_key:
105105
return False, False
106+
107+
# DEV: Remove this ``if`` once ITR is in GA
108+
if not ddconfig._ci_visibility_intelligent_testrunner_enabled:
109+
return False, False
110+
106111
url = "https://api.%s/api/v2/libraries/tests/services/setting" % self._dd_site
107112
_headers = {"dd-api-key": self._api_key, "dd-application-key": self._app_key}
108113
payload = {

ddtrace/settings/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ def __init__(self):
289289

290290
self._ci_visibility_agentless_enabled = asbool(os.getenv("DD_CIVISIBILITY_AGENTLESS_ENABLED", default=False))
291291
self._ci_visibility_agentless_url = os.getenv("DD_CIVISIBILITY_AGENTLESS_URL", default="")
292+
self._ci_visibility_intelligent_testrunner_enabled = asbool(
293+
os.getenv("DD_CIVISIBILITY_ITR_ENABLED", default=False)
294+
)
292295

293296
def __getattr__(self, name):
294297
if name not in self._config:
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: This fix resolves an issue where the tracer was doing extra requests if the ``DD_CIVISIBILITY_ITR_ENABLED`` env var was not set.

tests/ci_visibility/test_ci_visibility.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,24 @@ def test_ci_visibility_service_enable():
5555

5656

5757
@mock.patch("ddtrace.internal.ci_visibility.recorder._do_request")
58-
def test_ci_visibility_service_enable_with_app_key(_do_request):
58+
def test_ci_visibility_service_enable_with_app_key_and_itr_disabled(_do_request):
5959
with override_env(dict(DD_API_KEY="foobar.baz", DD_APP_KEY="foobar")):
60+
_do_request.return_value = Response(
61+
status=200,
62+
body='{"data":{"id":"1234","type":"ci_app_tracers_test_service_settings","attributes":'
63+
'{"code_coverage":true,"tests_skipping":true}}}',
64+
)
65+
CIVisibility.enable(service="test-service")
66+
assert CIVisibility._instance._code_coverage_enabled_by_api is False
67+
assert CIVisibility._instance._test_skipping_enabled_by_api is False
68+
CIVisibility.disable()
69+
70+
71+
@mock.patch("ddtrace.internal.ci_visibility.recorder._do_request")
72+
def test_ci_visibility_service_enable_with_app_key_and_itr_enabled(_do_request):
73+
74+
with override_env(dict(DD_API_KEY="foobar.baz", DD_APP_KEY="foobar", DD_CIVISIBILITY_ITR_ENABLED="1")):
75+
ddtrace.internal.ci_visibility.recorder.ddconfig = ddtrace.settings.Config()
6076
_do_request.return_value = Response(
6177
status=200,
6278
body='{"data":{"id":"1234","type":"ci_app_tracers_test_service_settings","attributes":'

0 commit comments

Comments
 (0)