-
Notifications
You must be signed in to change notification settings - Fork 2
/
model.go
164 lines (135 loc) · 3.98 KB
/
model.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package tsdb
type ValueType string
const (
Long ValueType = "Long"
Double = "Double"
String = "String"
Bytes = "Bytes"
Number = "Number"
)
type Tags map[string]string
type Datapoint struct {
Metric string `json:"metric"`
Field string `json:"field,omitempty"`
Tags Tags `json:"tags"`
Type ValueType `json:"type,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
Value interface{} `json:"value,omitempty"`
Values [][]interface{} `json:"values,omitempty"`
}
type WriteDataPointArgs struct {
DataPoints []Datapoint `json:"datapoints"`
}
type ListMetricsResult struct {
Metrics []string `json:"metrics"`
}
type Field struct {
Type ValueType `json:"fields"`
}
type ListFieldResult struct {
Fields map[string]Field `json:"fields"`
}
type TagValues []string
type ListTagsResult struct {
Tags map[string]TagValues `json:"tags"`
}
type Query struct {
Metric string `json:"metric"`
Field string `json:"field,omitempty"`
Fields []string `json:"fields,omitempty"`
Tags []string `json:"tags,omitempty"`
Filters Filter `json:"filters"`
GroupBy []GroupBy `json:"groupBy,omitempty"`
Limit int `json:"limit,omitempty"`
Aggregators []Aggregator `json:"aggregators,omitempty"`
Order string `json:"order,omitempty"`
Fill *Fill `json:"fill,omitempty"`
Fills []Fill `json:"fills,omitempty"`
Marker string `json:"marker,omitempty"`
}
type Queries []Query
type ListDatapointArgs struct {
Queries Queries `json:"queries"`
DisablePresampling bool `json:"disablePresampling,omitempty"`
}
type ListDatapointResult struct {
Results []QueryResult `json:"results"`
}
type QueryResult struct {
Metric string `json:"metric"`
Field string `json:"field"`
Fields []string `json:"fields"`
Tags []string `json:"tags"`
RawCount int `json:"rawCount"`
Groups []Group `json:"groups"`
Truncated bool `json:"truncated"`
NextMarker string `json:"nextMarker"`
PresamplingRuleId string `json:"presamplingRuleId"`
}
type Group struct {
GroupInfos []GroupInfo `json:"groupInfos"`
Values []Value `json:"values"`
}
type GroupInfo struct {
Name string `json:"name"`
Tags map[string]TagValues `json:"tags"`
}
type Fill struct {
Name string `json:"type"`
Interval string `json:"interval"`
MaxWriteInterval string `json:"maxWriteInterval,omitempty"`
}
type Aggregator struct {
Name string `json:"name"`
Sampling string `json:"sampling,omitempty"`
Percentile float64 `json:"percentile,omitempty"`
Divisor float64 `json:"divisor,omitempty"`
Factor float64 `json:"factor,omitempty"`
TimeUnit string `json:"timeUnit,omitempty"`
}
type GroupBy struct {
Name string `json:"name"`
Tags []string `json:"tags,omitempty"`
}
type Filter struct {
Start interface{} `json:"start"`
End interface{} `json:"end,omitempty"`
Tags map[string]TagValues `json:"tags,omitempty"`
Value string `json:"value,omitempty"`
Fields []FieldFilter `json:"fields,omitempty"`
Or []Filter `json:"or,omitempty"`
}
type FieldFilter struct {
Field string `json:"field"`
Value string `json:"value"`
}
type TagFilter struct {
Tag string `json:"tag"`
In []string `json:"in"`
NotIn []string `json:"notIn"`
Like string `json:"like"`
}
type Column struct {
Name string `json:"name"`
}
type Value []interface{}
type Raw []interface{}
func (v Value) Timestamp() int64 {
if t, ok := v[0].(int64); ok {
return t
}
if t, ok := v[0].(float64); ok {
return int64(t)
}
return 0
}
func (v Value) Value() interface{} {
return v[1]
}
func (v Value) Tag(i int) interface{} {
return v[1+i]
}
type RowResult struct {
Columns []Column `json:"columns"`
Raw []Raw `json:"raw"`
}