diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index d06a5967d3..b4a75b777d 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -159,7 +159,7 @@ postgrestResponse appState conf@AppConfig{..} maybeSchemaCache pgVer authResult@ liftEither . mapLeft Error.ApiRequestError $ ApiRequest.userApiRequest conf req body sCache - let jwtTiming = (SMJwt, if configDbPlanEnabled then Auth.getJwtDur req else Nothing) + let jwtTiming = (SMJwt, if configServerTimingEnabled then Auth.getJwtDur req else Nothing) handleRequest authResult conf appState (Just authRole /= configDbAnonRole) configDbPreparedStatements pgVer apiRequest sCache jwtTiming runDbHandler :: AppState.AppState -> SQL.IsolationLevel -> SQL.Mode -> Bool -> Bool -> DbHandler b -> Handler IO b @@ -256,9 +256,9 @@ handleRequest AuthResult{..} conf appState authenticated prepared pgVer apiReq@A query pgrstResponse :: ServerTimingData -> Response.PgrstResponse -> Wai.Response - pgrstResponse timings (Response.PgrstResponse st hdrs bod) = Wai.responseLBS st (hdrs ++ ([renderServerTimingHeader timings | configDbPlanEnabled conf])) bod + pgrstResponse timings (Response.PgrstResponse st hdrs bod) = Wai.responseLBS st (hdrs ++ ([renderServerTimingHeader timings | configServerTimingEnabled conf])) bod - withTiming f = if configServerTiming conf + withTiming f = if configServerTimingEnabled conf then do (t, r) <- timeItT f pure (Just t, r) diff --git a/src/PostgREST/Auth.hs b/src/PostgREST/Auth.hs index 35096e138e..ec30950793 100644 --- a/src/PostgREST/Auth.hs +++ b/src/PostgREST/Auth.hs @@ -109,7 +109,7 @@ middleware appState app req respond = do -- If DbPlanEnabled -> calculate JWT validation time -- If JwtCacheMaxLifetime -> cache JWT validation result - req' <- case (configDbPlanEnabled conf, configJwtCacheMaxLifetime conf) of + req' <- case (configServerTimingEnabled conf, configJwtCacheMaxLifetime conf) of (True, 0) -> do (dur, authResult) <- timeItT parseJwt return $ req { Wai.vault = Wai.vault req & Vault.insert authResultKey authResult & Vault.insert jwtDurKey dur } diff --git a/src/PostgREST/Config.hs b/src/PostgREST/Config.hs index ae2de8faa8..af1238d7f6 100644 --- a/src/PostgREST/Config.hs +++ b/src/PostgREST/Config.hs @@ -104,7 +104,7 @@ data AppConfig = AppConfig , configServerHost :: Text , configServerPort :: Int , configServerTraceHeader :: Maybe (CI.CI BS.ByteString) - , configServerTiming :: Bool + , configServerTimingEnabled :: Bool , configServerUnixSocket :: Maybe FilePath , configServerUnixSocketMode :: FileMode , configAdminServerPort :: Maybe Int @@ -170,6 +170,7 @@ toText conf = ,("server-host", q . configServerHost) ,("server-port", show . configServerPort) ,("server-trace-header", q . T.decodeUtf8 . maybe mempty CI.original . configServerTraceHeader) + ,("server-timing-enabled", T.toLower . show . configServerTimingEnabled) ,("server-unix-socket", q . maybe mempty T.pack . configServerUnixSocket) ,("server-unix-socket-mode", q . T.pack . showSocketMode) ,("admin-server-port", maybe "\"\"" show . configAdminServerPort) diff --git a/test/io/configs/expected/aliases.config b/test/io/configs/expected/aliases.config index 7182a8989f..bb67b29648 100644 --- a/test/io/configs/expected/aliases.config +++ b/test/io/configs/expected/aliases.config @@ -30,6 +30,7 @@ server-cors-allowed-origins = "" server-host = "!4" server-port = 3000 server-trace-header = "" +server-timing-enabled = false server-unix-socket = "" server-unix-socket-mode = "660" admin-server-port = "" diff --git a/test/io/configs/expected/boolean-numeric.config b/test/io/configs/expected/boolean-numeric.config index 1c931a50e9..9bd66476dc 100644 --- a/test/io/configs/expected/boolean-numeric.config +++ b/test/io/configs/expected/boolean-numeric.config @@ -30,6 +30,7 @@ server-cors-allowed-origins = "" server-host = "!4" server-port = 3000 server-trace-header = "" +server-timing-enabled = false server-unix-socket = "" server-unix-socket-mode = "660" admin-server-port = "" diff --git a/test/io/configs/expected/boolean-string.config b/test/io/configs/expected/boolean-string.config index 1c931a50e9..9bd66476dc 100644 --- a/test/io/configs/expected/boolean-string.config +++ b/test/io/configs/expected/boolean-string.config @@ -30,6 +30,7 @@ server-cors-allowed-origins = "" server-host = "!4" server-port = 3000 server-trace-header = "" +server-timing-enabled = false server-unix-socket = "" server-unix-socket-mode = "660" admin-server-port = "" diff --git a/test/io/configs/expected/defaults.config b/test/io/configs/expected/defaults.config index 76ca1a26ff..30168ee149 100644 --- a/test/io/configs/expected/defaults.config +++ b/test/io/configs/expected/defaults.config @@ -30,6 +30,7 @@ server-cors-allowed-origins = "" server-host = "!4" server-port = 3000 server-trace-header = "" +server-timing-enabled = false server-unix-socket = "" server-unix-socket-mode = "660" admin-server-port = "" diff --git a/test/io/configs/expected/no-defaults-with-db-other-authenticator.config b/test/io/configs/expected/no-defaults-with-db-other-authenticator.config index 9fd08d0fd9..d5bbfe3cd0 100644 --- a/test/io/configs/expected/no-defaults-with-db-other-authenticator.config +++ b/test/io/configs/expected/no-defaults-with-db-other-authenticator.config @@ -30,6 +30,7 @@ server-cors-allowed-origins = "http://example.com" server-host = "0.0.0.0" server-port = 80 server-trace-header = "traceparent" +server-timing-enabled = false server-unix-socket = "/tmp/pgrst_io_test.sock" server-unix-socket-mode = "777" admin-server-port = 3001 diff --git a/test/io/configs/expected/no-defaults-with-db.config b/test/io/configs/expected/no-defaults-with-db.config index ccb1056408..01004ec2dd 100644 --- a/test/io/configs/expected/no-defaults-with-db.config +++ b/test/io/configs/expected/no-defaults-with-db.config @@ -30,6 +30,7 @@ server-cors-allowed-origins = "http://example.com" server-host = "0.0.0.0" server-port = 80 server-trace-header = "CF-Ray" +server-timing-enabled = false server-unix-socket = "/tmp/pgrst_io_test.sock" server-unix-socket-mode = "777" admin-server-port = 3001 diff --git a/test/io/configs/expected/no-defaults.config b/test/io/configs/expected/no-defaults.config index ca09c08c81..33325b7dda 100644 --- a/test/io/configs/expected/no-defaults.config +++ b/test/io/configs/expected/no-defaults.config @@ -30,6 +30,7 @@ server-cors-allowed-origins = "http://example.com" server-host = "0.0.0.0" server-port = 80 server-trace-header = "X-Request-Id" +server-timing-enabled = false server-unix-socket = "/tmp/pgrst_io_test.sock" server-unix-socket-mode = "777" admin-server-port = 3001 diff --git a/test/io/configs/expected/types.config b/test/io/configs/expected/types.config index ef698ba1a1..d7d6429312 100644 --- a/test/io/configs/expected/types.config +++ b/test/io/configs/expected/types.config @@ -30,6 +30,7 @@ server-cors-allowed-origins = "" server-host = "!4" server-port = 3000 server-trace-header = "" +server-timing-enabled = false server-unix-socket = "" server-unix-socket-mode = "660" admin-server-port = "" diff --git a/test/io/test_io.py b/test/io/test_io.py index 60d6eb8de7..9209463d13 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -1158,7 +1158,7 @@ def test_jwt_caching_works_with_db_plan_disabled(defaultenv): env = { **defaultenv, - "PGRST_DB_PLAN_ENABLED": "false", + "PGRST_SERVER_TIMING_ENABLED": "true", "PGRST_JWT_CACHE_MAX_LIFETIME": "86400", "PGRST_JWT_SECRET": "@/dev/stdin", "PGRST_DB_CONFIG": "false",