@@ -29,6 +29,7 @@ import qualified Feature.Auth.NoJwtSecretSpec
2929import qualified Feature.ConcurrentSpec
3030import qualified Feature.CorsSpec
3131import qualified Feature.ExtraSearchPathSpec
32+ import qualified Feature.MetricsSpec
3233import qualified Feature.NoSuperuserSpec
3334import qualified Feature.ObservabilitySpec
3435import qualified Feature.OpenApi.DisabledOpenApiSpec
@@ -68,16 +69,23 @@ import qualified Feature.Query.UpdateSpec
6869import qualified Feature.Query.UpsertSpec
6970import qualified Feature.RollbackSpec
7071import qualified Feature.RpcPreRequestGucsSpec
72+ import PostgREST.Observation (Observation (HasqlPoolObs ))
7173
7274
7375main :: IO ()
7476main = do
77+ poolChan <- newChan
78+ -- make sure poolChan is not growing indefinitely
79+ void $ forkIO $ fix (readChan poolChan *> )
80+ metricsState <- Metrics. init (configDbPoolSize testCfg)
7581 pool <- P. acquire $ P. settings
7682 [ P. size 3
7783 , P. acquisitionTimeout 10
7884 , P. agingTimeout 60
7985 , P. idlenessTimeout 60
8086 , P. staticConnectionSettings (toUtf8 $ configDbUri testCfg)
87+ -- make sure metrics are updated and pool observations published to poolChan
88+ , P. observationHandler $ (writeChan poolChan <> Metrics. observationMetrics metricsState) . HasqlPoolObs
8189 ]
8290
8391 actualPgVersion <- either (panic . show ) id <$> P. use pool (queryPgVersion False )
@@ -86,7 +94,6 @@ main = do
8694 baseSchemaCache <- loadSCache pool testCfg
8795 sockets <- AppState. initSockets testCfg
8896 loggerState <- Logger. init
89- metricsState <- Metrics. init (configDbPoolSize testCfg)
9097
9198 let
9299 initApp sCache st config = do
@@ -95,6 +102,14 @@ main = do
95102 AppState. putSchemaCache appState (Just sCache)
96103 return (st, postgrest (configLogLevel config) appState (pure () ))
97104
105+ initObservationsApp sCache config = do
106+ -- duplicate poolChan as a starting point
107+ obsChan <- dupChan poolChan
108+ appState <- AppState. initWithPool sockets pool config loggerState metricsState (Metrics. observationMetrics metricsState <> writeChan obsChan)
109+ AppState. putPgVersion appState actualPgVersion
110+ AppState. putSchemaCache appState (Just sCache)
111+ return (((appState, metricsState), obsChan), postgrest (configLogLevel config) appState (pure () ))
112+
98113 -- For tests that run with the same schema cache
99114 app = initApp baseSchemaCache ()
100115
@@ -123,6 +138,7 @@ main = do
123138 obsApp = app testObservabilityCfg
124139 serverTiming = app testCfgServerTiming
125140 aggregatesEnabled = app testCfgAggregatesEnabled
141+ observationsApp = initObservationsApp baseSchemaCache testCfg
126142
127143 extraSearchPathApp = appDbs testCfgExtraSearchPath
128144 unicodeApp = appDbs testUnicodeCfg
@@ -278,6 +294,12 @@ main = do
278294 before (initApp baseSchemaCache metricsState testCfgJwtCache) $
279295 describe " Feature.Auth.JwtCacheSpec" Feature.Auth.JwtCacheSpec. spec
280296
297+ before (initApp baseSchemaCache metricsState testCfgJwtCache) $
298+ describe " Feature.Auth.JwtCacheSpec" Feature.Auth.JwtCacheSpec. spec
299+
300+ before observationsApp $
301+ describe " Feature.MetricsSpec" Feature.MetricsSpec. spec
302+
281303 where
282304 loadSCache pool conf =
283305 either (panic. show ) id <$> P. use pool (HT. transaction HT. ReadCommitted HT. Read $ querySchemaCache conf)
0 commit comments