From 722287631b907e84c387780f8c1df407f3b39034 Mon Sep 17 00:00:00 2001 From: Vicente Ferrara <47219931+vicentefb@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:49:32 -0700 Subject: [PATCH] Fix allocator metrics endpoint (#3921) * updated metrics to use healthserver instead of default mux to create the tcp connection --- cmd/allocator/main.go | 5 ++--- cmd/allocator/metrics.go | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cmd/allocator/main.go b/cmd/allocator/main.go index b7168f2b2b..4c6caea7df 100644 --- a/cmd/allocator/main.go +++ b/cmd/allocator/main.go @@ -217,8 +217,8 @@ func main() { if !validPort(conf.GRPCPort) && !validPort(conf.HTTPPort) { logger.WithField("grpc-port", conf.GRPCPort).WithField("http-port", conf.HTTPPort).Fatal("Must specify a valid gRPC port or an HTTP port for the allocator service") } - - health, closer := setupMetricsRecorder(conf) + healthserver := &httpserver.Server{Logger: logger} + health, closer := setupMetricsRecorder(conf, healthserver) defer closer() kubeClient, agonesClient, err := getClients(conf) @@ -307,7 +307,6 @@ func main() { } // Finally listen on 8080 (http), used to serve /live and /ready handlers for Kubernetes probes. - healthserver := httpserver.Server{Logger: logger} healthserver.Handle("/", health) go func() { _ = healthserver.Run(listenCtx, 0) }() diff --git a/cmd/allocator/metrics.go b/cmd/allocator/metrics.go index 4dd1770996..7ce8ed2110 100644 --- a/cmd/allocator/metrics.go +++ b/cmd/allocator/metrics.go @@ -14,9 +14,8 @@ package main import ( - "net/http" - "agones.dev/agones/pkg/metrics" + "agones.dev/agones/pkg/util/httpserver" "github.com/heptiolabs/healthcheck" prom "github.com/prometheus/client_golang/prometheus" "go.opencensus.io/plugin/ocgrpc" @@ -33,7 +32,7 @@ func registerMetricViews() { } } -func setupMetricsRecorder(conf config) (health healthcheck.Handler, closer func()) { +func setupMetricsRecorder(conf config, healthserver *httpserver.Server) (health healthcheck.Handler, closer func()) { health = healthcheck.NewHandler() closer = func() {} @@ -54,7 +53,7 @@ func setupMetricsRecorder(conf config) (health healthcheck.Handler, closer func( if err != nil { logger.WithError(err).Fatal("Could not register prometheus exporter") } - http.Handle("/metrics", metricHandler) + healthserver.Handle("/metrics", metricHandler) health = healthcheck.NewMetricsHandler(registry, "agones") }