Skip to content

Commit

Permalink
New probe handlers (#100)
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Shishkin <me@teran.dev>
  • Loading branch information
teran authored Aug 5, 2024
1 parent 4f57fda commit c3ce077
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 9 deletions.
30 changes: 30 additions & 0 deletions cmd/exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,36 @@ func main() {

g.Go(func() error {
http.Handle("/metrics", promhttp.Handler())

http.HandleFunc("/healthz/startup", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok\n"))
})

http.HandleFunc("/healthz/readiness", func(w http.ResponseWriter, r *http.Request) {
log.Warnf("db.Ping() error on readiness probe: %s", err)

if err := db.Ping(); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte("failed\n"))
} else {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok\n"))
}
})

http.HandleFunc("/healthz/liveness", func(w http.ResponseWriter, r *http.Request) {
if err := db.Ping(); err != nil {
log.Warnf("db.Ping() error on liveness probe: %s", err)

w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte("failed\n"))
} else {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok\n"))
}
})

return http.ListenAndServe(cfg.Addr, nil)
})

Expand Down
30 changes: 30 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,36 @@ func main() {

g.Go(func() error {
http.Handle("/metrics", promhttp.Handler())

http.HandleFunc("/healthz/startup", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok\n"))
})

http.HandleFunc("/healthz/readiness", func(w http.ResponseWriter, r *http.Request) {
log.Warnf("db.Ping() error on readiness probe: %s", err)

if err := db.Ping(); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte("failed\n"))
} else {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok\n"))
}
})

http.HandleFunc("/healthz/liveness", func(w http.ResponseWriter, r *http.Request) {
if err := db.Ping(); err != nil {
log.Warnf("db.Ping() error on liveness probe: %s", err)

w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte("failed\n"))
} else {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok\n"))
}
})

return http.ListenAndServe(cfg.MetricsAddr, nil)
})

Expand Down
30 changes: 30 additions & 0 deletions cmd/publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,36 @@ func main() {

g.Go(func() error {
http.Handle("/metrics", promhttp.Handler())

http.HandleFunc("/healthz/startup", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok\n"))
})

http.HandleFunc("/healthz/readiness", func(w http.ResponseWriter, r *http.Request) {
log.Warnf("db.Ping() error on readiness probe: %s", err)

if err := db.Ping(); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte("failed\n"))
} else {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok\n"))
}
})

http.HandleFunc("/healthz/liveness", func(w http.ResponseWriter, r *http.Request) {
if err := db.Ping(); err != nil {
log.Warnf("db.Ping() error on liveness probe: %s", err)

w.WriteHeader(http.StatusServiceUnavailable)
w.Write([]byte("failed\n"))
} else {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok\n"))
}
})

return http.ListenAndServe(cfg.MetricsAddr, nil)
})

Expand Down
12 changes: 9 additions & 3 deletions docs/examples/deploy/k8s/archived-exporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,21 @@ spec:
memory: 128Mi
limits:
memory: 1Gi
readinessProbe:
startupProbe:
httpGet:
path: /metrics
path: /healthz/startup
port: metrics
timeoutSeconds: 1
readinessProbe:
httpGet:
path: /healthz/readiness
port: metrics
timeoutSeconds: 5
livenessProbe:
httpGet:
path: /metrics
path: /healthz/liveness
port: metrics
timeoutSeconds: 5
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
12 changes: 9 additions & 3 deletions docs/examples/deploy/k8s/archived-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,21 @@ spec:
memory: 1Gi
limits:
memory: 1Gi
readinessProbe:
startupProbe:
httpGet:
path: /metrics
path: /healthz/startup
port: metrics
timeoutSeconds: 1
readinessProbe:
httpGet:
path: /healthz/readiness
port: metrics
timeoutSeconds: 5
livenessProbe:
httpGet:
path: /metrics
path: /healthz/liveness
port: metrics
timeoutSeconds: 5
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
12 changes: 9 additions & 3 deletions docs/examples/deploy/k8s/archived-publisher.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,21 @@ spec:
memory: 128Mi
limits:
memory: 1Gi
readinessProbe:
startupProbe:
httpGet:
path: /metrics
path: /healthz/startup
port: metrics
timeoutSeconds: 1
readinessProbe:
httpGet:
path: /healthz/readiness
port: metrics
timeoutSeconds: 5
livenessProbe:
httpGet:
path: /metrics
path: /healthz/liveness
port: metrics
timeoutSeconds: 5
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true

0 comments on commit c3ce077

Please sign in to comment.