Skip to content
Open
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
23 changes: 20 additions & 3 deletions legacy/src/Command/Metrics/MetricsCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

/**
Expand Down