diff --git a/octopus_deploy/datadog_checks/octopus_deploy/check.py b/octopus_deploy/datadog_checks/octopus_deploy/check.py index 11793584df2d3..2cbafef695c6e 100644 --- a/octopus_deploy/datadog_checks/octopus_deploy/check.py +++ b/octopus_deploy/datadog_checks/octopus_deploy/check.py @@ -144,11 +144,14 @@ def _process_spaces(self): self.log.debug("Spaces: %s", spaces) for _, _, space, space_config in spaces: space_id = space.get("Id") - tags = self._base_tags + [f'space_id:{space_id}', f'space_name:{space.get("Name")}'] + space_name = space.get("Name") + tags = self._base_tags + [f'space_id:{space_id}', f'space_name:{space_name}'] self.gauge("space.count", 1, tags=tags) - self._process_project_groups(space_id, space_config.get("project_groups") if space_config else None) + self._process_project_groups( + space_id, space_name, space_config.get("project_groups") if space_config else None + ) - def _process_project_groups(self, space_id, project_groups_config): + def _process_project_groups(self, space_id, space_name, project_groups_config): if project_groups_config: self._init_project_groups_discovery(space_id, ProjectGroups(**project_groups_config)) project_groups = list(self._project_groups_discovery[space_id].get_items()) @@ -166,19 +169,20 @@ def _process_project_groups(self, space_id, project_groups_config): project_group_id = project_group.get("Id") project_group_name = project_group.get("Name") tags = self._base_tags + [ - f'space_id:{space_id}', + f'space_name:{space_name}', f'project_group_id:{project_group_id}', f'project_group_name:{project_group_name}', ] self.gauge("project_group.count", 1, tags=tags) self._process_projects( space_id, + space_name, project_group_id, project_group_name, project_group_config.get("projects") if project_group_config else None, ) - def _process_projects(self, space_id, project_group_id, project_group_name, projects_config): + def _process_projects(self, space_id, space_name, project_group_id, project_group_name, projects_config): if projects_config: self._init_projects_discovery(space_id, project_group_id, Projects(**projects_config)) projects = list(self._projects_discovery[space_id][project_group_id].get_items()) @@ -198,28 +202,28 @@ def _process_projects(self, space_id, project_group_id, project_group_name, proj project_id = project.get("Id") project_name = project.get("Name") tags = self._base_tags + [ - f'space_id:{space_id}', + f'space_name:{space_name}', f'project_group_name:{project_group_name}', f'project_id:{project_id}', f'project_name:{project_name}', ] self.gauge("project.count", 1, tags=tags) - self._process_queued_and_running_tasks(space_id, project_id, project_name) - self._process_completed_tasks(space_id, project_id, project_name) + self._process_queued_and_running_tasks(space_id, space_name, project_id, project_name) + self._process_completed_tasks(space_id, space_name, project_id, project_name) - def _process_queued_and_running_tasks(self, space_id, project_id, project_name): + def _process_queued_and_running_tasks(self, space_id, space_name, project_id, project_name): params = {'project': project_id, 'states': ["Queued", "Executing"]} response_json = self._process_endpoint(f"api/{space_id}/tasks", params) - self._process_tasks(space_id, project_name, response_json.get('Items', [])) + self._process_tasks(space_id, space_name, project_name, response_json.get('Items', [])) - def _process_completed_tasks(self, space_id, project_id, project_name): + def _process_completed_tasks(self, space_id, space_name, project_id, project_name): params = { 'project': project_id, 'fromCompletedDate': self._from_completed_time, 'toCompletedDate': self._to_completed_time, } response_json = self._process_endpoint(f"api/{space_id}/tasks", params) - self._process_tasks(space_id, project_name, response_json.get('Items', [])) + self._process_tasks(space_id, space_name, project_name, response_json.get('Items', [])) def _calculate_task_times(self, task): task_queue_time = task.get("QueueTime") @@ -248,10 +252,10 @@ def _calculate_task_times(self, task): completed_time = -1 return queued_time, executing_time, completed_time - def _process_tasks(self, space_id, project_name, tasks_json): + def _process_tasks(self, space_id, space_name, project_name, tasks_json): for task in tasks_json: tags = self._base_tags + [ - f'space_id:{space_id}', + f'space_name:{space_name}', f'project_name:{project_name}', f'task_id:{task.get("Id")}', f'task_name:{task.get("Name")}', diff --git a/octopus_deploy/tests/test_unit.py b/octopus_deploy/tests/test_unit.py index 622973b72b68d..272bf0888cd64 100644 --- a/octopus_deploy/tests/test_unit.py +++ b/octopus_deploy/tests/test_unit.py @@ -130,17 +130,17 @@ def test_project_groups(get_current_datetime, dd_run_check, aggregator): aggregator.assert_metric( 'octopus_deploy.project_group.count', 1, - tags=['project_group_id:ProjectGroups-1', 'project_group_name:Default Project Group', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-1', 'project_group_name:Default Project Group', 'space_name:Default'], ) aggregator.assert_metric( 'octopus_deploy.project_group.count', 1, - tags=['project_group_id:ProjectGroups-2', 'project_group_name:test-group', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-2', 'project_group_name:test-group', 'space_name:Default'], ) aggregator.assert_metric( 'octopus_deploy.project_group.count', 1, - tags=['project_group_id:ProjectGroups-3', 'project_group_name:hello', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-3', 'project_group_name:hello', 'space_name:Default'], ) @@ -160,7 +160,7 @@ def test_projects(get_current_datetime, dd_run_check, aggregator): 'project_id:Projects-1', 'project_name:test-api', 'project_group_name:Default Project Group', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -170,7 +170,7 @@ def test_projects(get_current_datetime, dd_run_check, aggregator): 'project_id:Projects-2', 'project_name:my-project', 'project_group_name:Default Project Group', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -180,13 +180,13 @@ def test_projects(get_current_datetime, dd_run_check, aggregator): 'project_id:Projects-3', 'project_name:test', 'project_group_name:Default Project Group', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( 'octopus_deploy.project.count', 1, - tags=['project_id:Projects-4', 'project_name:hi', 'project_group_name:test-group', 'space_id:Spaces-1'], + tags=['project_id:Projects-4', 'project_name:hi', 'project_group_name:test-group', 'space_name:Default'], ) @@ -207,7 +207,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_name:Deploy', 'task_state:Executing', 'project_name:my-project', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -218,7 +218,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_name:Deploy', 'task_state:Executing', 'project_name:my-project', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -229,7 +229,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_name:Deploy', 'task_state:Executing', 'project_name:my-project', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -241,7 +241,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_name:Deploy', 'task_state:Executing', 'project_name:my-project', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -252,7 +252,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_name:Deploy', 'task_state:Queued', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -263,7 +263,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_name:Deploy', 'task_state:Queued', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -275,7 +275,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_name:Deploy', 'task_state:Queued', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -287,7 +287,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_name:Deploy', 'task_state:Queued', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) @@ -316,7 +316,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Failed', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -327,7 +327,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Failed', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -338,7 +338,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Failed', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -349,7 +349,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Failed', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -360,7 +360,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Success', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -371,7 +371,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Success', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -382,7 +382,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Success', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -393,7 +393,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Success', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -403,7 +403,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Success', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -414,7 +414,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Success', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -425,7 +425,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Success', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -436,7 +436,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_name:Deploy', 'task_state:Success', 'project_name:test', - 'space_id:Spaces-1', + 'space_name:Default', ], ) @@ -482,7 +482,7 @@ def test_discovery_spaces(get_current_datetime, dd_run_check, aggregator): get_current_datetime.return_value = MOCKED_TIME1 dd_run_check(check) - aggregator.assert_metric('octopus_deploy.space.count', tags=['space_id:Spaces-1', 'space_name:First'], count=0) + aggregator.assert_metric('octopus_deploy.space.count', tags=['space_name:Default', 'space_name:First'], count=0) aggregator.assert_metric('octopus_deploy.space.count', tags=['space_id:Spaces-2', 'space_name:Second']) @@ -502,18 +502,18 @@ def test_discovery_default_project_groups(get_current_datetime, dd_run_check, ag aggregator.assert_metric( 'octopus_deploy.project_group.count', - tags=['project_group_id:ProjectGroups-1', 'project_group_name:Default Project Group', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-1', 'project_group_name:Default Project Group', 'space_name:Default'], count=0, ) aggregator.assert_metric( 'octopus_deploy.project_group.count', - tags=['project_group_id:ProjectGroups-2', 'project_group_name:test-group', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-2', 'project_group_name:test-group', 'space_name:Default'], count=0, ) aggregator.assert_metric( 'octopus_deploy.project_group.count', 1, - tags=['project_group_id:ProjectGroups-3', 'project_group_name:hello', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-3', 'project_group_name:hello', 'space_name:Default'], ) @@ -541,18 +541,18 @@ def test_discovery_space_project_groups(get_current_datetime, dd_run_check, aggr aggregator.assert_metric( 'octopus_deploy.project_group.count', - tags=['project_group_id:ProjectGroups-1', 'project_group_name:Default Project Group', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-1', 'project_group_name:Default Project Group', 'space_name:Default'], count=0, ) aggregator.assert_metric( 'octopus_deploy.project_group.count', - tags=['project_group_id:ProjectGroups-2', 'project_group_name:test-group', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-2', 'project_group_name:test-group', 'space_name:Default'], count=0, ) aggregator.assert_metric( 'octopus_deploy.project_group.count', 1, - tags=['project_group_id:ProjectGroups-3', 'project_group_name:hello', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-3', 'project_group_name:hello', 'space_name:Default'], ) @@ -577,7 +577,7 @@ def test_discovery_default_projects(get_current_datetime, dd_run_check, aggregat 'project_id:Projects-1', 'project_name:test-api', 'project_group_name:Default Project Group', - 'space_id:Spaces-1', + 'space_name:Default', ], ) aggregator.assert_metric( @@ -586,7 +586,7 @@ def test_discovery_default_projects(get_current_datetime, dd_run_check, aggregat 'project_id:Projects-2', 'project_name:my-project', 'project_group_name:Default Project Group', - 'space_id:Spaces-1', + 'space_name:Default', ], count=0, ) @@ -596,13 +596,13 @@ def test_discovery_default_projects(get_current_datetime, dd_run_check, aggregat 'project_name:test', 'project_name:test', 'project_group_name:Default Project Group', - 'space_id:Spaces-1', + 'space_name:Default', ], count=0, ) aggregator.assert_metric( 'octopus_deploy.project.count', - tags=['project_id:Projects-4', 'project_name:hi', 'project_group_name:test-group', 'space_id:Spaces-1'], + tags=['project_id:Projects-4', 'project_name:hi', 'project_group_name:test-group', 'space_name:Default'], count=0, ) @@ -639,18 +639,18 @@ def test_discovery_space_project_group_projects(get_current_datetime, dd_run_che aggregator.assert_metric( 'octopus_deploy.project_group.count', - tags=['project_group_id:ProjectGroups-1', 'project_group_name:Default Project Group', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-1', 'project_group_name:Default Project Group', 'space_name:Default'], count=0, ) aggregator.assert_metric( 'octopus_deploy.project_group.count', - tags=['project_group_id:ProjectGroups-2', 'project_group_name:test-group', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-2', 'project_group_name:test-group', 'space_name:Default'], count=0, ) aggregator.assert_metric( 'octopus_deploy.project_group.count', 1, - tags=['project_group_id:ProjectGroups-3', 'project_group_name:hello', 'space_id:Spaces-1'], + tags=['project_group_id:ProjectGroups-3', 'project_group_name:hello', 'space_name:Default'], )