/
healthchecks.go
47 lines (38 loc) · 1.18 KB
/
healthchecks.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
package drainer
import (
"github.com/mintel/healthcheck" // Healthchecks framework.
"github.com/pkg/errors" // Wrap errors with stacktrace.
"github.com/prometheus/client_golang/prometheus" // Prometheus metrics.
)
type Healthchecks struct {
Handler healthcheck.Handler
// Flag to be set true once a connection
// to Elasticsearch is successfully established.
ElasticSessionCreated bool
// Flag to be set true once an AWS session
// has been successfully created.
AWSSessionCreated bool
}
func NewHealthchecks(r prometheus.Registerer, namespace string) *Healthchecks {
h := &Healthchecks{
Handler: healthcheck.NewMetricsHandler(
r,
namespace,
),
}
// Add a liveness check that always succeeds just to show we're alive.
h.Handler.AddLivenessCheck("alive", func() error { return nil })
h.Handler.AddReadinessCheck("elasticsearch-session", func() error {
if !h.ElasticSessionCreated {
return errors.New("Elasticsearch session not yet ready")
}
return nil
})
h.Handler.AddReadinessCheck("aws-session", func() error {
if !h.AWSSessionCreated {
return errors.New("AWS session not yet ready")
}
return nil
})
return h
}