-
Notifications
You must be signed in to change notification settings - Fork 31
/
sink_statuses.go
53 lines (46 loc) · 1.03 KB
/
sink_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
package v1alpha1
import (
"strconv"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type SinkStatuses map[string]SinkStatus
func (in SinkStatuses) Set(name string, replica int, msg string) {
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++
x.Metrics[strconv.Itoa(replica)] = m
in[name] = x
}
func (in SinkStatuses) IncErrors(name string, replica int, err error) {
x := in[name]
x.LastError = &Error{Message: trunc(err.Error()), 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 SinkStatuses) AnySunk() bool {
for _, s := range in {
for _, m := range s.Metrics {
if m.Total > 0 {
return true
}
}
}
return false
}
func (in SinkStatuses) AnyErrors() bool {
for _, s := range in {
if s.AnyErrors() {
return true
}
}
return false
}