Skip to content

Commit

Permalink
Use space name instead of space id
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-witt committed Nov 21, 2024
1 parent 10ad093 commit fa99e9d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 55 deletions.
32 changes: 18 additions & 14 deletions octopus_deploy/datadog_checks/octopus_deploy/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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")
Expand Down Expand Up @@ -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")}',
Expand Down
Loading

0 comments on commit fa99e9d

Please sign in to comment.