fix: log on LISTEN notification
This commit is contained in:
committed by
Steve Chavez
parent
47b70b8329
commit
ee8b3ef8fe
+1
-1
@@ -24,7 +24,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #3237, Dump media handlers and timezones with --dump-schema - @wolfgangwalther
|
- #3237, Dump media handlers and timezones with --dump-schema - @wolfgangwalther
|
||||||
- #3323, #3324, Don't hide error on LISTEN channel failure - @steve-chavez
|
- #3323, #3324, Don't hide error on LISTEN channel failure - @steve-chavez
|
||||||
- #3330, Incorrect admin server `/ready` response on slow schema cache loads - @steve-chavez
|
- #3330, Incorrect admin server `/ready` response on slow schema cache loads - @steve-chavez
|
||||||
- #3327, Fix slow responses on schema cache reloads - @steve-chavez
|
- #3340, Log when the LISTEN channel gets a notification - @steve-chavez
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE LambdaCase #-}
|
{-# LANGUAGE LambdaCase #-}
|
||||||
|
{-# LANGUAGE MultiWayIf #-}
|
||||||
{-# LANGUAGE NamedFieldPuns #-}
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
|
|
||||||
@@ -501,6 +502,7 @@ listener appState observer = do
|
|||||||
putIsListenerOn appState True
|
putIsListenerOn appState True
|
||||||
SQL.listen db $ SQL.toPgIdentifier dbChannel
|
SQL.listen db $ SQL.toPgIdentifier dbChannel
|
||||||
SQL.waitForNotifications handleNotification db
|
SQL.waitForNotifications handleNotification db
|
||||||
|
|
||||||
Left err -> do
|
Left err -> do
|
||||||
observer $ DBListenerFail dbChannel err
|
observer $ DBListenerFail dbChannel err
|
||||||
exitFailure
|
exitFailure
|
||||||
@@ -517,11 +519,11 @@ listener appState observer = do
|
|||||||
-- retry the listener
|
-- retry the listener
|
||||||
listener appState observer
|
listener appState observer
|
||||||
|
|
||||||
handleNotification _ msg
|
handleNotification channel msg =
|
||||||
| BS.null msg = cacheReloader
|
if | BS.null msg -> observer (DBListenerGotSCacheMsg channel) >> cacheReloader
|
||||||
| msg == "reload schema" = cacheReloader
|
| msg == "reload schema" -> observer (DBListenerGotSCacheMsg channel) >> cacheReloader
|
||||||
| msg == "reload config" = reReadConfig False appState observer
|
| msg == "reload config" -> observer (DBListenerGotConfigMsg channel) >> reReadConfig False appState observer
|
||||||
| otherwise = pure () -- Do nothing if anything else than an empty message is sent
|
| otherwise -> pure () -- Do nothing if anything else than an empty message is sent
|
||||||
|
|
||||||
cacheReloader =
|
cacheReloader =
|
||||||
-- reloads the schema cache + restarts pool connections
|
-- reloads the schema cache + restarts pool connections
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ data Observation
|
|||||||
| DBListenerStart Text
|
| DBListenerStart Text
|
||||||
| DBListenerFail Text SQL.ConnectionError
|
| DBListenerFail Text SQL.ConnectionError
|
||||||
| DBListenerFailRecoverObs Bool Text (Either SomeException ())
|
| DBListenerFailRecoverObs Bool Text (Either SomeException ())
|
||||||
|
| DBListenerGotSCacheMsg ByteString
|
||||||
|
| DBListenerGotConfigMsg ByteString
|
||||||
| ConfigReadErrorObs
|
| ConfigReadErrorObs
|
||||||
| ConfigReadErrorFatalObs SQL.UsageError Text
|
| ConfigReadErrorFatalObs SQL.UsageError Text
|
||||||
| ConfigReadErrorNotFatalObs SQL.UsageError
|
| ConfigReadErrorNotFatalObs SQL.UsageError
|
||||||
@@ -82,11 +84,15 @@ observationMessage = \case
|
|||||||
ConnectionPgVersionErrorObs usageErr ->
|
ConnectionPgVersionErrorObs usageErr ->
|
||||||
jsonMessage usageErr
|
jsonMessage usageErr
|
||||||
DBListenerStart channel -> do
|
DBListenerStart channel -> do
|
||||||
"Listening for notifications on the " <> channel <> " channel"
|
"Listening for notifications on the " <> show channel <> " channel"
|
||||||
DBListenerFail channel err -> do
|
DBListenerFail channel err -> do
|
||||||
"Could not listen for notifications on the " <> channel <> " channel. " <> show err
|
"Could not listen for notifications on the " <> channel <> " channel. " <> show err
|
||||||
DBListenerFailRecoverObs recover channel err ->
|
DBListenerFailRecoverObs recover channel err ->
|
||||||
"Could not listen for notifications on the " <> channel <> " channel. " <> showListenerError err <> (if recover then " Retrying listening for notifications.." else mempty)
|
"Could not listen for notifications on the " <> channel <> " channel. " <> showListenerError err <> (if recover then " Retrying listening for notifications.." else mempty)
|
||||||
|
DBListenerGotSCacheMsg channel ->
|
||||||
|
"Received a schema cache reload message on the " <> show channel <> " channel"
|
||||||
|
DBListenerGotConfigMsg channel ->
|
||||||
|
"Received a config reload message on the " <> show channel <> " channel"
|
||||||
ConfigReadErrorObs ->
|
ConfigReadErrorObs ->
|
||||||
"An error ocurred when trying to query database settings for the config parameters"
|
"An error ocurred when trying to query database settings for the config parameters"
|
||||||
ConfigReadErrorFatalObs usageErr hint ->
|
ConfigReadErrorFatalObs usageErr hint ->
|
||||||
|
|||||||
@@ -421,6 +421,8 @@ def test_invalid_role_claim_key_notify_reload(defaultenv):
|
|||||||
with run(env=env) as postgrest:
|
with run(env=env) as postgrest:
|
||||||
postgrest.session.post("/rpc/invalid_role_claim_key_reload")
|
postgrest.session.post("/rpc/invalid_role_claim_key_reload")
|
||||||
|
|
||||||
|
output = postgrest.read_stdout()
|
||||||
|
assert 'Received a config reload message on the "pgrst" channel' in output[0]
|
||||||
output = postgrest.read_stdout()
|
output = postgrest.read_stdout()
|
||||||
assert "failed to parse role-claim-key value" in output[0]
|
assert "failed to parse role-claim-key value" in output[0]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user