-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInsightsAnnotation.php
More file actions
75 lines (61 loc) · 2.42 KB
/
Copy pathInsightsAnnotation.php
File metadata and controls
75 lines (61 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
declare(strict_types=1);
namespace Hypernode\Api\Service;
use Hypernode\Api\Exception\HypernodeApiClientException;
use Hypernode\Api\Exception\HypernodeApiServerException;
class InsightsAnnotation extends AbstractService
{
public const V2_INSIGHTS_ANNOTATION_LIST_URL = "/v2/insights-annotation/";
public const V2_INSIGHTS_ANNOTATION_CREATE_URL = "/v2/insights-annotation/create/";
/**
* List all custom Insights annotations for the Hypernodes you have access
* to. Only annotations created through the API are listed; system
* annotations generated from platform events are not included.
*
* @param array $params Query parameters, e.g. limit and offset
* @return array List of Insights annotations
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function getList(array $params = []): array
{
$annotations = [];
$requestUrl = self::V2_INSIGHTS_ANNOTATION_LIST_URL;
if ($params) {
$requestUrl .= '?' . http_build_query($params);
}
while ($requestUrl) {
$response = $this->client->api->get($requestUrl);
$this->client->maybeThrowApiExceptions($response);
$data = $this->client->getJsonFromResponse($response);
foreach ($data['results'] as $item) {
$annotations[] = $item;
}
$requestUrl = $data['next'];
}
return $annotations;
}
/**
* Create a custom Insights annotation for a Hypernode. The annotation is
* shown in the Insights graphs at the point in time given by `x_axis` (a
* unix timestamp in seconds). Optionally restrict the annotation to
* specific graphs with `metrics`, a comma-separated list of metric names;
* when omitted, the annotation applies to all metrics.
*
* @param array $data Annotation data, requires at least the keys
* `name`, `x_axis` and `app`.
* @return array The created annotation
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function create(array $data): array
{
$response = $this->client->api->post(
self::V2_INSIGHTS_ANNOTATION_CREATE_URL,
[],
json_encode($data)
);
$this->client->maybeThrowApiExceptions($response);
return $this->client->getJsonFromResponse($response);
}
}