Skip to content

Commit e8e361e

Browse files
authored
Merge pull request hkulekci#27 from hkulekci/metrics-endpoint
response class parser changed for metrics endpoint which returns text…
2 parents 2668cdb + 25ea987 commit e8e361e

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/Endpoints/Service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function telemetry(bool $anonymize): Response
3636
public function metrics(bool $anonymize): Response
3737
{
3838
return $this->client->execute(
39-
$this->createRequest('POST', '/metrics' . ($anonymize ? '?anonymize=true' : ''))
39+
$this->createRequest('GET', '/metrics' . ($anonymize ? '?anonymize=true' : ''))
4040
);
4141
}
4242

src/Response.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ class Response implements ArrayAccess
2727
public function __construct(ResponseInterface $response)
2828
{
2929
$this->response = $response;
30-
$this->raw = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
30+
31+
if ($response->getHeaderLine('content-type') === 'application/json') {
32+
$this->raw = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
33+
} else {
34+
$this->raw = [
35+
'content' => $response->getBody()->getContents()
36+
];
37+
}
3138

3239
if ($this->response->getStatusCode() >= 400 && $this->response->getStatusCode() < 500) {
3340
throw (new InvalidArgumentException($this->raw['status']['error'] ?? 'Invalid argument exception'))->setResponse($this);

tests/Integration/Endpoints/ServiceTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ public function testServiceTelemetry(): void
2929
$this->assertArrayHasKey('id', $response['result']);
3030
}
3131

32+
/**
33+
* @throws InvalidArgumentException
34+
*/
35+
public function testServiceMetrics(): void
36+
{
37+
$service = new Service($this->client);
38+
$response = $service->metrics(false);
39+
40+
$this->assertStringContainsString('app_info', $response['content']);
41+
$this->assertStringContainsString('cluster_enabled', $response['content']);
42+
$this->assertStringContainsString('collections_total', $response['content']);
43+
$this->assertStringContainsString('rest_responses_', $response['content']);
44+
}
45+
3246
/**
3347
* @throws InvalidArgumentException
3448
*/

0 commit comments

Comments
 (0)