-
Notifications
You must be signed in to change notification settings - Fork 31
/
source_statuses.go
60 lines (52 loc) · 1.2 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
package v1alpha1
import (
"strconv"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type SourceStatuses map[string]SourceStatus // key is replica
func (in SourceStatuses) Set(name string, replica int, msg string, rate uint64) {
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) IncErrors(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() int {
v := 0
for _, s := range in {
if s.Pending != nil {
v += int(*s.Pending)
}
}
return v
}
func (in SourceStatuses) AnyErrors() bool {
for _, s := range in {
if s.AnyErrors() {
return true
}
}
return false
}