-
Notifications
You must be signed in to change notification settings - Fork 31
/
source_status.go
53 lines (45 loc) · 1.18 KB
/
source_status.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
package v1alpha1
import (
"time"
)
type SourceStatus struct {
LastMessage *Message `json:"lastMessage,omitempty" protobuf:"bytes,2,opt,name=lastMessage"`
LastError *Error `json:"lastError,omitempty" protobuf:"bytes,5,opt,name=lastError"`
Pending *uint64 `json:"pending,omitempty" protobuf:"varint,3,opt,name=pending"`
Metrics map[string]Metrics `json:"metrics,omitempty" protobuf:"bytes,4,rep,name=metrics"`
}
// GetPending returns pending counts
func (in SourceStatus) GetPending() uint64 {
if in.Pending != nil {
return *in.Pending
}
return 0
}
func (in SourceStatus) GetTotal() uint64 {
var x uint64
for _, m := range in.Metrics {
x += m.Total
}
return x
}
func (in SourceStatus) GetErrors() uint64 {
var x uint64
for _, m := range in.Metrics {
x += m.Errors
}
return x
}
func (in SourceStatus) AnySunk() bool {
return in.GetTotal() > 0
}
func (in SourceStatus) RecentErrors() bool {
return in.LastError != nil && time.Since(in.LastError.Time.Time) < 15*time.Minute
}
// GetRetries returns total Retries metrics
func (in SourceStatus) GetRetries() uint64 {
var x uint64
for _, m := range in.Metrics {
x += m.Retries
}
return x
}