From afb04fa390630335013f365a742faf5afbff587a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Choutri=20de=20Tarl=C3=A9?= Date: Thu, 26 Dec 2024 16:25:56 +0100 Subject: [PATCH] [FLORA-235] Re-enable prometheus metrics for http & process resources (#802) --- changelog.d/801 | 2 ++ flora.cabal | 10 +++++++--- src/web/FloraWeb/Server.hs | 12 +++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 changelog.d/801 diff --git a/changelog.d/801 b/changelog.d/801 new file mode 100644 index 000000000..4a02ed14b --- /dev/null +++ b/changelog.d/801 @@ -0,0 +1,2 @@ +synopsis: Re-enable prometheus metrics for http & process resources +prs: #802 diff --git a/flora.cabal b/flora.cabal index 8a365b31d..671ccbca8 100644 --- a/flora.cabal +++ b/flora.cabal @@ -27,13 +27,13 @@ flag prod common common-extensions default-extensions: - NoStarIsType DataKinds DeriveAnyClass DerivingStrategies DerivingVia DuplicateRecordFields LambdaCase + NoStarIsType OverloadedLabels OverloadedRecordDot OverloadedStrings @@ -347,7 +347,7 @@ library flora-web build-depends: , aeson , async - , base ^>=4.18.2 + , base ^>=4.18.2 , base32 , bytestring , Cabal-syntax @@ -381,13 +381,16 @@ library flora-web , mtl , network-uri , odd-jobs - , one-time-password ==3.0.0.0 + , one-time-password ==3.0.0.0 , openapi3 , optics-core , pg-entity , pg-transact-effectful , postgresql-simple , pretty + , prometheus-client + , prometheus-metrics-ghc + , prometheus-proc , PyF , raven-haskell , resource-pool @@ -411,6 +414,7 @@ library flora-web , wai-app-static , wai-log , wai-middleware-heartbeat + , wai-middleware-prometheus , warp , xml-conduit , xml-conduit-writer diff --git a/src/web/FloraWeb/Server.hs b/src/web/FloraWeb/Server.hs index 925a269df..3bee43a9a 100644 --- a/src/web/FloraWeb/Server.hs +++ b/src/web/FloraWeb/Server.hs @@ -33,10 +33,14 @@ import Network.Wai.Handler.Warp ) import Network.Wai.Log qualified as WaiLog import Network.Wai.Middleware.Heartbeat (heartbeatMiddleware) +import Network.Wai.Middleware.Prometheus qualified as P import OddJobs.Endpoints qualified as OddJobs import OddJobs.Job (startJobRunner) import OddJobs.Types qualified as OddJobs import Optics.Core +import Prometheus qualified as P +import Prometheus.Metric.GHC qualified as P +import Prometheus.Metric.Proc qualified as P import Sel import Servant ( Application @@ -106,6 +110,10 @@ runFlora = let baseURL = "http://localhost:" <> display env.httpPort liftIO $ blueMessage $ "🌺 Starting Flora server on " <> baseURL liftIO $ when (isJust env.mltp.sentryDSN) (blueMessage "📋 Connecting to Sentry endpoint") + liftIO $ when env.mltp.prometheusEnabled $ do + blueMessage $ "🔥 Exposing Prometheus metrics at " <> baseURL <> "/metrics" + void $ P.register P.ghcMetrics + void $ P.register P.procMetrics liftIO $ when env.mltp.zipkinEnabled (blueMessage "🖊️ Connecting to Zipkin endpoint") liftIO $ when (env.environment == Development) (blueMessage "🔁 Live reloading enabled") let withLogger = Logging.makeLogger env.mltp.logger @@ -169,7 +177,9 @@ runServer appLogger floraEnv = do $ heartbeatMiddleware . loggingMiddleware . const - $ server + $ P.prometheus + P.def + server mkServer :: Logger