From 908b343ba7fa78ed6985c1006b9ddb1d09858735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Haracewiat?= Date: Fri, 26 Jun 2026 11:16:05 +0200 Subject: [PATCH] feat(metrics): decouple resources overview from chorus --- .../Command/Metrics/MetricsCommandBase.php | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/legacy/src/Command/Metrics/MetricsCommandBase.php b/legacy/src/Command/Metrics/MetricsCommandBase.php index 28074594..132e1244 100644 --- a/legacy/src/Command/Metrics/MetricsCommandBase.php +++ b/legacy/src/Command/Metrics/MetricsCommandBase.php @@ -107,15 +107,32 @@ protected function addMetricsOptions(): self /** * Returns the resources overview URL for the selected environment. * - * @return string|false The link data or false on failure + * @return string|false The resources overview URL, or false if not available * @throws \GuzzleHttp\Exception\GuzzleException if there is an error in fetching observability metadata */ private function getResourcesOverviewUrl(Environment $environment): false|string { - if (!$environment->hasLink('#observability-pipeline')) { + $entrypointUrl = rtrim($environment->getUri(), '/') . '/observability/'; + + $client = $this->api->getHttpClient(); + $request = new Request('GET', $entrypointUrl); + + try { + $response = $client->send($request); + } catch (BadResponseException $e) { + if ($e->getResponse()->getStatusCode() === 404) { + return false; + } + throw ApiResponseException::create($request, $e->getResponse(), $e); + } + + $data = json_decode($response->getBody()->__toString(), true); + + if (!is_array($data) || empty($data['_links']['resources_overview']['href'])) { return false; } - return rtrim($environment->getLink('#observability-pipeline'), '/') . '/resources/overview'; + + return $data['_links']['resources_overview']['href']; } /**