Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLINT 593] Add waiting, queued, and executing metrics #19291

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions octopus_deploy/datadog_checks/octopus_deploy/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,11 @@ def _process_tasks(self, space_id, space_name, project_name, tasks_json):
self.log.debug("Discovered %s tasks for project %s", len(tasks_json), project_name)
for task in tasks_json:
task_id = task.get("Id")
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"
deployment_id = task.get("Arguments", {}).get("DeploymentId")
environment_name, deployment_tags = self._get_deployment_tags(space_id, deployment_id)
if environment_name in self._environments_cache.values():
Expand All @@ -371,15 +373,17 @@ 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)

if completed_time != -1:
self.gauge("deployment.completed_time", completed_time, tags=tags)

if self.logs_enabled:
self.log.debug("Collecting logs for task %s, id: %s", task_name, task_id)
self.log.debug("Collecting logs for task id: %s", task_id)
self._collect_deployment_logs(space_id, task_id, tags)
else:
self.log.debug(
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.environment.allow_dynamic_infrastructure,gauge,,,,Whether or not the environment allows dynamic infrastructure.,-1,octopus_deploy,octopus_deploy env infra,,
octopus_deploy.environment.count,gauge,,,,Number of environments discovered.,-1,octopus_deploy,octopus_deploy env count,,
octopus_deploy.environment.use_guided_failure,gauge,,,,Whether or not the environment is in guided failure mode.,-1,octopus_deploy,octopus_deploy env guided failure,,
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
84 changes: 84 additions & 0 deletions octopus_deploy/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,48 @@ 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=[
'deployment_id:Deployments-18',
'release_version:0.0.1',
'environment_name:staging',
'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=[
'deployment_id:Deployments-18',
'release_version:0.0.1',
'environment_name:staging',
'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=[
'deployment_id:Deployments-18',
'release_version:0.0.1',
'environment_name:staging',
'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 @@ -303,6 +345,48 @@ 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=[
'deployment_id:Deployments-19',
'release_version:0.0.2',
'environment_name:dev',
'task_state:Queued',
'project_name:test',
'space_name:Default',
'server_node:None',
],
)
aggregator.assert_metric(
'octopus_deploy.deployment.queued',
1,
count=1,
tags=[
'deployment_id:Deployments-19',
'release_version:0.0.2',
'environment_name:dev',
'task_state:Queued',
'project_name:test',
'space_name:Default',
'server_node:None',
],
)
aggregator.assert_metric(
'octopus_deploy.deployment.waiting',
0,
count=1,
tags=[
'deployment_id:Deployments-19',
'release_version:0.0.2',
'environment_name:dev',
'task_state:Queued',
'project_name:test',
'space_name:Default',
'server_node:None',
],
)


@pytest.mark.usefixtures('mock_http_get')
Expand Down
Loading