From ebe985e51bebe7d50bf292ab4574c1c8cc619679 Mon Sep 17 00:00:00 2001 From: maura fortino Date: Wed, 13 Dec 2023 11:25:36 -0500 Subject: [PATCH] added basic coreendpoints --- main.go | 4 ++-- metrics.go | 2 +- routes.go | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 3b51550a..41e7ebcf 100644 --- a/main.go +++ b/main.go @@ -135,8 +135,8 @@ func caduceus(arguments []string, run bool) error { arrangehttp.ProvideServer("servers.health"), arrangehttp.ProvideServer("servers.metrics"), arrangehttp.ProvideServer("servers.pprof"), - // arrangehttp.ProvideServer("servers.primary"), - // arrangehttp.ProvideServer("servers.alternate"), + arrangehttp.ProvideServer("servers.primary"), + arrangehttp.ProvideServer("servers.alternate"), touchstone.Provide(), touchhttp.Provide(), diff --git a/metrics.go b/metrics.go index 668ecd37..731f9579 100644 --- a/metrics.go +++ b/metrics.go @@ -76,7 +76,7 @@ func NewMetricWrapperMeasures(m CaduceusMetricsRegistry) metrics.Histogram { // TODO: do these need to be annonated/broken into groups based on where the metrics are being used/called func ProvideMetrics() fx.Option { - return fx.Provide( + return fx.Options( touchstone.Gauge(prometheus.GaugeOpts{ Name: IncomingQueueDepth, Help: "The depth of the queue behind the incoming handlers.", diff --git a/routes.go b/routes.go index ef96fe62..3ca50c54 100644 --- a/routes.go +++ b/routes.go @@ -43,13 +43,27 @@ func provideCoreEndpoints() fx.Option { }, func(in RoutesIn) RoutesOut { return RoutesOut{ - // Primary: provideCoreOption("primary", in), - // Alternate: provideCoreOption("alternate", in), + Primary: provideCoreOption("primary", in), + Alternate: provideCoreOption("alternate", in), } }, ) } +func provideCoreOption(server string, in RoutesIn) arrangehttp.Option[http.Server] { + return arrangehttp.AsOption[http.Server]( + func(s *http.Server) { + mux := chi.NewMux() + if server == "primary" { + s.Handler = in.PrimaryMetrics.Then(mux) + } else { + s.Handler = in.AlternateMetrics.Then(mux) + } + }, + ) + +} + func provideHealthCheck() fx.Option { return fx.Provide( fx.Annotated{