Skip to content

Commit

Permalink
Add support for waiting, queued, executing metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-witt committed Dec 19, 2024
1 parent 197843e commit 5d192c9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
7 changes: 7 additions & 0 deletions octopus_deploy/datadog_checks/octopus_deploy/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions octopus_deploy/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,,
Expand Down
3 changes: 3 additions & 0 deletions octopus_deploy/tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"HasBeenPickedUpByProcessor": true,
"IsCompleted": false,
"FinishedSuccessfully": false,
"HasPendingInterruptions": false,
"HasPendingInterruptions": true,
"CanRerun": false,
"HasWarningsOrErrors": false,
"UnmetPreconditions": null,
Expand Down
78 changes: 78 additions & 0 deletions octopus_deploy/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 5d192c9

Please sign in to comment.