From 8ea24b289045ee841136cb29fd599c75241d8de6 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Fri, 19 Apr 2024 23:00:15 -0500 Subject: [PATCH] feat: schema cache metrics --- src/PostgREST/Metrics.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/PostgREST/Metrics.hs b/src/PostgREST/Metrics.hs index cbf56e03b23..d22dcf0e504 100644 --- a/src/PostgREST/Metrics.hs +++ b/src/PostgREST/Metrics.hs @@ -1,5 +1,4 @@ -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE NumericUnderscores #-} +{-# LANGUAGE NamedFieldPuns #-} module PostgREST.Metrics ( init , MetricsState (..) @@ -21,6 +20,8 @@ data MetricsState = MetricsState , poolAvailable :: Prom.Gauge , poolWaiting :: Prom.Gauge , poolMaxSize :: Prom.Gauge + , schemaCacheLoads :: Prom.Counter + , schemaCacheQueryTime :: Prom.Gauge } init :: Int -> IO MetricsState @@ -29,11 +30,13 @@ init poolMaxSize = do available <- Prom.register $ Prom.gauge (Prom.Info "pgrst_db_pool_available" "Available connections in the pool") waiting <- Prom.register $ Prom.gauge (Prom.Info "pgrst_db_pool_waiting" "Requests waiting to acquire a pool connection") maxSize <- Prom.register $ Prom.gauge (Prom.Info "pgrst_db_pool_max" "Max pool connections") + sCacheLoads <- Prom.register $ Prom.counter (Prom.Info "pgrst_schema_cache_loads_total" "The total number of times the schema cache was loaded") + sCacheQTime <- Prom.register $ Prom.gauge (Prom.Info "pgrst_schema_cache_query_time_seconds" "The query time in seconds of the last schema cache load") Prom.setGauge maxSize (fromIntegral poolMaxSize) - pure $ MetricsState timeouts available waiting maxSize + pure $ MetricsState timeouts available waiting maxSize sCacheLoads sCacheQTime observationMetrics :: MetricsState -> ObservationHandler -observationMetrics MetricsState{poolTimeouts, poolAvailable, poolWaiting} obs = case obs of +observationMetrics MetricsState{poolTimeouts, poolAvailable, poolWaiting, schemaCacheLoads, schemaCacheQueryTime} obs = case obs of (PoolAcqTimeoutObs _) -> do Prom.incCounter poolTimeouts (HasqlPoolObs (SQL.ConnectionObservation _ status)) -> case status of @@ -48,6 +51,9 @@ observationMetrics MetricsState{poolTimeouts, poolAvailable, poolWaiting} obs = Prom.incGauge poolWaiting PoolRequestFullfilled -> Prom.decGauge poolWaiting + SchemaCacheLoadedObs resTime -> do + Prom.incCounter schemaCacheLoads + Prom.setGauge schemaCacheQueryTime resTime _ -> pure ()