From d662619825d10c9a57fb842ca8cdbf56f22f54e5 Mon Sep 17 00:00:00 2001 From: Sarah Witt Date: Wed, 18 Dec 2024 15:25:06 -0500 Subject: [PATCH 1/5] Add support for machine metrics --- .../datadog_checks/octopus_deploy/check.py | 22 ++++ octopus_deploy/metadata.csv | 2 + octopus_deploy/tests/constants.py | 2 + octopus_deploy/tests/docker/Caddyfile | 10 +- .../machines/skip=0/take=2/response.json | 68 ++++++++++++ .../machines/skip=0/take=30/response.json | 68 ++++++++++++ octopus_deploy/tests/test_unit.py | 104 ++++++++++++++++++ 7 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=2/response.json create mode 100644 octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=30/response.json diff --git a/octopus_deploy/datadog_checks/octopus_deploy/check.py b/octopus_deploy/datadog_checks/octopus_deploy/check.py index c71b36875a81a..67cb8d05a6bd4 100644 --- a/octopus_deploy/datadog_checks/octopus_deploy/check.py +++ b/octopus_deploy/datadog_checks/octopus_deploy/check.py @@ -188,6 +188,7 @@ def _process_spaces(self): self._process_project_groups( space_id, space_name, space_config.get("project_groups") if space_config else None ) + self._collect_machine_metrics(space_id) if self.collect_events: self._collect_new_events(space_id, space_name) @@ -341,6 +342,27 @@ def _collect_server_nodes_metrics(self): self.gauge("server_node.in_maintenance_mode", maintenance_mode, tags=self._base_tags + server_tags) self.gauge("server_node.max_concurrent_tasks", max_tasks, tags=self._base_tags + server_tags) + def _collect_machine_metrics(self, space_id): + self.log.debug("Collecting server node metrics.") + url = f"api/{space_id}/machines" + response_json = self._process_paginated_endpoint(url) + machines = response_json.get('Items', []) + + for machine in machines: + machine_id = machine.get("Id") + machine_name = machine.get("Name") + machine_slug = machine.get("Slug") + health_status = machine.get("HealthStatus", None) + is_healthy = health_status == "Healthy" + machine_tags = [ + f"machine_id:{machine_id}", + f"machine_name:{machine_name}", + f"machine_slug:{machine_slug}", + f"health_status:{health_status}", + ] + self.gauge("machine.count", 1, tags=self._base_tags + machine_tags) + self.gauge("machine.is_healthy", is_healthy, tags=self._base_tags + machine_tags) + def _collect_deployment_logs(self, space_id, task_id, tags): url = f"api/{space_id}/tasks/{task_id}/details" activity_logs = self._process_endpoint(url).get('ActivityLogs', []) diff --git a/octopus_deploy/metadata.csv b/octopus_deploy/metadata.csv index a41002aa00758..971d18eb5fe22 100644 --- a/octopus_deploy/metadata.csv +++ b/octopus_deploy/metadata.csv @@ -4,6 +4,8 @@ octopus_deploy.deployment.completed_time,gauge,,second,,Duration of deployment., octopus_deploy.deployment.count,gauge,,,,Number of deployments monitored.,-1,octopus_deploy,octopus_deploy deploy count,, 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_time,gauge,,second,,Time deployment was in queue.,-1,octopus_deploy,octopus_deploy deploy queue,, +octopus_deploy.machine.count,gauge,,,,Number of machines discovered.,-1,octopus_deploy,octopus_deploy machine count,, +octopus_deploy.machine.is_healthy,gauge,,,,Whether or not the machine is healthy.,-1,octopus_deploy,octopus_deploy machine health,, 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..ff3abf0ccb8ae 100644 --- a/octopus_deploy/tests/constants.py +++ b/octopus_deploy/tests/constants.py @@ -33,6 +33,8 @@ "octopus_deploy.server_node.count", "octopus_deploy.server_node.in_maintenance_mode", "octopus_deploy.server_node.max_concurrent_tasks", + "octopus_deploy.machine.count", + "octopus_deploy.machine.is_healthy", ] ALL_METRICS = ["octopus_deploy.deployment.completed_time"] + E2E_METRICS diff --git a/octopus_deploy/tests/docker/Caddyfile b/octopus_deploy/tests/docker/Caddyfile index b78c45e8b0422..16e67e6d27d4a 100644 --- a/octopus_deploy/tests/docker/Caddyfile +++ b/octopus_deploy/tests/docker/Caddyfile @@ -124,7 +124,15 @@ rewrite * /GET/api/octopusservernodes/skip=0/take=30/response.json file_server } - @get_tasks_1844 { + @get_machines { + method GET + path /api/Spaces-1/machines + } + route @get_machines { + rewrite * /GET/api/Spaces-1/machines/skip=0/take=30/response.json + file_server + } + @get_tasks_1844 { method GET path /api/Spaces-1/tasks/ServerTasks-1844/details } diff --git a/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=2/response.json b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=2/response.json new file mode 100644 index 0000000000000..93b4d1dfe10df --- /dev/null +++ b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=2/response.json @@ -0,0 +1,68 @@ +{ + "ItemType": "Machine", + "TotalResults": 1, + "ItemsPerPage": 2, + "NumberOfPages": 1, + "LastPageNumber": 0, + "Items": [ + { + "Id": "Machines-1", + "EnvironmentIds": [ + "Environments-1" + ], + "Roles": [ + "test-tag" + ], + "TenantedDeploymentParticipation": "Untenanted", + "TenantIds": [], + "TenantTags": [], + "SpaceId": "Spaces-1", + "Name": "test-machine", + "Thumbprint": "test-footprint", + "Uri": "hostname-test:10933/", + "IsDisabled": false, + "MachinePolicyId": "MachinePolicies-1", + "HealthStatus": "Healthy", + "HasLatestCalamari": false, + "StatusSummary": "Octopus was able to successfully establish a connection with this machine on Wednesday", + "IsInProcess": false, + "Endpoint": { + "CommunicationStyle": "TentaclePassive", + "ProxyId": null, + "Thumbprint": "test-footprint", + "Uri": "hostname-test:10933/", + "TentacleVersionDetails": { + "UpgradeLocked": false, + "Version": "8.2.2517", + "UpgradeSuggested": false, + "UpgradeRequired": false, + "UpgradeAvailable": false + }, + "CertificateSignatureAlgorithm": "sha256RSA", + "Id": null, + "LastModifiedOn": null, + "LastModifiedBy": null, + "Links": {} + }, + "OperatingSystem": "Ubuntu 24.04.1 LTS", + "ShellName": "Bash", + "ShellVersion": "5.2.21(1)-release", + "Architecture": "x86_64", + "Slug": "test-machine", + "SkipInitialHealthCheck": false, + "Links": { + "Self": "/api/Spaces-1/machines/Machines-1", + "Connection": "/api/Spaces-1/machines/Machines-1/connection", + "TasksTemplate": "/api/Spaces-1/machines/Machines-1/tasks{?skip,take,type}", + "SinglyScopedVariableDetails": "/api/Spaces-1/machines/Machines-1/singlyScopedVariableDetails" + } + } + ], + "Links": { + "Self": "/api/Spaces-1/machines?skip=0&take=30", + "Template": "/api/Spaces-1/machines{?skip,take,name,ids,partialName,roles,isDisabled,healthStatuses,commStyles,tenantIds,tenantTags,environmentIds,shellNames,deploymentTargetTypes}", + "Page.All": "/api/Spaces-1/machines?skip=0&take=2147483647", + "Page.Current": "/api/Spaces-1/machines?skip=0&take=30", + "Page.Last": "/api/Spaces-1/machines?skip=0&take=30" + } +} \ No newline at end of file diff --git a/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=30/response.json b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=30/response.json new file mode 100644 index 0000000000000..18b7818ffe166 --- /dev/null +++ b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=30/response.json @@ -0,0 +1,68 @@ +{ + "ItemType": "Machine", + "TotalResults": 1, + "ItemsPerPage": 30, + "NumberOfPages": 1, + "LastPageNumber": 0, + "Items": [ + { + "Id": "Machines-1", + "EnvironmentIds": [ + "Environments-1" + ], + "Roles": [ + "test-tag" + ], + "TenantedDeploymentParticipation": "Untenanted", + "TenantIds": [], + "TenantTags": [], + "SpaceId": "Spaces-1", + "Name": "test-machine", + "Thumbprint": "test-footprint", + "Uri": "hostname-test:10933/", + "IsDisabled": false, + "MachinePolicyId": "MachinePolicies-1", + "HealthStatus": "Healthy", + "HasLatestCalamari": false, + "StatusSummary": "Octopus was able to successfully establish a connection with this machine on Wednesday", + "IsInProcess": false, + "Endpoint": { + "CommunicationStyle": "TentaclePassive", + "ProxyId": null, + "Thumbprint": "test-footprint", + "Uri": "hostname-test:10933/", + "TentacleVersionDetails": { + "UpgradeLocked": false, + "Version": "8.2.2517", + "UpgradeSuggested": false, + "UpgradeRequired": false, + "UpgradeAvailable": false + }, + "CertificateSignatureAlgorithm": "sha256RSA", + "Id": null, + "LastModifiedOn": null, + "LastModifiedBy": null, + "Links": {} + }, + "OperatingSystem": "Ubuntu 24.04.1 LTS", + "ShellName": "Bash", + "ShellVersion": "5.2.21(1)-release", + "Architecture": "x86_64", + "Slug": "test-machine", + "SkipInitialHealthCheck": false, + "Links": { + "Self": "/api/Spaces-1/machines/Machines-1", + "Connection": "/api/Spaces-1/machines/Machines-1/connection", + "TasksTemplate": "/api/Spaces-1/machines/Machines-1/tasks{?skip,take,type}", + "SinglyScopedVariableDetails": "/api/Spaces-1/machines/Machines-1/singlyScopedVariableDetails" + } + } + ], + "Links": { + "Self": "/api/Spaces-1/machines?skip=0&take=30", + "Template": "/api/Spaces-1/machines{?skip,take,name,ids,partialName,roles,isDisabled,healthStatuses,commStyles,tenantIds,tenantTags,environmentIds,shellNames,deploymentTargetTypes}", + "Page.All": "/api/Spaces-1/machines?skip=0&take=2147483647", + "Page.Current": "/api/Spaces-1/machines?skip=0&take=30", + "Page.Last": "/api/Spaces-1/machines?skip=0&take=30" + } +} \ No newline at end of file diff --git a/octopus_deploy/tests/test_unit.py b/octopus_deploy/tests/test_unit.py index c1162953d1473..b2fbc15d2289a 100644 --- a/octopus_deploy/tests/test_unit.py +++ b/octopus_deploy/tests/test_unit.py @@ -1272,3 +1272,107 @@ def test_paginated_limit_tasks( skip_take_args += [(list(args), skip, take)] assert skip_take_args == expected_skip_take_args + + +@pytest.mark.usefixtures('mock_http_get') +@mock.patch("datadog_checks.octopus_deploy.check.get_current_datetime") +def test_machines_metrics( + get_current_datetime, + dd_run_check, + aggregator, +): + instance = {'octopus_endpoint': 'http://localhost:80'} + + check = OctopusDeployCheck('octopus_deploy', {}, [instance]) + + get_current_datetime.return_value = MOCKED_TIME1 + dd_run_check(check) + aggregator.assert_metric( + "octopus_deploy.machine.count", + 1, + tags=[ + "machine_id:Machines-1", + "machine_name:test-machine", + "machine_slug:test-machine", + "health_status:Healthy", + ], + ) + aggregator.assert_metric( + "octopus_deploy.machine.is_healthy", + 1, + tags=[ + "machine_id:Machines-1", + "machine_name:test-machine", + "machine_slug:test-machine", + "health_status:Healthy", + ], + ) + + +@pytest.mark.parametrize( + ('paginated_limit, expected_skip_take_args'), + [ + pytest.param( + 30, + [ + (['http://localhost:80/api/Spaces-1/machines'], 0, 30), + ], + id='high limit', + ), + pytest.param( + 2, + [ + (['http://localhost:80/api/Spaces-1/machines'], 0, 2), + ], + id='low limit', + ), + ], +) +@pytest.mark.usefixtures('mock_http_get') +@mock.patch("datadog_checks.octopus_deploy.check.get_current_datetime") +def test_machines_pagination( + get_current_datetime, + dd_run_check, + aggregator, + expected_skip_take_args, + mock_http_get, + paginated_limit, +): + instance = {'octopus_endpoint': 'http://localhost:80'} + instance['paginated_limit'] = paginated_limit + + check = OctopusDeployCheck('octopus_deploy', {}, [instance]) + + get_current_datetime.return_value = MOCKED_TIME1 + dd_run_check(check) + + skip_take_args = [] + for call in mock_http_get.call_args_list: + args, kwargs = call + take = kwargs.get('params', {}).get('take') + skip = kwargs.get('params', {}).get('skip') + if 'http://localhost:80/api/Spaces-1/machines' == args[0]: + skip_take_args += [(list(args), skip, take)] + + assert skip_take_args == expected_skip_take_args + + aggregator.assert_metric( + "octopus_deploy.machine.count", + 1, + tags=[ + "machine_id:Machines-1", + "machine_name:test-machine", + "machine_slug:test-machine", + "health_status:Healthy", + ], + ) + aggregator.assert_metric( + "octopus_deploy.machine.is_healthy", + 1, + tags=[ + "machine_id:Machines-1", + "machine_name:test-machine", + "machine_slug:test-machine", + "health_status:Healthy", + ], + ) From 9e4b6b5f84e782834f23e476ce5fd5f204102ae3 Mon Sep 17 00:00:00 2001 From: Sarah Witt Date: Wed, 18 Dec 2024 16:31:20 -0500 Subject: [PATCH 2/5] add role tags --- octopus_deploy/datadog_checks/octopus_deploy/check.py | 2 ++ octopus_deploy/tests/test_unit.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/octopus_deploy/datadog_checks/octopus_deploy/check.py b/octopus_deploy/datadog_checks/octopus_deploy/check.py index 67cb8d05a6bd4..0f822292dfa1f 100644 --- a/octopus_deploy/datadog_checks/octopus_deploy/check.py +++ b/octopus_deploy/datadog_checks/octopus_deploy/check.py @@ -352,6 +352,7 @@ def _collect_machine_metrics(self, space_id): machine_id = machine.get("Id") machine_name = machine.get("Name") machine_slug = machine.get("Slug") + roles = machine.get("Roles", []) health_status = machine.get("HealthStatus", None) is_healthy = health_status == "Healthy" machine_tags = [ @@ -360,6 +361,7 @@ def _collect_machine_metrics(self, space_id): f"machine_slug:{machine_slug}", f"health_status:{health_status}", ] + machine_tags += roles self.gauge("machine.count", 1, tags=self._base_tags + machine_tags) self.gauge("machine.is_healthy", is_healthy, tags=self._base_tags + machine_tags) diff --git a/octopus_deploy/tests/test_unit.py b/octopus_deploy/tests/test_unit.py index b2fbc15d2289a..fa691b5b5337a 100644 --- a/octopus_deploy/tests/test_unit.py +++ b/octopus_deploy/tests/test_unit.py @@ -1295,6 +1295,7 @@ def test_machines_metrics( "machine_name:test-machine", "machine_slug:test-machine", "health_status:Healthy", + "test-tag", ], ) aggregator.assert_metric( @@ -1305,6 +1306,7 @@ def test_machines_metrics( "machine_name:test-machine", "machine_slug:test-machine", "health_status:Healthy", + "test-tag", ], ) @@ -1364,6 +1366,7 @@ def test_machines_pagination( "machine_name:test-machine", "machine_slug:test-machine", "health_status:Healthy", + "test-tag", ], ) aggregator.assert_metric( @@ -1374,5 +1377,6 @@ def test_machines_pagination( "machine_name:test-machine", "machine_slug:test-machine", "health_status:Healthy", + "test-tag", ], ) From caae890551b44dccb5acb0e347e4fc962c8f52da Mon Sep 17 00:00:00 2001 From: Sarah Witt Date: Thu, 19 Dec 2024 14:54:33 -0500 Subject: [PATCH 3/5] change to startswith --- octopus_deploy/datadog_checks/octopus_deploy/check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octopus_deploy/datadog_checks/octopus_deploy/check.py b/octopus_deploy/datadog_checks/octopus_deploy/check.py index 0f822292dfa1f..805fcbc88dede 100644 --- a/octopus_deploy/datadog_checks/octopus_deploy/check.py +++ b/octopus_deploy/datadog_checks/octopus_deploy/check.py @@ -354,7 +354,7 @@ def _collect_machine_metrics(self, space_id): machine_slug = machine.get("Slug") roles = machine.get("Roles", []) health_status = machine.get("HealthStatus", None) - is_healthy = health_status == "Healthy" + is_healthy = health_status.startswith("Healthy") machine_tags = [ f"machine_id:{machine_id}", f"machine_name:{machine_name}", From cf47801c9a2e59bb22644e4874fe5fdc59b79ea5 Mon Sep 17 00:00:00 2001 From: Sarah Witt Date: Fri, 20 Dec 2024 10:06:54 -0500 Subject: [PATCH 4/5] validate metadata --- octopus_deploy/metadata.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octopus_deploy/metadata.csv b/octopus_deploy/metadata.csv index be124c204daad..904d80cddf278 100644 --- a/octopus_deploy/metadata.csv +++ b/octopus_deploy/metadata.csv @@ -4,11 +4,11 @@ octopus_deploy.deployment.completed_time,gauge,,second,,Duration of deployment., octopus_deploy.deployment.count,gauge,,,,Number of deployments monitored.,-1,octopus_deploy,octopus_deploy deploy count,, 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_time,gauge,,second,,Time deployment was in queue.,-1,octopus_deploy,octopus_deploy deploy queue,, -octopus_deploy.machine.count,gauge,,,,Number of machines discovered.,-1,octopus_deploy,octopus_deploy machine count,, -octopus_deploy.machine.is_healthy,gauge,,,,Whether or not the machine is healthy.,-1,octopus_deploy,octopus_deploy machine health,, 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,, +octopus_deploy.machine.count,gauge,,,,Number of machines discovered.,-1,octopus_deploy,octopus_deploy machine count,, +octopus_deploy.machine.is_healthy,gauge,,,,Whether or not the machine is healthy.,-1,octopus_deploy,octopus_deploy machine health,, 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,, From 69d8d131888c503d4e9ae7291878c5f113e4f035 Mon Sep 17 00:00:00 2001 From: Sarah Witt Date: Thu, 26 Dec 2024 10:51:55 -0500 Subject: [PATCH 5/5] Address comments --- .../datadog_checks/octopus_deploy/check.py | 4 +- .../machines/skip=0/take=2/response.json | 57 +++++++++- .../machines/skip=0/take=30/response.json | 105 +++++++++++++++++ .../machines/skip=2/take=2/response.json | 68 +++++++++++ octopus_deploy/tests/test_unit.py | 107 ++++++++++++++++++ 5 files changed, 338 insertions(+), 3 deletions(-) create mode 100644 octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=2/take=2/response.json diff --git a/octopus_deploy/datadog_checks/octopus_deploy/check.py b/octopus_deploy/datadog_checks/octopus_deploy/check.py index ed615c056723d..c44be512bcbef 100644 --- a/octopus_deploy/datadog_checks/octopus_deploy/check.py +++ b/octopus_deploy/datadog_checks/octopus_deploy/check.py @@ -452,13 +452,15 @@ def _collect_machine_metrics(self, space_id): machine_name = machine.get("Name") machine_slug = machine.get("Slug") roles = machine.get("Roles", []) - health_status = machine.get("HealthStatus", None) + os = machine.get("OperatingSystem") + health_status = machine.get("HealthStatus") is_healthy = health_status.startswith("Healthy") machine_tags = [ f"machine_id:{machine_id}", f"machine_name:{machine_name}", f"machine_slug:{machine_slug}", f"health_status:{health_status}", + f"operating_system:{os}", ] machine_tags += roles self.gauge("machine.count", 1, tags=self._base_tags + machine_tags) diff --git a/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=2/response.json b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=2/response.json index 93b4d1dfe10df..9f637f4095aa5 100644 --- a/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=2/response.json +++ b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=2/response.json @@ -1,8 +1,8 @@ { "ItemType": "Machine", - "TotalResults": 1, + "TotalResults": 3, "ItemsPerPage": 2, - "NumberOfPages": 1, + "NumberOfPages": 2, "LastPageNumber": 0, "Items": [ { @@ -56,6 +56,59 @@ "TasksTemplate": "/api/Spaces-1/machines/Machines-1/tasks{?skip,take,type}", "SinglyScopedVariableDetails": "/api/Spaces-1/machines/Machines-1/singlyScopedVariableDetails" } + }, + { + "Id": "Machines-2", + "EnvironmentIds": [ + "Environments-1" + ], + "Roles": [ + "test", + "tag" + ], + "TenantedDeploymentParticipation": "Untenanted", + "TenantIds": [], + "TenantTags": [], + "SpaceId": "Spaces-1", + "Name": "test-machine1", + "Thumbprint": "test-footprint1", + "Uri": "hostname-test1:10933/", + "IsDisabled": false, + "MachinePolicyId": "MachinePolicies-1", + "HealthStatus": "Healthy with warnings", + "HasLatestCalamari": false, + "StatusSummary": "Octopus was able to successfully establish a connection with this machine on Wednesday", + "IsInProcess": false, + "Endpoint": { + "CommunicationStyle": "TentaclePassive", + "ProxyId": null, + "Thumbprint": "test-footprint1", + "Uri": "hostname-test1:10933/", + "TentacleVersionDetails": { + "UpgradeLocked": false, + "Version": "8.2.2517", + "UpgradeSuggested": false, + "UpgradeRequired": false, + "UpgradeAvailable": false + }, + "CertificateSignatureAlgorithm": "sha256RSA", + "Id": null, + "LastModifiedOn": null, + "LastModifiedBy": null, + "Links": {} + }, + "OperatingSystem": "Ubuntu 24.04.1 LTS", + "ShellName": "Bash", + "ShellVersion": "5.2.21(1)-release", + "Architecture": "x86_64", + "Slug": "test-machine1", + "SkipInitialHealthCheck": false, + "Links": { + "Self": "/api/Spaces-1/machines/Machines-1", + "Connection": "/api/Spaces-1/machines/Machines-1/connection", + "TasksTemplate": "/api/Spaces-1/machines/Machines-1/tasks{?skip,take,type}", + "SinglyScopedVariableDetails": "/api/Spaces-1/machines/Machines-1/singlyScopedVariableDetails" + } } ], "Links": { diff --git a/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=30/response.json b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=30/response.json index 18b7818ffe166..095aa3518d39a 100644 --- a/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=30/response.json +++ b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=0/take=30/response.json @@ -56,6 +56,111 @@ "TasksTemplate": "/api/Spaces-1/machines/Machines-1/tasks{?skip,take,type}", "SinglyScopedVariableDetails": "/api/Spaces-1/machines/Machines-1/singlyScopedVariableDetails" } + }, + { + "Id": "Machines-2", + "EnvironmentIds": [ + "Environments-1" + ], + "Roles": [ + "test", + "tag" + ], + "TenantedDeploymentParticipation": "Untenanted", + "TenantIds": [], + "TenantTags": [], + "SpaceId": "Spaces-1", + "Name": "test-machine1", + "Thumbprint": "test-footprint1", + "Uri": "hostname-test1:10933/", + "IsDisabled": false, + "MachinePolicyId": "MachinePolicies-1", + "HealthStatus": "Healthy with warnings", + "HasLatestCalamari": false, + "StatusSummary": "Octopus was able to successfully establish a connection with this machine on Wednesday", + "IsInProcess": false, + "Endpoint": { + "CommunicationStyle": "TentaclePassive", + "ProxyId": null, + "Thumbprint": "test-footprint1", + "Uri": "hostname-test1:10933/", + "TentacleVersionDetails": { + "UpgradeLocked": false, + "Version": "8.2.2517", + "UpgradeSuggested": false, + "UpgradeRequired": false, + "UpgradeAvailable": false + }, + "CertificateSignatureAlgorithm": "sha256RSA", + "Id": null, + "LastModifiedOn": null, + "LastModifiedBy": null, + "Links": {} + }, + "OperatingSystem": "Ubuntu 24.04.1 LTS", + "ShellName": "Bash", + "ShellVersion": "5.2.21(1)-release", + "Architecture": "x86_64", + "Slug": "test-machine1", + "SkipInitialHealthCheck": false, + "Links": { + "Self": "/api/Spaces-1/machines/Machines-1", + "Connection": "/api/Spaces-1/machines/Machines-1/connection", + "TasksTemplate": "/api/Spaces-1/machines/Machines-1/tasks{?skip,take,type}", + "SinglyScopedVariableDetails": "/api/Spaces-1/machines/Machines-1/singlyScopedVariableDetails" + } + }, + { + "Id": "Machines-3", + "EnvironmentIds": [ + "Environments-1" + ], + "Roles": [ + "test" + ], + "TenantedDeploymentParticipation": "Untenanted", + "TenantIds": [], + "TenantTags": [], + "SpaceId": "Spaces-1", + "Name": "test-machine3", + "Thumbprint": "test-footprint2", + "Uri": "hostname-test2:10933/", + "IsDisabled": false, + "MachinePolicyId": "MachinePolicies-1", + "HealthStatus": "Unhealthy", + "HasLatestCalamari": false, + "StatusSummary": "Octopus was unable to successfully establish a connection with this machine on Wednesday", + "IsInProcess": false, + "Endpoint": { + "CommunicationStyle": "TentaclePassive", + "ProxyId": null, + "Thumbprint": "test-footprint3", + "Uri": "hostname-test3:10933/", + "TentacleVersionDetails": { + "UpgradeLocked": false, + "Version": "8.2.2517", + "UpgradeSuggested": false, + "UpgradeRequired": false, + "UpgradeAvailable": false + }, + "CertificateSignatureAlgorithm": "sha256RSA", + "Id": null, + "LastModifiedOn": null, + "LastModifiedBy": null, + "Links": {} + }, + "OperatingSystem": "Ubuntu 24.04.1 LTS", + "ShellName": "Bash", + "ShellVersion": "5.2.21(1)-release", + "Architecture": "x86_64", + "Slug": "test-machine3", + "SkipInitialHealthCheck": false, + "Links": { + "Self": "/api/Spaces-1/machines/Machines-1", + "Connection": "/api/Spaces-1/machines/Machines-1/connection", + "TasksTemplate": "/api/Spaces-1/machines/Machines-1/tasks{?skip,take,type}", + "SinglyScopedVariableDetails": "/api/Spaces-1/machines/Machines-1/singlyScopedVariableDetails" + } } ], "Links": { diff --git a/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=2/take=2/response.json b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=2/take=2/response.json new file mode 100644 index 0000000000000..f6d0aa5d31643 --- /dev/null +++ b/octopus_deploy/tests/fixtures/GET/api/Spaces-1/machines/skip=2/take=2/response.json @@ -0,0 +1,68 @@ +{ + "ItemType": "Machine", + "TotalResults": 1, + "ItemsPerPage": 2, + "NumberOfPages": 2, + "LastPageNumber": 0, + "Items": [ + { + "Id": "Machines-3", + "EnvironmentIds": [ + "Environments-1" + ], + "Roles": [ + "test" + ], + "TenantedDeploymentParticipation": "Untenanted", + "TenantIds": [], + "TenantTags": [], + "SpaceId": "Spaces-1", + "Name": "test-machine3", + "Thumbprint": "test-footprint2", + "Uri": "hostname-test2:10933/", + "IsDisabled": false, + "MachinePolicyId": "MachinePolicies-1", + "HealthStatus": "Unhealthy", + "HasLatestCalamari": false, + "StatusSummary": "Octopus was unable to successfully establish a connection with this machine on Wednesday", + "IsInProcess": false, + "Endpoint": { + "CommunicationStyle": "TentaclePassive", + "ProxyId": null, + "Thumbprint": "test-footprint3", + "Uri": "hostname-test3:10933/", + "TentacleVersionDetails": { + "UpgradeLocked": false, + "Version": "8.2.2517", + "UpgradeSuggested": false, + "UpgradeRequired": false, + "UpgradeAvailable": false + }, + "CertificateSignatureAlgorithm": "sha256RSA", + "Id": null, + "LastModifiedOn": null, + "LastModifiedBy": null, + "Links": {} + }, + "OperatingSystem": "Ubuntu 24.04.1 LTS", + "ShellName": "Bash", + "ShellVersion": "5.2.21(1)-release", + "Architecture": "x86_64", + "Slug": "test-machine3", + "SkipInitialHealthCheck": false, + "Links": { + "Self": "/api/Spaces-1/machines/Machines-1", + "Connection": "/api/Spaces-1/machines/Machines-1/connection", + "TasksTemplate": "/api/Spaces-1/machines/Machines-1/tasks{?skip,take,type}", + "SinglyScopedVariableDetails": "/api/Spaces-1/machines/Machines-1/singlyScopedVariableDetails" + } + } + ], + "Links": { + "Self": "/api/Spaces-1/machines?skip=0&take=30", + "Template": "/api/Spaces-1/machines{?skip,take,name,ids,partialName,roles,isDisabled,healthStatuses,commStyles,tenantIds,tenantTags,environmentIds,shellNames,deploymentTargetTypes}", + "Page.All": "/api/Spaces-1/machines?skip=0&take=2147483647", + "Page.Current": "/api/Spaces-1/machines?skip=0&take=30", + "Page.Last": "/api/Spaces-1/machines?skip=0&take=30" + } +} \ No newline at end of file diff --git a/octopus_deploy/tests/test_unit.py b/octopus_deploy/tests/test_unit.py index 52a9ba689a66a..14e82015b5e14 100644 --- a/octopus_deploy/tests/test_unit.py +++ b/octopus_deploy/tests/test_unit.py @@ -2280,6 +2280,7 @@ def test_machines_metrics( "machine_name:test-machine", "machine_slug:test-machine", "health_status:Healthy", + "operating_system:Ubuntu 24.04.1 LTS", "test-tag", ], ) @@ -2291,9 +2292,61 @@ def test_machines_metrics( "machine_name:test-machine", "machine_slug:test-machine", "health_status:Healthy", + "operating_system:Ubuntu 24.04.1 LTS", "test-tag", ], ) + aggregator.assert_metric( + "octopus_deploy.machine.count", + 1, + tags=[ + "machine_id:Machines-2", + "machine_name:test-machine1", + "machine_slug:test-machine1", + "health_status:Healthy with warnings", + "operating_system:Ubuntu 24.04.1 LTS", + "tag", + "test", + ], + ) + aggregator.assert_metric( + "octopus_deploy.machine.is_healthy", + 1, + tags=[ + "machine_id:Machines-2", + "machine_name:test-machine1", + "machine_slug:test-machine1", + "health_status:Healthy with warnings", + "operating_system:Ubuntu 24.04.1 LTS", + "test", + "tag", + ], + ) + + aggregator.assert_metric( + "octopus_deploy.machine.count", + 1, + tags=[ + "machine_id:Machines-3", + "machine_name:test-machine3", + "machine_slug:test-machine3", + "health_status:Unhealthy", + "operating_system:Ubuntu 24.04.1 LTS", + "test", + ], + ) + aggregator.assert_metric( + "octopus_deploy.machine.is_healthy", + 0, + tags=[ + "machine_id:Machines-3", + "machine_name:test-machine3", + "machine_slug:test-machine3", + "health_status:Unhealthy", + "operating_system:Ubuntu 24.04.1 LTS", + "test", + ], + ) @pytest.mark.parametrize( @@ -2310,6 +2363,7 @@ def test_machines_metrics( 2, [ (['http://localhost:80/api/Spaces-1/machines'], 0, 2), + (['http://localhost:80/api/Spaces-1/machines'], 2, 2), ], id='low limit', ), @@ -2351,6 +2405,7 @@ def test_machines_pagination( "machine_name:test-machine", "machine_slug:test-machine", "health_status:Healthy", + "operating_system:Ubuntu 24.04.1 LTS", "test-tag", ], ) @@ -2362,6 +2417,58 @@ def test_machines_pagination( "machine_name:test-machine", "machine_slug:test-machine", "health_status:Healthy", + "operating_system:Ubuntu 24.04.1 LTS", "test-tag", ], ) + aggregator.assert_metric( + "octopus_deploy.machine.count", + 1, + tags=[ + "machine_id:Machines-2", + "machine_name:test-machine1", + "machine_slug:test-machine1", + "health_status:Healthy with warnings", + "operating_system:Ubuntu 24.04.1 LTS", + "tag", + "test", + ], + ) + aggregator.assert_metric( + "octopus_deploy.machine.is_healthy", + 1, + tags=[ + "machine_id:Machines-2", + "machine_name:test-machine1", + "machine_slug:test-machine1", + "health_status:Healthy with warnings", + "operating_system:Ubuntu 24.04.1 LTS", + "test", + "tag", + ], + ) + + aggregator.assert_metric( + "octopus_deploy.machine.count", + 1, + tags=[ + "machine_id:Machines-3", + "machine_name:test-machine3", + "machine_slug:test-machine3", + "health_status:Unhealthy", + "operating_system:Ubuntu 24.04.1 LTS", + "test", + ], + ) + aggregator.assert_metric( + "octopus_deploy.machine.is_healthy", + 0, + tags=[ + "machine_id:Machines-3", + "machine_name:test-machine3", + "machine_slug:test-machine3", + "health_status:Unhealthy", + "operating_system:Ubuntu 24.04.1 LTS", + "test", + ], + )