-
Notifications
You must be signed in to change notification settings - Fork 31
/
source_statuses.go
98 lines (85 loc) · 1.92 KB
/
source_statuses.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
package v1alpha1
import (
"strconv"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type SourceStatuses map[string]SourceStatus // key is replica
func (in SourceStatuses) IncrTotal(name string, replica int, msg string, rate resource.Quantity) {
x := in[name]
x.LastMessage = &Message{Data: trunc(msg), Time: metav1.Now()}
if x.Metrics == nil {
x.Metrics = map[string]Metrics{}
}
m := x.Metrics[strconv.Itoa(replica)]
m.Total++
m.Rate = rate
x.Metrics[strconv.Itoa(replica)] = m
in[name] = x
}
func (in SourceStatuses) Get(name string) SourceStatus {
if x, ok := in[name]; ok {
return x
}
return SourceStatus{}
}
func (in SourceStatuses) IncrErrors(name string, replica int, err error) {
x := in[name]
msg := err.Error()
x.LastError = &Error{Message: trunc(msg), Time: metav1.Now()}
if x.Metrics == nil {
x.Metrics = map[string]Metrics{}
}
m := x.Metrics[strconv.Itoa(replica)]
m.Errors++
x.Metrics[strconv.Itoa(replica)] = m
in[name] = x
}
func (in SourceStatuses) SetPending(name string, pending uint64) {
x := in[name]
x.Pending = &pending
in[name] = x
}
func (in SourceStatuses) GetPending() uint64 {
var v uint64
for _, s := range in {
if s.Pending != nil {
v += *s.Pending
}
}
return v
}
func (in SourceStatuses) GetTotal() uint64 {
var v uint64
for _, s := range in {
v += s.GetTotal()
}
return v
}
func (in SourceStatuses) RecentErrors() bool {
for _, s := range in {
if s.RecentErrors() {
return true
}
}
return false
}
func (in SourceStatuses) AnySunk() bool {
for _, s := range in {
if s.AnySunk() {
return true
}
}
return false
}
// IncrRetryCount increase the retry_count metrics by 1
func (in SourceStatuses) IncrRetryCount(name string, replica int) {
x := in[name]
if x.Metrics == nil {
x.Metrics = map[string]Metrics{}
}
m := x.Metrics[strconv.Itoa(replica)]
m.Retries++
x.Metrics[strconv.Itoa(replica)] = m
in[name] = x
}