refactor: Remove unnecessary SQL.UsageError parameter from PoolAcqTimeoutObs

PoolAcqTimeoutObs is always created with SQL.AcquisitionTimeoutUsageError so the parameter does not provide any useful information.
On the other hand, it complicates debouncing logic in Logger as logWithDebounce has to lazily create the debouncer (which is error prone and hence the logic has a race condition).

This change removes the parameter from PoolAcqTimeoutObs. It is a prerequisite to simplifying logWithDebounce.
This commit is contained in:
Michał Kłeczek
2026-02-15 13:14:10 -05:00
committed by Steve Chavez
parent c5d495006a
commit d6816d8d2a
4 changed files with 5 additions and 6 deletions
+1 -1
View File
@@ -222,7 +222,7 @@ usePool AppState{stateObserver=observer, stateMainThreadId=mainThreadId, ..} ses
whenLeft res (\case whenLeft res (\case
SQL.AcquisitionTimeoutUsageError -> SQL.AcquisitionTimeoutUsageError ->
observer $ PoolAcqTimeoutObs SQL.AcquisitionTimeoutUsageError observer PoolAcqTimeoutObs
err@(SQL.ConnectionUsageError e) -> err@(SQL.ConnectionUsageError e) ->
let failureMessage = BS.unpack $ fromMaybe mempty e in let failureMessage = BS.unpack $ fromMaybe mempty e in
when (("FATAL: password authentication failed" `isInfixOf` failureMessage) || ("no password supplied" `isInfixOf` failureMessage)) $ do when (("FATAL: password authentication failed" `isInfixOf` failureMessage) || ("no password supplied" `isInfixOf` failureMessage)) $ do
+1 -1
View File
@@ -88,7 +88,7 @@ shouldLogResponse logLevel = case logLevel of
-- All observations are logged except some that depend on the log-level -- All observations are logged except some that depend on the log-level
observationLogger :: LoggerState -> LogLevel -> ObservationHandler observationLogger :: LoggerState -> LogLevel -> ObservationHandler
observationLogger loggerState logLevel obs = case obs of observationLogger loggerState logLevel obs = case obs of
o@(PoolAcqTimeoutObs _) -> do o@PoolAcqTimeoutObs -> do
when (logLevel >= LogError) $ do when (logLevel >= LogError) $ do
logWithDebounce loggerState $ logWithDebounce loggerState $
logWithZTime loggerState $ observationMessage o logWithZTime loggerState $ observationMessage o
+1 -1
View File
@@ -50,7 +50,7 @@ init configDbPoolSize = do
-- Only some observations are used as metrics -- Only some observations are used as metrics
observationMetrics :: MetricsState -> ObservationHandler observationMetrics :: MetricsState -> ObservationHandler
observationMetrics MetricsState{..} obs = case obs of observationMetrics MetricsState{..} obs = case obs of
(PoolAcqTimeoutObs _) -> do PoolAcqTimeoutObs -> do
incCounter poolTimeouts incCounter poolTimeouts
(HasqlPoolObs (SQL.ConnectionObservation _ status)) -> case status of (HasqlPoolObs (SQL.ConnectionObservation _ status)) -> case status of
SQL.ReadyForUseConnectionStatus -> do SQL.ReadyForUseConnectionStatus -> do
+2 -3
View File
@@ -59,7 +59,7 @@ data Observation
| QueryErrorCodeHighObs SQL.UsageError | QueryErrorCodeHighObs SQL.UsageError
| QueryPgVersionError SQL.UsageError | QueryPgVersionError SQL.UsageError
| PoolInit Int | PoolInit Int
| PoolAcqTimeoutObs SQL.UsageError | PoolAcqTimeoutObs
| HasqlPoolObs SQL.Observation | HasqlPoolObs SQL.Observation
| PoolRequest | PoolRequest
| PoolRequestFullfilled | PoolRequestFullfilled
@@ -140,8 +140,7 @@ observationMessage = \case
"Config reloaded" "Config reloaded"
PoolInit poolSize -> PoolInit poolSize ->
"Connection Pool initialized with a maximum size of " <> show poolSize <> " connections" "Connection Pool initialized with a maximum size of " <> show poolSize <> " connections"
PoolAcqTimeoutObs usageErr -> PoolAcqTimeoutObs -> jsonMessage SQL.AcquisitionTimeoutUsageError
jsonMessage usageErr
HasqlPoolObs (SQL.ConnectionObservation uuid status) -> HasqlPoolObs (SQL.ConnectionObservation uuid status) ->
"Connection " <> show uuid <> ( "Connection " <> show uuid <> (
case status of case status of