This repository has been archived by the owner on Dec 1, 2018. It is now read-only.
/
types.go
164 lines (142 loc) · 3.54 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
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
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package core
import (
"time"
)
type MetricType int8
const (
MetricCumulative MetricType = iota
MetricGauge
MetricDelta
)
func (self *MetricType) String() string {
switch *self {
case MetricCumulative:
return "cumulative"
case MetricGauge:
return "gauge"
case MetricDelta:
return "delta"
}
return ""
}
type ValueType int8
const (
ValueInt64 ValueType = iota
ValueFloat
)
func (self *ValueType) String() string {
switch *self {
case ValueInt64:
return "int64"
case ValueFloat:
return "double"
}
return ""
}
type UnitsType int8
const (
// A counter metric.
UnitsCount UnitsType = iota
// A metric in bytes.
UnitsBytes
// A metric in milliseconds.
UnitsMilliseconds
// A metric in nanoseconds.
UnitsNanoseconds
// A metric in millicores.
UnitsMillicores
)
func (self *UnitsType) String() string {
switch *self {
case UnitsBytes:
return "bytes"
case UnitsMilliseconds:
return "ms"
case UnitsNanoseconds:
return "ns"
case UnitsMillicores:
return "millicores"
}
return ""
}
type MetricValue struct {
IntValue int64
FloatValue float64
MetricType MetricType
ValueType ValueType
}
func (this *MetricValue) GetValue() interface{} {
if ValueInt64 == this.ValueType {
return this.IntValue
} else if ValueFloat == this.ValueType {
return this.FloatValue
} else {
return nil
}
}
type LabeledMetric struct {
Name string
Labels map[string]string
MetricValue
}
func (this *LabeledMetric) GetValue() interface{} {
if ValueInt64 == this.ValueType {
return this.IntValue
} else if ValueFloat == this.ValueType {
return this.FloatValue
} else {
return nil
}
}
type MetricSet struct {
// CollectionStartTime is a time since when the metrics are collected for this entity.
// It is affected by events like entity (e.g. pod) creation, entity restart (e.g. for container),
// Kubelet restart.
CollectionStartTime time.Time
// EntityCreateTime is a time of entity creation and persists through entity restarts and
// Kubelet restarts.
EntityCreateTime time.Time
ScrapeTime time.Time
MetricValues map[string]MetricValue
Labels map[string]string
LabeledMetrics []LabeledMetric
}
type DataBatch struct {
Timestamp time.Time
// Should use key functions from ms_keys.go
MetricSets map[string]*MetricSet
}
// A place from where the metrics should be scraped.
type MetricsSource interface {
Name() string
ScrapeMetrics(start, end time.Time) (*DataBatch, error)
}
// Provider of list of sources to be scaped.
type MetricsSourceProvider interface {
GetMetricsSources() []MetricsSource
}
type DataSink interface {
Name() string
// Exports data to the external storage. The function should be synchronous/blocking and finish only
// after the given DataBatch was written. This will allow sink manager to push data only to these
// sinks that finished writing the previous data.
ExportData(*DataBatch)
Stop()
}
type DataProcessor interface {
Name() string
Process(*DataBatch) (*DataBatch, error)
}