Skip to content

Commit

Permalink
chore: add comments on the Observation module
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Nov 15, 2024
1 parent 9237fb8 commit 6919816
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/PostgREST/Logger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ middleware logLevel getAuthRole = case logLevel of
, Wai.destination = Wai.Handle stdout
}

-- All observations are logged except some that depend on the log-level
observationLogger :: LoggerState -> LogLevel -> ObservationHandler
observationLogger loggerState logLevel obs = case obs of
o@(PoolAcqTimeoutObs _) -> do
Expand Down
5 changes: 5 additions & 0 deletions src/PostgREST/Metrics.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{-|
Module : PostgREST.Logger
Description : Metrics based on the Observation module. See Observation.hs.
-}
module PostgREST.Metrics
( init
, MetricsState (..)
Expand Down Expand Up @@ -28,6 +32,7 @@ init configDbPoolSize = do
setGauge poolMaxSize (fromIntegral configDbPoolSize)
pure $ MetricsState poolTimeouts poolAvailable poolWaiting poolMaxSize schemaCacheLoads schemaCacheQueryTime

-- Only some observations are used as metrics
observationMetrics :: MetricsState -> ObservationHandler
observationMetrics (MetricsState poolTimeouts poolAvailable poolWaiting _ schemaCacheLoads schemaCacheQueryTime) obs = case obs of
(PoolAcqTimeoutObs _) -> do
Expand Down
4 changes: 3 additions & 1 deletion src/PostgREST/Observation.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{-# LANGUAGE LambdaCase #-}
{-|
Module : PostgREST.Observation
Description : Observations that can be used for Logging and Metrics
Description : This module holds an Observation type which is the core of Observability for PostgREST.
The Observation is an abstraction that avoids scattering logging messages and metrics across the codebase.
The Logger and Metrics modules decide which observations to expose. Not all observations need to be logged nor all correspond to a metric.
-}
module PostgREST.Observation
( Observation(..)
Expand Down

0 comments on commit 6919816

Please sign in to comment.