-
Notifications
You must be signed in to change notification settings - Fork 14
/
updater.go
71 lines (59 loc) · 1.63 KB
/
updater.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
package metrics
import (
"context"
"time"
"github.com/cybozu-go/cke"
)
func alwaysAvailable(_ context.Context, _ storage) (bool, error) {
return true, nil
}
var isLeader bool
// UpdateLeader updates "leader".
func UpdateLeader(flag bool) {
if flag {
leader.Set(1)
} else {
leader.Set(0)
}
isLeader = flag
}
// UpdateOperationPhase updates "operation_phase" and its timestamp.
func UpdateOperationPhase(phase cke.OperationPhase, ts time.Time) {
for _, labelPhase := range cke.AllOperationPhases {
if labelPhase == phase {
operationPhase.WithLabelValues(string(labelPhase)).Set(1)
} else {
operationPhase.WithLabelValues(string(labelPhase)).Set(0)
}
}
operationPhaseTimestampSeconds.Set(float64(ts.Unix()))
}
func isOperationPhaseAvailable(_ context.Context, _ storage) (bool, error) {
return isLeader, nil
}
func isNodeAvailable(_ context.Context, _ storage) (bool, error) {
return isLeader, nil
}
// UpdateSabakanIntegration updates Sabakan integration metrics.
func UpdateSabakanIntegration(isSuccessful bool, workersByRole map[string]int, unusedMachines int, ts time.Time) {
sabakanIntegrationTimestampSeconds.Set(float64(ts.Unix()))
if !isSuccessful {
sabakanIntegrationSuccessful.Set(0)
return
}
sabakanIntegrationSuccessful.Set(1)
for role, num := range workersByRole {
sabakanWorkers.WithLabelValues(role).Set(float64(num))
}
sabakanUnusedMachines.Set(float64(unusedMachines))
}
func isSabakanIntegrationAvailable(ctx context.Context, st storage) (bool, error) {
if !isLeader {
return false, nil
}
disabled, err := st.IsSabakanDisabled(ctx)
if err != nil {
return false, err
}
return !disabled, nil
}