forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
129 lines (109 loc) · 2.6 KB
/
types.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
package metrics
import (
"encoding/json"
"fmt"
// "time"
)
// MetricType restrictions
type MetricType int
const (
Gauge = iota
Availability
Counter
Generic
)
var longForm = []string{
"gauges",
"availability",
"counters",
"metrics",
}
var shortForm = []string{
"gauge",
"availability",
"counter",
"metrics",
}
func (self MetricType) validate() error {
if int(self) > len(longForm) && int(self) > len(shortForm) {
return fmt.Errorf("Given MetricType value %d is not valid", self)
}
return nil
}
func (self MetricType) String() string {
if err := self.validate(); err != nil {
return "unknown"
}
return longForm[self]
}
func (self MetricType) shortForm() string {
if err := self.validate(); err != nil {
return "unknown"
}
return shortForm[self]
}
// Custom unmarshaller
func (self *MetricType) UnmarshalJSON(b []byte) error {
var f interface{}
err := json.Unmarshal(b, &f)
if err != nil {
return err
}
if str, ok := f.(string); ok {
for i, v := range shortForm {
if str == v {
*self = MetricType(i)
break
}
}
}
return nil
}
func (self MetricType) MarshalJSON() ([]byte, error) {
return json.Marshal(self.String())
}
type SortKey struct {
Tenant string
Type MetricType
}
// Hawkular-Metrics external structs
// Do I need external.. hmph.
type MetricHeader struct {
Tenant string `json:"-"`
Type MetricType `json:"-"`
Id string `json:"id"`
Data []Datapoint `json:"data"`
}
// Value should be convertible to float64 for numeric values
// Timestamp is milliseconds since epoch
type Datapoint struct {
Timestamp int64 `json:"timestamp"`
Value interface{} `json:"value"`
Tags map[string]string `json:"tags,omitempty"`
}
type HawkularError struct {
ErrorMsg string `json:"errorMsg"`
}
type MetricDefinition struct {
Tenant string `json:"-"`
Type MetricType `json:"type,omitempty"`
Id string `json:"id"`
Tags map[string]string `json:"tags,omitempty"`
RetentionTime int `json:"dataRetention,omitempty"`
}
// TODO Fix the Start & End to return a time.Time
type Bucketpoint struct {
Start int64 `json:"start"`
End int64 `json:"end"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Avg float64 `json:"avg"`
Median float64 `json:"median"`
Empty bool `json:"empty"`
Samples int64 `json:"samples"`
Percentiles []Percentile `json:"percentiles"`
}
type Percentile struct {
Quantile float64 `json:"quantile"`
Value float64 `json:"value"`
}