diff --git a/octopus_deploy/datadog_checks/octopus_deploy/check.py b/octopus_deploy/datadog_checks/octopus_deploy/check.py index eabf1f63f393e..11793584df2d3 100644 --- a/octopus_deploy/datadog_checks/octopus_deploy/check.py +++ b/octopus_deploy/datadog_checks/octopus_deploy/check.py @@ -164,17 +164,21 @@ def _process_project_groups(self, space_id, project_groups_config): self.log.debug("Project Groups: %s", project_groups) for _, _, project_group, project_group_config in project_groups: project_group_id = project_group.get("Id") + project_group_name = project_group.get("Name") tags = self._base_tags + [ f'space_id:{space_id}', f'project_group_id:{project_group_id}', - f'project_group_name:{project_group.get("Name")}', + f'project_group_name:{project_group_name}', ] self.gauge("project_group.count", 1, tags=tags) self._process_projects( - space_id, project_group_id, project_group_config.get("projects") if project_group_config else None + space_id, + 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, projects_config): + def _process_projects(self, space_id, 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()) @@ -192,29 +196,30 @@ def _process_projects(self, space_id, project_group_id, projects_config): self.log.debug("Projects: %s", projects) for _, _, project, _ in projects: project_id = project.get("Id") + project_name = project.get("Name") tags = self._base_tags + [ f'space_id:{space_id}', - f'project_group_id:{project_group_id}', + f'project_group_name:{project_group_name}', f'project_id:{project_id}', - f'project_name:{project.get("Name")}', + f'project_name:{project_name}', ] self.gauge("project.count", 1, tags=tags) - self._process_queued_and_running_tasks(space_id, project_id) - self._process_completed_tasks(space_id, project_id) + self._process_queued_and_running_tasks(space_id, project_id, project_name) + self._process_completed_tasks(space_id, project_id, project_name) - def _process_queued_and_running_tasks(self, space_id, project_id): + def _process_queued_and_running_tasks(self, space_id, 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_id, response_json.get('Items', [])) + self._process_tasks(space_id, project_name, response_json.get('Items', [])) - def _process_completed_tasks(self, space_id, project_id): + def _process_completed_tasks(self, space_id, 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_id, response_json.get('Items', [])) + self._process_tasks(space_id, project_name, response_json.get('Items', [])) def _calculate_task_times(self, task): task_queue_time = task.get("QueueTime") @@ -243,11 +248,11 @@ def _calculate_task_times(self, task): completed_time = -1 return queued_time, executing_time, completed_time - def _process_tasks(self, space_id, project_id, tasks_json): + def _process_tasks(self, space_id, project_name, tasks_json): for task in tasks_json: tags = self._base_tags + [ f'space_id:{space_id}', - f'project_id:{project_id}', + f'project_name:{project_name}', f'task_id:{task.get("Id")}', f'task_name:{task.get("Name")}', f'task_state:{task.get("State")}', diff --git a/octopus_deploy/tests/test_unit.py b/octopus_deploy/tests/test_unit.py index db723727e00d8..622973b72b68d 100644 --- a/octopus_deploy/tests/test_unit.py +++ b/octopus_deploy/tests/test_unit.py @@ -159,7 +159,7 @@ def test_projects(get_current_datetime, dd_run_check, aggregator): tags=[ 'project_id:Projects-1', 'project_name:test-api', - 'project_group_id:ProjectGroups-1', + 'project_group_name:Default Project Group', 'space_id:Spaces-1', ], ) @@ -169,19 +169,24 @@ def test_projects(get_current_datetime, dd_run_check, aggregator): tags=[ 'project_id:Projects-2', 'project_name:my-project', - 'project_group_id:ProjectGroups-1', + 'project_group_name:Default Project Group', 'space_id:Spaces-1', ], ) aggregator.assert_metric( 'octopus_deploy.project.count', 1, - tags=['project_id:Projects-3', 'project_name:test', 'project_group_id:ProjectGroups-1', 'space_id:Spaces-1'], + tags=[ + 'project_id:Projects-3', + 'project_name:test', + 'project_group_name:Default Project Group', + 'space_id:Spaces-1', + ], ) aggregator.assert_metric( 'octopus_deploy.project.count', 1, - tags=['project_id:Projects-4', 'project_name:hi', 'project_group_id:ProjectGroups-2', 'space_id:Spaces-1'], + tags=['project_id:Projects-4', 'project_name:hi', 'project_group_name:test-group', 'space_id:Spaces-1'], ) @@ -201,7 +206,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_id:ServerTasks-118048', 'task_name:Deploy', 'task_state:Executing', - 'project_id:Projects-2', + 'project_name:my-project', 'space_id:Spaces-1', ], ) @@ -212,7 +217,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_id:ServerTasks-118048', 'task_name:Deploy', 'task_state:Executing', - 'project_id:Projects-2', + 'project_name:my-project', 'space_id:Spaces-1', ], ) @@ -223,7 +228,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_id:ServerTasks-118048', 'task_name:Deploy', 'task_state:Executing', - 'project_id:Projects-2', + 'project_name:my-project', 'space_id:Spaces-1', ], ) @@ -235,7 +240,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_id:ServerTasks-118048', 'task_name:Deploy', 'task_state:Executing', - 'project_id:Projects-2', + 'project_name:my-project', 'space_id:Spaces-1', ], ) @@ -246,7 +251,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_id:ServerTasks-118055', 'task_name:Deploy', 'task_state:Queued', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -257,7 +262,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_id:ServerTasks-118055', 'task_name:Deploy', 'task_state:Queued', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -269,7 +274,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_id:ServerTasks-118055', 'task_name:Deploy', 'task_state:Queued', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -281,7 +286,7 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'task_id:ServerTasks-118055', 'task_name:Deploy', 'task_state:Queued', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -297,8 +302,8 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): dd_run_check(check) metrics = aggregator.metrics('octopus_deploy.deployment.count') for metric in metrics: - assert not ('project_id:Projects-1' in metric.tags and 'task_state:Success' in metric.tags) - assert not ('project_id:Projects-3' in metric.tags and 'task_state:Success' in metric.tags) + assert not ('project_name:test-api' in metric.tags and 'task_state:Success' in metric.tags) + assert not ('project_name:test' in metric.tags and 'task_state:Success' in metric.tags) get_current_datetime.return_value = MOCKED_TIME2 dd_run_check(check) @@ -310,7 +315,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1847', 'task_name:Deploy', 'task_state:Failed', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -321,7 +326,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1847', 'task_name:Deploy', 'task_state:Failed', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -332,7 +337,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1847', 'task_name:Deploy', 'task_state:Failed', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -343,7 +348,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1847', 'task_name:Deploy', 'task_state:Failed', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -354,7 +359,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1846', 'task_name:Deploy', 'task_state:Success', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -365,7 +370,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1846', 'task_name:Deploy', 'task_state:Success', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -376,7 +381,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1846', 'task_name:Deploy', 'task_state:Success', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -387,7 +392,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1846', 'task_name:Deploy', 'task_state:Success', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -397,7 +402,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1845', 'task_name:Deploy', 'task_state:Success', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -408,7 +413,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1845', 'task_name:Deploy', 'task_state:Success', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -419,7 +424,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1845', 'task_name:Deploy', 'task_state:Success', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -430,7 +435,7 @@ def test_completed_tasks(get_current_datetime, dd_run_check, aggregator): 'task_id:ServerTasks-1845', 'task_name:Deploy', 'task_state:Success', - 'project_id:Projects-3', + 'project_name:test', 'space_id:Spaces-1', ], ) @@ -571,7 +576,7 @@ def test_discovery_default_projects(get_current_datetime, dd_run_check, aggregat tags=[ 'project_id:Projects-1', 'project_name:test-api', - 'project_group_id:ProjectGroups-1', + 'project_group_name:Default Project Group', 'space_id:Spaces-1', ], ) @@ -580,19 +585,24 @@ def test_discovery_default_projects(get_current_datetime, dd_run_check, aggregat tags=[ 'project_id:Projects-2', 'project_name:my-project', - 'project_group_id:ProjectGroups-1', + 'project_group_name:Default Project Group', 'space_id:Spaces-1', ], count=0, ) aggregator.assert_metric( 'octopus_deploy.project.count', - tags=['project_id:Projects-3', 'project_name:test', 'project_group_id:ProjectGroups-1', 'space_id:Spaces-1'], + tags=[ + 'project_name:test', + 'project_name:test', + 'project_group_name:Default Project Group', + 'space_id:Spaces-1', + ], count=0, ) aggregator.assert_metric( 'octopus_deploy.project.count', - tags=['project_id:Projects-4', 'project_name:hi', 'project_group_id:ProjectGroups-2', 'space_id:Spaces-1'], + tags=['project_id:Projects-4', 'project_name:hi', 'project_group_name:test-group', 'space_id:Spaces-1'], count=0, )