-
Notifications
You must be signed in to change notification settings - Fork 0
/
pushgateway.go
73 lines (64 loc) · 2.47 KB
/
pushgateway.go
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
package client
import (
"context"
"fmt"
"net/http"
"time"
)
type PushgatewayMetric struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
TTL string `json:"ttl"`
Type string `json:"type"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Value string `json:"value"`
}
type CreateOrUpdatePushgatewayMetricInput struct {
Name string `json:"name" validate:"required,max=255,min=1"`
Description string `json:"description,omitempty"`
Labels map[string]string `json:"labels" description:"Healthcheck labels" validate:"dive,keys,max=255,min=1,endkeys,max=255,min=1"`
TTL string `json:"ttl"`
Type string `json:"type" validate:"omitempty,oneof=counter gauge histogram summary"`
Value string `json:"value" validate:"required"`
}
type DeletePushgatewayMetricInput struct {
Identifier string `param:"identifier" validate:"required"`
}
type ListPushgatewayMetricsOutput struct {
Result []PushgatewayMetric `json:"result"`
}
func (c *Client) CreateOrUpdatePushgatewayMetric(ctx context.Context, input CreateOrUpdatePushgatewayMetricInput) (Response, error) {
var result Response
_, err := c.sendRequest(ctx, "/api/v1/pushgateway", http.MethodPost, input, &result, nil)
if err != nil {
return Response{}, err
}
return result, nil
}
func (c *Client) DeletePushgatewayMetric(ctx context.Context, input DeletePushgatewayMetricInput) (Response, error) {
var result Response
_, err := c.sendRequest(ctx, fmt.Sprintf("/api/v1/pushgateway/%s", input.Identifier), http.MethodDelete, nil, &result, nil)
if err != nil {
return Response{}, err
}
return result, nil
}
func (c *Client) ListPushgatewayMetrics(ctx context.Context) (ListPushgatewayMetricsOutput, error) {
var result ListPushgatewayMetricsOutput
_, err := c.sendRequest(ctx, "/api/v1/pushgateway", http.MethodGet, nil, &result, nil)
if err != nil {
return ListPushgatewayMetricsOutput{}, err
}
return result, nil
}
func (c *Client) DeleteAllPushgatewayMetrics(ctx context.Context) (Response, error) {
var result Response
_, err := c.sendRequest(ctx, "/api/v1/pushgateway", http.MethodDelete, nil, &result, nil)
if err != nil {
return Response{}, err
}
return result, nil
}