-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_liveness_probe.go
68 lines (60 loc) · 1.17 KB
/
check_liveness_probe.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
package main
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"io"
"net/http"
"os"
"time"
)
func getLivenessProbe() string {
gitlabUrl := os.Getenv("GITLAB_URL")
token := os.Getenv("GITLAB_PROBES_TOKEN")
livenessEndpoint := fmt.Sprintf(gitlabUrl+livenessPartOfUrl, token)
var livProbe LivenessProbe
request, err := http.NewRequest("GET", livenessEndpoint, nil)
if err != nil {
log.Error(err)
}
result, err := http.DefaultClient.Do(request)
if err != nil {
log.Error(err)
}
defer result.Body.Close()
body, err := io.ReadAll(result.Body)
err = json.Unmarshal(body, &livProbe)
if err != nil {
log.Error(err)
}
return livProbe.Status
}
func checkLivenessProbe() {
i := 0
n := 0
Loop:
for {
status := getLivenessProbe()
if i > 1 {
log.Error("A lot of errors in liveness probes")
notificationToSlack("no")
sendAlert()
break
} else {
if status != "ok" && i <= 1 {
i++
n++
log.Error("Failed checking of liveness probe")
log.Info("Retry check for 5 minutes")
if i != 2 {
time.Sleep(5 * time.Minute)
}
continue Loop
}
break
}
}
if n == 0 {
log.Info("All liveness probes are ready")
}
}