From 5d192c9f78e1ed90edf3cf15acea971f3e74cf8a Mon Sep 17 00:00:00 2001 From: Sarah Witt Date: Thu, 19 Dec 2024 16:47:39 -0500 Subject: [PATCH] Add support for waiting, queued, executing metrics --- .../datadog_checks/octopus_deploy/check.py | 7 ++ octopus_deploy/metadata.csv | 3 + octopus_deploy/tests/constants.py | 3 + .../states=Queued,Executing/response.json | 2 +- octopus_deploy/tests/test_unit.py | 78 +++++++++++++++++++ 5 files changed, 92 insertions(+), 1 deletion(-) diff --git a/octopus_deploy/datadog_checks/octopus_deploy/check.py b/octopus_deploy/datadog_checks/octopus_deploy/check.py index b42b5f92c2e1c..9e5d192961f57 100644 --- a/octopus_deploy/datadog_checks/octopus_deploy/check.py +++ b/octopus_deploy/datadog_checks/octopus_deploy/check.py @@ -277,6 +277,10 @@ def _process_tasks(self, space_id, space_name, project_name, tasks_json): task_name = task.get("Name") server_node = task.get("ServerNode") task_state = task.get("State") + pending_interruptions = task.get("HasPendingInterruptions") + is_queued = task_state == "Queued" + is_executing = task_state == "Executing" + tags = self._base_tags + [ f'space_name:{space_name}', f'project_name:{project_name}', @@ -288,6 +292,9 @@ def _process_tasks(self, space_id, space_name, project_name, tasks_json): self.log.debug("Processing task id %s for project %s", task_id, project_name) queued_time, executing_time, completed_time = self._calculate_task_times(task) self.gauge("deployment.count", 1, tags=tags) + self.gauge("deployment.waiting", pending_interruptions, tags=tags) + self.gauge("deployment.queued", is_queued, tags=tags) + self.gauge("deployment.executing", is_executing, tags=tags) self.gauge("deployment.queued_time", queued_time, tags=tags) if executing_time != -1: self.gauge("deployment.executing_time", executing_time, tags=tags) diff --git a/octopus_deploy/metadata.csv b/octopus_deploy/metadata.csv index a41002aa00758..4c03645b13601 100644 --- a/octopus_deploy/metadata.csv +++ b/octopus_deploy/metadata.csv @@ -2,8 +2,11 @@ metric_name,metric_type,interval,unit_name,per_unit_name,description,orientation octopus_deploy.api.can_connect,gauge,,,,Whether or not the check can connect to the Octopus Deploy API.,-1,octopus_deploy,octopus_deploy api,, octopus_deploy.deployment.completed_time,gauge,,second,,Duration of deployment.,-1,octopus_deploy,octopus_deploy deploy dur,, octopus_deploy.deployment.count,gauge,,,,Number of deployments monitored.,-1,octopus_deploy,octopus_deploy deploy count,, +octopus_deploy.deployment.executing,gauge,,second,,Whether or not the deployment is currently executing.,-1,octopus_deploy,octopus_deploy deploy executing,, octopus_deploy.deployment.executing_time,gauge,,second,,How long the deployment has been executing.,-1,octopus_deploy,octopus_deploy deploy dur,, +octopus_deploy.deployment.queued,gauge,,second,,Whether or not the deployment is currently in the queue.,-1,octopus_deploy,octopus_deploy deploy queue,, octopus_deploy.deployment.queued_time,gauge,,second,,Time deployment was in queue.,-1,octopus_deploy,octopus_deploy deploy queue,, +octopus_deploy.deployment.waiting,gauge,,second,,Whether or not the deployment is in a waiting state.,-1,octopus_deploy,octopus_deploy deploy waiting,, octopus_deploy.project.count,gauge,,,,Number of projects discovered.,-1,octopus_deploy,octopus_deploy projects count,, octopus_deploy.project_group.count,gauge,,,,Number of project groups discovered.,-1,octopus_deploy,octopus_deploy project group count,, octopus_deploy.server_node.count,gauge,,,,Number of Octopus server nodes discovered.,-1,octopus_deploy,octopus_deploy server count,, diff --git a/octopus_deploy/tests/constants.py b/octopus_deploy/tests/constants.py index 2dce9ef9aa1f7..b064bf7ddf24c 100644 --- a/octopus_deploy/tests/constants.py +++ b/octopus_deploy/tests/constants.py @@ -28,6 +28,9 @@ "octopus_deploy.project_group.count", "octopus_deploy.project.count", "octopus_deploy.deployment.count", + "octopus_deploy.deployment.executing", + "octopus_deploy.deployment.queued", + "octopus_deploy.deployment.waiting", "octopus_deploy.deployment.queued_time", "octopus_deploy.deployment.executing_time", "octopus_deploy.server_node.count", diff --git a/octopus_deploy/tests/fixtures/GET/api/Spaces-1/tasks/project=Projects-2/states=Queued,Executing/response.json b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/tasks/project=Projects-2/states=Queued,Executing/response.json index 49bdeab0175bb..b4dabf494edc6 100644 --- a/octopus_deploy/tests/fixtures/GET/api/Spaces-1/tasks/project=Projects-2/states=Queued,Executing/response.json +++ b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/tasks/project=Projects-2/states=Queued,Executing/response.json @@ -47,7 +47,7 @@ "HasBeenPickedUpByProcessor": true, "IsCompleted": false, "FinishedSuccessfully": false, - "HasPendingInterruptions": false, + "HasPendingInterruptions": true, "CanRerun": false, "HasWarningsOrErrors": false, "UnmetPreconditions": null, diff --git a/octopus_deploy/tests/test_unit.py b/octopus_deploy/tests/test_unit.py index a70085d54c802..f7a56fef68753 100644 --- a/octopus_deploy/tests/test_unit.py +++ b/octopus_deploy/tests/test_unit.py @@ -245,6 +245,45 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'server_node:OctopusServerNodes-50c3dfbarc82', ], ) + aggregator.assert_metric( + 'octopus_deploy.deployment.executing', + 1, + count=1, + tags=[ + 'task_id:ServerTasks-118048', + 'task_name:Deploy', + 'task_state:Executing', + 'project_name:my-project', + 'space_name:Default', + 'server_node:OctopusServerNodes-50c3dfbarc82', + ], + ) + aggregator.assert_metric( + 'octopus_deploy.deployment.queued', + 0, + count=1, + tags=[ + 'task_id:ServerTasks-118048', + 'task_name:Deploy', + 'task_state:Executing', + 'project_name:my-project', + 'space_name:Default', + 'server_node:OctopusServerNodes-50c3dfbarc82', + ], + ) + aggregator.assert_metric( + 'octopus_deploy.deployment.waiting', + 1, + count=1, + tags=[ + 'task_id:ServerTasks-118048', + 'task_name:Deploy', + 'task_state:Executing', + 'project_name:my-project', + 'space_name:Default', + 'server_node:OctopusServerNodes-50c3dfbarc82', + ], + ) aggregator.assert_metric( 'octopus_deploy.deployment.count', 1, @@ -295,6 +334,45 @@ def test_queued_or_running_tasks(get_current_datetime, dd_run_check, aggregator) 'server_node:None', ], ) + aggregator.assert_metric( + 'octopus_deploy.deployment.executing', + 0, + count=1, + tags=[ + 'task_id:ServerTasks-118055', + 'task_name:Deploy', + 'task_state:Queued', + 'project_name:test', + 'space_name:Default', + 'server_node:None', + ], + ) + aggregator.assert_metric( + 'octopus_deploy.deployment.queued', + 1, + count=1, + tags=[ + 'task_id:ServerTasks-118055', + 'task_name:Deploy', + 'task_state:Queued', + 'project_name:test', + 'space_name:Default', + 'server_node:None', + ], + ) + aggregator.assert_metric( + 'octopus_deploy.deployment.waiting', + 0, + count=1, + tags=[ + 'task_id:ServerTasks-118055', + 'task_name:Deploy', + 'task_state:Queued', + 'project_name:test', + 'space_name:Default', + 'server_node:None', + ], + ) @pytest.mark.usefixtures('mock_http_get')