feat(metrics): wire instrumentation through queue, handlers, middleware
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/shcizo/package-updater/internal/discovery"
|
||||
"github.com/shcizo/package-updater/internal/logging"
|
||||
"github.com/shcizo/package-updater/internal/metrics"
|
||||
"github.com/shcizo/package-updater/internal/updater"
|
||||
)
|
||||
|
||||
@@ -34,11 +35,13 @@ type Handlers struct {
|
||||
version string
|
||||
commit string
|
||||
buildTime string
|
||||
metrics *metrics.Metrics
|
||||
}
|
||||
|
||||
// NewHandlers constructs a Handlers value with all dependencies injected.
|
||||
func NewHandlers(f Finder, s Submitter, p Pinger, version, commit, buildTime string) *Handlers {
|
||||
return &Handlers{finder: f, submitter: s, pinger: p, version: version, commit: commit, buildTime: buildTime}
|
||||
// m may be nil, in which case metrics recording is silently skipped.
|
||||
func NewHandlers(f Finder, s Submitter, p Pinger, version, commit, buildTime string, m *metrics.Metrics) *Handlers {
|
||||
return &Handlers{finder: f, submitter: s, pinger: p, version: version, commit: commit, buildTime: buildTime, metrics: m}
|
||||
}
|
||||
|
||||
// Update implements POST /update.
|
||||
@@ -107,9 +110,15 @@ func (h *Handlers) Update(w http.ResponseWriter, r *http.Request) {
|
||||
// Healthz implements GET /healthz.
|
||||
func (h *Handlers) Healthz(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := h.pinger.Ping(r.Context()); err != nil {
|
||||
if h.metrics != nil {
|
||||
h.metrics.DockerPingUp.Set(0)
|
||||
}
|
||||
writeJSON(w, http.StatusServiceUnavailable, HealthResponse{Status: "unhealthy", Docker: "unreachable"})
|
||||
return
|
||||
}
|
||||
if h.metrics != nil {
|
||||
h.metrics.DockerPingUp.Set(1)
|
||||
}
|
||||
writeJSON(w, http.StatusOK, HealthResponse{Status: "ok", Docker: "ok"})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user