feat(go): expose runtime ingest metrics

This commit is contained in:
lingniu
2026-07-02 19:06:24 +08:00
parent 1dfd540700
commit 896e841902
18 changed files with 602 additions and 28 deletions

View File

@@ -7,6 +7,8 @@ import (
"net/http"
"strings"
"time"
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/metrics"
)
type Check struct {
@@ -32,22 +34,25 @@ func NewHandler(service string, checks []Check) *Handler {
return &Handler{service: service, checks: checks}
}
func NewMux(service string, checks []Check) *http.ServeMux {
func NewMux(service string, checks []Check, registry *metrics.Registry) *http.ServeMux {
mux := http.NewServeMux()
handler := NewHandler(service, checks)
mux.Handle("/healthz", handler)
mux.Handle("/readyz", handler)
if registry != nil {
mux.Handle("/metrics", metrics.NewHandler(registry))
}
return mux
}
func NewServer(addr string, service string, checks []Check) *http.Server {
func NewServer(addr string, service string, checks []Check, registry *metrics.Registry) *http.Server {
addr = strings.TrimSpace(addr)
if addr == "" {
return nil
}
return &http.Server{
Addr: addr,
Handler: NewMux(service, checks),
Handler: NewMux(service, checks, registry),
ReadHeaderTimeout: 5 * time.Second,
}
}