-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
69 lines (59 loc) · 1.66 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
package graphiteapi
import (
"context"
pb "github.com/go-graphite/carbonzipper/carbonzipperpb3"
)
// Query is interface for all api request
type Query interface {
URL() string
Request(ctx context.Context) (Response, error)
}
// Response is interface for all api request response types
type Response interface {
Unmarshal([]byte) error
}
// RenderQuery is used to build `/render/` query
type RenderQuery struct {
Base string // base url of graphite server
Targets []*RenderTarget
From string
Until string
MaxDataPoints int
}
// RenderResponse is response of `/render/` query
type RenderResponse struct {
pb.MultiFetchResponse
}
// QueryTarget represents a `target=` arg in `/render/` query
type RenderTarget struct {
str string
}
// GetLastNonNullValue searches for the latest non null value, and skips at most maxNullPoints.
// If the last maxNullPoints values are all absent, returns absent
func GetLastNonNullValue(m *pb.FetchResponse, maxNullPoints int) (v float64, t int32, absent bool) {
l := len(m.Values)
if l == 0 {
// there is values, we should return absent
v = 0
t = m.StopTime
absent = true
return v, t, absent
}
for i := 0; i < maxNullPoints && i < l; i++ {
if m.IsAbsent[l-1-i] {
continue
}
v = m.Values[l-1-i]
t = m.StopTime - int32(i)*m.StepTime
absent = false
return v, t, absent
}
// if we get here, there are two cases
// * maxNullPoints == 0, we didn't even enter the loop above
// * maxNullPoints > 0, but we didn't find a non-null point in the loop
// in both cases, we return the last point's info
v = m.Values[l-1]
t = m.StopTime
absent = m.IsAbsent[l-1]
return v, t, absent
}