From cdcce289d2fc5c80449cae16cb6e7554a3120b13 Mon Sep 17 00:00:00 2001 From: Federico Mon Date: Tue, 16 May 2023 18:21:03 +0200 Subject: [PATCH 1/2] fix(ci-app): remove extra requests performed if env var not set --- ddtrace/internal/ci_visibility/recorder.py | 5 +++++ .../fix-ci-app-api-call-12f848d25f93d02d.yaml | 4 ++++ tests/ci_visibility/test_ci_visibility.py | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml diff --git a/ddtrace/internal/ci_visibility/recorder.py b/ddtrace/internal/ci_visibility/recorder.py index 10c20ccf2c7..4f050cb4df1 100644 --- a/ddtrace/internal/ci_visibility/recorder.py +++ b/ddtrace/internal/ci_visibility/recorder.py @@ -112,6 +112,11 @@ def _check_enabled_features(self): # type: () -> Tuple[bool, bool] if not self._app_key: return False, False + + # DEV: Remove this ``if`` once ITR is in GA + if not ddconfig._ci_visibility_intelligent_testrunner_enabled: + return False, False + url = "https://api.%s/api/v2/libraries/tests/services/setting" % self._dd_site _headers = {"dd-api-key": self._api_key, "dd-application-key": self._app_key} payload = { diff --git a/releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml b/releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml new file mode 100644 index 00000000000..da94dab8c7b --- /dev/null +++ b/releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + CI App: This fix resolves an issue where the tracer was doing extra requests if the ``DD_CIVISIBILITY_ITR_ENABLED`` env var was not set. diff --git a/tests/ci_visibility/test_ci_visibility.py b/tests/ci_visibility/test_ci_visibility.py index 77454bb1dbb..8ecf55fda4a 100644 --- a/tests/ci_visibility/test_ci_visibility.py +++ b/tests/ci_visibility/test_ci_visibility.py @@ -72,8 +72,24 @@ def test_ci_visibility_service_enable(): @mock.patch("ddtrace.internal.ci_visibility.recorder._do_request") -def test_ci_visibility_service_enable_with_app_key(_do_request): +def test_ci_visibility_service_enable_with_app_key_and_itr_disabled(_do_request): with override_env(dict(DD_API_KEY="foobar.baz", DD_APP_KEY="foobar")): + _do_request.return_value = Response( + status=200, + body='{"data":{"id":"1234","type":"ci_app_tracers_test_service_settings","attributes":' + '{"code_coverage":true,"tests_skipping":true}}}', + ) + CIVisibility.enable(service="test-service") + assert CIVisibility._instance._code_coverage_enabled_by_api is False + assert CIVisibility._instance._test_skipping_enabled_by_api is False + CIVisibility.disable() + + +@mock.patch("ddtrace.internal.ci_visibility.recorder._do_request") +def test_ci_visibility_service_enable_with_app_key_and_itr_enabled(_do_request): + + with override_env(dict(DD_API_KEY="foobar.baz", DD_APP_KEY="foobar", DD_CIVISIBILITY_ITR_ENABLED="1")): + ddtrace.internal.ci_visibility.recorder.ddconfig = ddtrace.settings.Config() _do_request.return_value = Response( status=200, body='{"data":{"id":"1234","type":"ci_app_tracers_test_service_settings","attributes":' From 60a8141babb3ac2079746e167e96fdff1e44b2c9 Mon Sep 17 00:00:00 2001 From: Federico Mon Date: Tue, 16 May 2023 18:49:56 +0200 Subject: [PATCH 2/2] Update releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml Co-authored-by: Yun Kim <35776586+Yun-Kim@users.noreply.github.com> --- releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml b/releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml index da94dab8c7b..0f8c77244ef 100644 --- a/releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml +++ b/releasenotes/notes/fix-ci-app-api-call-12f848d25f93d02d.yaml @@ -1,4 +1,4 @@ --- fixes: - | - CI App: This fix resolves an issue where the tracer was doing extra requests if the ``DD_CIVISIBILITY_ITR_ENABLED`` env var was not set. + 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.