From ce97ca1813700e2798c562dde59a3c6ff2e0b3c3 Mon Sep 17 00:00:00 2001 From: dkirov-dd <166512750+dkirov-dd@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:07:24 +0200 Subject: [PATCH] [AGENT-11701] Fix handling of deleted build config (#18122) * Fix handling of deleted build config * Add debug log * Run lint * Add changelog * Update teamcity/changelog.d/18122.fixed Co-authored-by: Kyle Neale --------- Co-authored-by: Kyle Neale --- teamcity/changelog.d/18122.fixed | 1 + teamcity/datadog_checks/teamcity/teamcity_rest.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 teamcity/changelog.d/18122.fixed diff --git a/teamcity/changelog.d/18122.fixed b/teamcity/changelog.d/18122.fixed new file mode 100644 index 0000000000000..f5deff79d3b84 --- /dev/null +++ b/teamcity/changelog.d/18122.fixed @@ -0,0 +1 @@ +Fix handling of deleted build config diff --git a/teamcity/datadog_checks/teamcity/teamcity_rest.py b/teamcity/datadog_checks/teamcity/teamcity_rest.py index 9f7b727a6b230..83ddff680332f 100644 --- a/teamcity/datadog_checks/teamcity/teamcity_rest.py +++ b/teamcity/datadog_checks/teamcity/teamcity_rest.py @@ -3,6 +3,7 @@ # Licensed under a 3-clause BSD style license (see LICENSE) from copy import deepcopy +from requests.exceptions import HTTPError from six import PY2 from datadog_checks.base import AgentCheck, ConfigurationError, is_affirmative @@ -244,13 +245,20 @@ def _collect_new_builds(self, project_id): self.log.debug( 'No builds for project %d and build config %d, checking again', project_id, self.current_build_config ) - ressource = "last_build" + resource = "last_build" options = {"project_id": project_id} else: self.log.debug('Checking for new builds...') - ressource = "new_builds" + resource = "new_builds" options = {"since_build": last_build_id} - return get_response(self, ressource, build_conf=self.current_build_config, **options) + try: + new_builds = get_response(self, resource, build_conf=self.current_build_config, **options) + except HTTPError: + # In the case where a build config has been deleted, no new builds should be returned and it will be removed + # from the list of all build configs in the next re-initialization + self.log.debug('Failed to retrieve new builds for build config %s', self.current_build_config) + new_builds = {} + return new_builds def _get_build_config_type(self, build_config): if self.is_deployment: