-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathseverityController.go
76 lines (62 loc) · 2.34 KB
/
severityController.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
package main
import (
"context"
log "github.com/Financial-Times/go-logger"
)
func (c *healthCheckController) getSeverityForService(ctx context.Context, serviceName string, appPort int32) uint8 {
pods, err := c.healthCheckService.getPodsForService(ctx, serviceName)
if err != nil {
log.WithError(err).Warnf("Cannot get pods for service with name %s in order to get severity level, using default severity: %d.", serviceName, defaultSeverity)
return defaultSeverity
}
var isResilient bool
service, err := c.healthCheckService.getServiceByName(serviceName)
if err != nil {
log.WithError(err).Warnf("Cannot get service with name %s in order to get resiliency, using default resiliency: %t.", serviceName, defaultResiliency)
isResilient = defaultResiliency
} else {
isResilient = service.isResilient
}
if !isResilient {
return c.computeSeverityByPods(pods, appPort)
}
finalSeverity := defaultSeverity
for _, pod := range pods {
individualPodSeverity, checkFailed, err := c.healthCheckService.getIndividualPodSeverity(pod, appPort)
if err != nil {
log.WithError(err).Error("Cannot get individual pod severity, skipping pod.")
continue
}
// if at least one pod of the resilient service is healthy, we return the default severity,
// regardless of the status of other pods
if !checkFailed {
return defaultSeverity
}
if individualPodSeverity < finalSeverity {
finalSeverity = individualPodSeverity
}
}
return finalSeverity
}
func (c *healthCheckController) getSeverityForPod(ctx context.Context, podName string, appPort int32) uint8 {
podToBeChecked, err := c.healthCheckService.getPodByName(ctx, podName)
if err != nil {
log.WithError(err).Errorf("Cannot get pod by name: %s in order to get severity level, using default severity: %d.", podName, defaultSeverity)
return defaultSeverity
}
return c.computeSeverityByPods([]pod{podToBeChecked}, appPort)
}
func (c *healthCheckController) computeSeverityByPods(pods []pod, appPort int32) uint8 {
finalSeverity := defaultSeverity
for _, pod := range pods {
individualPodSeverity, _, err := c.healthCheckService.getIndividualPodSeverity(pod, appPort)
if err != nil {
log.WithError(err).Warn("Cannot get individual pod severity, skipping pod.")
continue
}
if individualPodSeverity < finalSeverity {
return individualPodSeverity
}
}
return finalSeverity
}