From 4d8bb7251292792492d476c61d60f34ee413a0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszko?= Date: Tue, 13 Aug 2024 13:10:13 +0200 Subject: [PATCH 1/2] Fix /metrics for cluster-only mode We still need to have the `/metrics` endpoint to report the catalyst-api version used inside catalyst --- api/http_internal.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/api/http_internal.go b/api/http_internal.go index 586af70f1..9587e0b66 100644 --- a/api/http_internal.go +++ b/api/http_internal.go @@ -5,6 +5,7 @@ import ( "bytes" "context" "database/sql" + "github.com/prometheus/client_golang/prometheus/promhttp" "net/http" "net/http/httptest" "time" @@ -26,7 +27,6 @@ import ( "github.com/livepeer/catalyst-api/middleware" "github.com/livepeer/catalyst-api/pipeline" "github.com/livepeer/go-api-client" - "github.com/prometheus/client_golang/prometheus/promhttp" ) func ListenAndServeInternal(ctx context.Context, cli config.Cli, vodEngine *pipeline.Coordinator, mapic mistapiconnector.IMac, bal balancer.Balancer, c cluster.Cluster, broker misttriggers.TriggerBroker, metricsDB *sql.DB, serfMembersEndpoint, eventsEndpoint string) error { @@ -84,8 +84,9 @@ func NewCatalystAPIRouterInternal(cli config.Cli, vodEngine *pipeline.Coordinato // Simple endpoint for healthchecks router.GET("/ok", withLogging(catalystApiHandlers.Ok())) + var metricsHandlers []http.Handler + if cli.IsApiMode() { - var metricsHandlers []http.Handler if cli.ShouldMapic() { metricsHandlers = append(metricsHandlers, mapic.MetricsHandler()) } @@ -93,9 +94,6 @@ func NewCatalystAPIRouterInternal(cli config.Cli, vodEngine *pipeline.Coordinato // Enable Mist metrics enrichment metricsHandlers = append(metricsHandlers, mapic.MistMetricsHandler()) } - metricsHandlers = append(metricsHandlers, promhttp.Handler()) - // Hacky combined metrics handler. To be refactored away with mapic. - router.GET("/metrics", concatHandlers(metricsHandlers...)) // Public Catalyst API router.POST("/api/vod", @@ -132,6 +130,10 @@ func NewCatalystAPIRouterInternal(cli config.Cli, vodEngine *pipeline.Coordinato router.POST("/api/serf/receiveUserEvent", withLogging(eventsHandler.ReceiveUserEvent())) } + metricsHandlers = append(metricsHandlers, promhttp.Handler()) + // Hacky combined metrics handler. To be refactored away with mapic. + router.GET("/metrics", concatHandlers(metricsHandlers...)) + if cli.IsClusterMode() { // Temporary endpoint for admin queries router.GET("/admin/members", withLogging(adminHandlers.MembersHandler())) From 8409d8fce07a25d0dbb23d43466c2b62f57736ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Leszko?= Date: Tue, 13 Aug 2024 13:12:52 +0200 Subject: [PATCH 2/2] Fix imports --- api/http_internal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/http_internal.go b/api/http_internal.go index 9587e0b66..4ed6cb022 100644 --- a/api/http_internal.go +++ b/api/http_internal.go @@ -5,7 +5,6 @@ import ( "bytes" "context" "database/sql" - "github.com/prometheus/client_golang/prometheus/promhttp" "net/http" "net/http/httptest" "time" @@ -27,6 +26,7 @@ import ( "github.com/livepeer/catalyst-api/middleware" "github.com/livepeer/catalyst-api/pipeline" "github.com/livepeer/go-api-client" + "github.com/prometheus/client_golang/prometheus/promhttp" ) func ListenAndServeInternal(ctx context.Context, cli config.Cli, vodEngine *pipeline.Coordinator, mapic mistapiconnector.IMac, bal balancer.Balancer, c cluster.Cluster, broker misttriggers.TriggerBroker, metricsDB *sql.DB, serfMembersEndpoint, eventsEndpoint string) error {