-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck.go
35 lines (31 loc) · 964 Bytes
/
healthcheck.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
package main
import (
"github.com/Sirupsen/logrus"
"github.com/gorilla/mux"
"net/http"
)
var (
router = mux.NewRouter()
healthcheckPort = ":1000"
)
func startHealthcheck() {
router.HandleFunc("/", healthcheck).Methods("GET", "HEAD").Name("Healthcheck")
logrus.Info("Healthcheck handler is listening on ", healthcheckPort)
logrus.Fatal(http.ListenAndServe(healthcheckPort, router))
}
func healthcheck(w http.ResponseWriter, req *http.Request) {
// 1) test metadata server
_, err := m.MetadataClient.GetSelfStack()
if err != nil {
logrus.Errorf("Metadata health check failed: %v", err)
http.Error(w, "Failed to reach metadata server", http.StatusInternalServerError)
} else {
// 2) test provider
if err := provider.HealthCheck(); err != nil {
logrus.Errorf("Provider health check failed: %v", err)
http.Error(w, "Failed to reach external provider ", http.StatusInternalServerError)
} else {
w.Write([]byte("OK"))
}
}
}