-
Notifications
You must be signed in to change notification settings - Fork 2k
/
api_compatibility.go
85 lines (72 loc) · 2.77 KB
/
api_compatibility.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
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
package testpromcompatibility
import (
"encoding/json"
"time"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/rules"
)
type RuleDiscovery struct {
RuleGroups []*RuleGroup `json:"groups"`
}
// Same as https://github.com/prometheus/prometheus/blob/c530b4b456cc5f9ec249f771dff187eb7715dc9b/web/api/v1/api.go#L955
// but with Partial Response.
type RuleGroup struct {
Name string `json:"name"`
File string `json:"file"`
Rules []Rule `json:"rules"`
Interval float64 `json:"interval"`
EvaluationTime float64 `json:"evaluationTime"`
LastEvaluation time.Time `json:"lastEvaluation"`
Limit int `json:"limit"`
PartialResponseStrategy string `json:"partialResponseStrategy"`
}
// https://github.com/prometheus/prometheus/blob/c530b4b456cc5f9ec249f771dff187eb7715dc9b/web/api/v1/api.go#L1016
// MarshalJSON marshals a rulegroup while ensuring that `rules' is always non-empty.
func (r *RuleGroup) MarshalJSON() ([]byte, error) {
if r.Rules == nil {
r.Rules = make([]Rule, 0)
}
type plain RuleGroup
return json.Marshal((*plain)(r))
}
type Rule interface{}
type AlertAPI struct {
Alerts []*Alert `json:"alerts"`
}
type Alert struct {
Labels labels.Labels `json:"labels"`
Annotations labels.Labels `json:"annotations"`
State string `json:"state"`
ActiveAt *time.Time `json:"activeAt,omitempty"`
Value string `json:"value"`
PartialResponseStrategy string `json:"partialResponseStrategy"`
}
type AlertingRule struct {
// State can be "pending", "firing", "inactive".
State string `json:"state"`
Name string `json:"name"`
Query string `json:"query"`
Duration float64 `json:"duration"`
Labels labels.Labels `json:"labels"`
Annotations labels.Labels `json:"annotations"`
Alerts []*Alert `json:"alerts"`
Health rules.RuleHealth `json:"health"`
LastError string `json:"lastError,omitempty"`
EvaluationTime float64 `json:"evaluationTime"`
LastEvaluation time.Time `json:"lastEvaluation"`
// Type of an AlertingRule is always "alerting".
Type string `json:"type"`
}
type RecordingRule struct {
Name string `json:"name"`
Query string `json:"query"`
Labels labels.Labels `json:"labels"`
Health rules.RuleHealth `json:"health"`
LastError string `json:"lastError,omitempty"`
EvaluationTime float64 `json:"evaluationTime"`
LastEvaluation time.Time `json:"lastEvaluation"`
// Type of a prometheusRecordingRule is always "recording".
Type string `json:"type"`
}