fix: log db-schemas and db-extra-search-path in schema cache load error (#4108)
This commit is contained in:
+3
-1
@@ -8,7 +8,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix jwt error returning HTTP status `400` for invalid role by @taimoorzaeem in #3601
|
- Fix jwt error returning HTTP status `400` for invalid role by @taimoorzaeem in #3601
|
||||||
- Allow `db-extra-search-path` to accept empty value by @taimoorzaeem in #4074
|
- Fix `db-extra-search-path` cannot be set to nothing by @taimoorzaeem in #4074
|
||||||
|
+ It can now be disabled by setting it to empty string.
|
||||||
|
+ Schema Cache load error is now logged including `db-schemas` and `db-extra-search-path` config values.
|
||||||
|
|
||||||
## [13.0.0] - 2025-05-08
|
## [13.0.0] - 2025-05-08
|
||||||
|
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ retryingSchemaCacheLoad appState@AppState{stateObserver=observer, stateMainThrea
|
|||||||
Left e -> do
|
Left e -> do
|
||||||
putSCacheStatus appState SCPending
|
putSCacheStatus appState SCPending
|
||||||
putSchemaCache appState Nothing
|
putSchemaCache appState Nothing
|
||||||
observer $ SchemaCacheErrorObs e
|
observer $ SchemaCacheErrorObs configDbSchemas configDbExtraSearchPath e
|
||||||
return Nothing
|
return Nothing
|
||||||
|
|
||||||
Right sCache -> do
|
Right sCache -> do
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ dumpSchema appState = do
|
|||||||
case result of
|
case result of
|
||||||
Left e -> do
|
Left e -> do
|
||||||
let observer = AppState.getObserver appState
|
let observer = AppState.getObserver appState
|
||||||
observer $ SchemaCacheErrorObs e
|
observer $ SchemaCacheErrorObs configDbSchemas configDbExtraSearchPath e
|
||||||
exitFailure
|
exitFailure
|
||||||
Right sCache -> return $ JSON.encode sCache
|
Right sCache -> return $ JSON.encode sCache
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ observationMetrics (MetricsState poolTimeouts poolAvailable poolWaiting _ schema
|
|||||||
SchemaCacheLoadedObs resTime -> do
|
SchemaCacheLoadedObs resTime -> do
|
||||||
withLabel schemaCacheLoads "SUCCESS" incCounter
|
withLabel schemaCacheLoads "SUCCESS" incCounter
|
||||||
setGauge schemaCacheQueryTime resTime
|
setGauge schemaCacheQueryTime resTime
|
||||||
SchemaCacheErrorObs _ -> do
|
SchemaCacheErrorObs{} -> do
|
||||||
withLabel schemaCacheLoads "FAIL" incCounter
|
withLabel schemaCacheLoads "FAIL" incCounter
|
||||||
_ ->
|
_ ->
|
||||||
pure ()
|
pure ()
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ module PostgREST.Observation
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy as LBS
|
import qualified Data.ByteString.Lazy as LBS
|
||||||
|
import Data.List.NonEmpty (toList)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as T
|
import qualified Data.Text.Encoding as T
|
||||||
import qualified Hasql.Connection as SQL
|
import qualified Hasql.Connection as SQL
|
||||||
@@ -25,7 +26,7 @@ import Numeric (showFFloat)
|
|||||||
import PostgREST.Config.PgVersion
|
import PostgREST.Config.PgVersion
|
||||||
import qualified PostgREST.Error as Error
|
import qualified PostgREST.Error as Error
|
||||||
|
|
||||||
import Protolude
|
import Protolude hiding (toList)
|
||||||
import Protolude.Partial (fromJust)
|
import Protolude.Partial (fromJust)
|
||||||
|
|
||||||
data Observation
|
data Observation
|
||||||
@@ -37,7 +38,7 @@ data Observation
|
|||||||
| ExitDBNoRecoveryObs
|
| ExitDBNoRecoveryObs
|
||||||
| ExitDBFatalError ObsFatalError SQL.UsageError
|
| ExitDBFatalError ObsFatalError SQL.UsageError
|
||||||
| DBConnectedObs Text
|
| DBConnectedObs Text
|
||||||
| SchemaCacheErrorObs SQL.UsageError
|
| SchemaCacheErrorObs (NonEmpty Text) [Text] SQL.UsageError
|
||||||
| SchemaCacheQueriedObs Double
|
| SchemaCacheQueriedObs Double
|
||||||
| SchemaCacheSummaryObs Text
|
| SchemaCacheSummaryObs Text
|
||||||
| SchemaCacheLoadedObs Double
|
| SchemaCacheLoadedObs Double
|
||||||
@@ -88,8 +89,12 @@ observationMessage = \case
|
|||||||
"If you are using connection poolers in transaction mode, try setting db-prepared-statements to false. " <> jsonMessage usageErr
|
"If you are using connection poolers in transaction mode, try setting db-prepared-statements to false. " <> jsonMessage usageErr
|
||||||
ExitDBFatalError ServerError08P01 usageErr ->
|
ExitDBFatalError ServerError08P01 usageErr ->
|
||||||
"Connection poolers in statement mode are not supported." <> jsonMessage usageErr
|
"Connection poolers in statement mode are not supported." <> jsonMessage usageErr
|
||||||
SchemaCacheErrorObs usageErr ->
|
SchemaCacheErrorObs dbSchemas extraPaths usageErr ->
|
||||||
"Failed to load the schema cache. " <> jsonMessage usageErr
|
"Failed to load the schema cache using "
|
||||||
|
<> "db-schemas=" <> T.intercalate "," (toList dbSchemas)
|
||||||
|
<> " and "
|
||||||
|
<> "db-extra-search-path=" <> T.intercalate "," extraPaths
|
||||||
|
<> ". " <> jsonMessage usageErr
|
||||||
SchemaCacheQueriedObs resultTime ->
|
SchemaCacheQueriedObs resultTime ->
|
||||||
"Schema cache queried in " <> showMillis resultTime <> " milliseconds"
|
"Schema cache queried in " <> showMillis resultTime <> " milliseconds"
|
||||||
SchemaCacheSummaryObs summary ->
|
SchemaCacheSummaryObs summary ->
|
||||||
|
|||||||
@@ -1909,3 +1909,23 @@ def test_allow_configs_to_be_set_to_empty(defaultenv):
|
|||||||
with run(env=env) as postgrest:
|
with run(env=env) as postgrest:
|
||||||
response = postgrest.session.get("/projects")
|
response = postgrest.session.get("/projects")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_schema_cache_error_observation(defaultenv):
|
||||||
|
"schema cache error observation should be logged with invalid db-schemas or db-extra-search-path"
|
||||||
|
|
||||||
|
env = {
|
||||||
|
**defaultenv,
|
||||||
|
"PGRST_DB_EXTRA_SEARCH_PATH": "x",
|
||||||
|
}
|
||||||
|
|
||||||
|
with run(env=env, no_startup_stdout=False, wait_for_readiness=False) as postgrest:
|
||||||
|
# TODO: postgrest should exit here, instead it keeps retrying
|
||||||
|
# exitCode = wait_until_exit(postgrest)
|
||||||
|
# assert exitCode == 1
|
||||||
|
|
||||||
|
output = postgrest.read_stdout(nlines=9)
|
||||||
|
assert (
|
||||||
|
"Failed to load the schema cache using db-schemas=public and db-extra-search-path=x"
|
||||||
|
in output[7]
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user