Skip to content

Commit

Permalink
Fix allocator metrics endpoint (#3921)
Browse files Browse the repository at this point in the history
* updated metrics to use healthserver instead of default mux to create the tcp connection
  • Loading branch information
vicentefb authored Jul 29, 2024
1 parent 1ebec58 commit 7222876
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions cmd/allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) }()

Expand Down
7 changes: 3 additions & 4 deletions cmd/allocator/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {}

Expand All @@ -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")
}

Expand Down

0 comments on commit 7222876

Please sign in to comment.