From 5a568ed9022db01e2da553b3c6a1267badd5f223 Mon Sep 17 00:00:00 2001 From: dkirov-dd <166512750+dkirov-dd@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:00:30 +0200 Subject: [PATCH] [AGENT-11701] Fix TeamCity Integration (#18041) * Handle project without builds * Add changelog * Refactor code * Add comment * Fix * Update teamcity/changelog.d/18041.fixed Co-authored-by: Ilia Kurenkov --------- Co-authored-by: Ilia Kurenkov --- teamcity/changelog.d/18041.fixed | 1 + teamcity/datadog_checks/teamcity/teamcity_rest.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 teamcity/changelog.d/18041.fixed diff --git a/teamcity/changelog.d/18041.fixed b/teamcity/changelog.d/18041.fixed new file mode 100644 index 0000000000000..3b855bf6230ee --- /dev/null +++ b/teamcity/changelog.d/18041.fixed @@ -0,0 +1 @@ +Fix handling of projects with no builds. We used to refresh all the projects whenever we encountered a build config that didn't have any builds associated with it. Now we refresh only the specific build config that's lacking builds. diff --git a/teamcity/datadog_checks/teamcity/teamcity_rest.py b/teamcity/datadog_checks/teamcity/teamcity_rest.py index e907a68ee4218..9f7b727a6b230 100644 --- a/teamcity/datadog_checks/teamcity/teamcity_rest.py +++ b/teamcity/datadog_checks/teamcity/teamcity_rest.py @@ -240,13 +240,17 @@ def _collect_build_problems(self, new_build): def _collect_new_builds(self, project_id): last_build_id = self.bc_store.get_last_build_id(project_id, self.current_build_config) if not last_build_id: - self._initialize() + # We want to handle the case of an unbuilt build config by checking for any last builds + self.log.debug( + 'No builds for project %d and build config %d, checking again', project_id, self.current_build_config + ) + ressource = "last_build" + options = {"project_id": project_id} else: self.log.debug('Checking for new builds...') - new_builds = get_response( - self, 'new_builds', build_conf=self.current_build_config, since_build=last_build_id - ) - return new_builds + ressource = "new_builds" + options = {"since_build": last_build_id} + return get_response(self, ressource, build_conf=self.current_build_config, **options) def _get_build_config_type(self, build_config): if self.is_deployment: