Skip to content

nix(test): add test suite for observability tests#4732

Merged
steve-chavez merged 1 commit intoPostgREST:mainfrom
taimoorzaeem:nix/postgrest-test-obs
Mar 19, 2026
Merged

nix(test): add test suite for observability tests#4732
steve-chavez merged 1 commit intoPostgREST:mainfrom
taimoorzaeem:nix/postgrest-test-obs

Conversation

@taimoorzaeem
Copy link
Copy Markdown
Member

  • Create separate test suite for observability tests

  • Create wrapper script postgrest-test-observability

  • Add to CI and postgrest-check

  • Move JWT cache tests under observability tests

As discussed in #4671 (comment).

@taimoorzaeem taimoorzaeem marked this pull request as draft March 18, 2026 07:24
@taimoorzaeem taimoorzaeem marked this pull request as ready for review March 18, 2026 07:50
@taimoorzaeem taimoorzaeem added the nix related to Nix tooling label Mar 18, 2026
@taimoorzaeem taimoorzaeem marked this pull request as draft March 18, 2026 11:40
@taimoorzaeem taimoorzaeem force-pushed the nix/postgrest-test-obs branch from 2d48d58 to 0108cb6 Compare March 18, 2026 15:37
@taimoorzaeem taimoorzaeem marked this pull request as ready for review March 18, 2026 15:48
Copy link
Copy Markdown
Member

@steve-chavez steve-chavez Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at our current

spec :: SpecWith (MetricsState, Application)

It is indeed purely tested in terms of metrics, so I agree in that it fits here.

Comment on lines +31 to +109
baseCfg :: AppConfig
baseCfg = let secret = encodeUtf8 "reallyreallyreallyreallyverysafe" in
AppConfig {
configAppSettings = []
, configClientErrorVerbosity = Verbose
, configDbAggregates = False
, configDbAnonRole = Just "postgrest_test_anonymous"
, configDbChannel = mempty
, configDbChannelEnabled = True
, configDbExtraSearchPath = []
, configDbHoistedTxSettings = ["default_transaction_isolation","plan_filter.statement_cost_limit","statement_timeout"]
, configDbMaxRows = Nothing
, configDbPlanEnabled = False
, configDbPoolSize = 10
, configDbPoolAcquisitionTimeout = 10
, configDbPoolMaxLifetime = 1800
, configDbPoolMaxIdletime = 600
, configDbPoolAutomaticRecovery = True
, configDbPreRequest = Nothing
, configDbPreparedStatements = True
, configDbRootSpec = Nothing
, configDbSchemas = fromList ["test"]
, configDbConfig = False
, configDbPreConfig = Nothing
, configDbUri = "postgresql://"
, configFilePath = Nothing
, configJWKS = rightToMaybe $ parseSecret secret
, configJwtAudience = Nothing
, configJwtRoleClaimKey = [JSPKey "role"]
, configJwtSecret = Just secret
, configJwtSecretIsBase64 = False
, configJwtCacheMaxEntries = 10
, configLogLevel = LogCrit
, configLogQuery = False
, configOpenApiMode = OAFollowPriv
, configOpenApiSecurityActive = False
, configOpenApiServerProxyUri = Nothing
, configServerCorsAllowedOrigins = Nothing
, configServerHost = "localhost"
, configServerPort = 3000
, configServerTraceHeader = Nothing
, configServerUnixSocket = Nothing
, configServerUnixSocketMode = 432
, configDbTxAllowOverride = True
, configDbTxRollbackAll = True
, configAdminServerHost = "localhost"
, configAdminServerPort = Nothing
, configRoleSettings = mempty
, configRoleIsoLvl = mempty
, configInternalSCQuerySleep = Nothing
, configInternalSCLoadSleep = Nothing
, configInternalSCRelLoadSleep = Nothing
, configServerTimingEnabled = True
}

testCfg :: AppConfig
testCfg = baseCfg

testCfgJwtCache :: AppConfig
testCfgJwtCache =
baseCfg {
configJwtSecret = Just generateSecret
, configJWKS = rightToMaybe $ parseSecret generateSecret
, configJwtCacheMaxEntries = 2
}

authHeader :: BS.ByteString -> BS.ByteString -> Header
authHeader typ creds =
(hAuthorization, typ <> " " <> creds)

authHeaderJWT :: BS.ByteString -> Header
authHeaderJWT = authHeader "Bearer"

generateSecret :: ByteString
generateSecret = B64.decodeLenient "cmVhbGx5cmVhbGx5cmVhbGx5cmVhbGx5dmVyeXNhZmU="

generateJWT :: BL.ByteString -> ByteString
generateJWT claims =
either mempty JWT.unJwt $ JWT.hmacEncode JWT.HS256 generateSecret (BL.toStrict claims)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there's duplication here but don't have a good idea on how to solve right now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I feel the same way. I believe the long term solution would be to come with some sort of internal helper library of functions, but that would be too much for now.

- Create separate test suite for observability tests

- Create wrapper script `postgrest-test-observability`

- Add to CI and `postgrest-check`

- Move JWT cache tests under observability tests

Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
@taimoorzaeem taimoorzaeem force-pushed the nix/postgrest-test-obs branch from 0108cb6 to 0678896 Compare March 19, 2026 02:34
@steve-chavez steve-chavez merged commit 12ef633 into PostgREST:main Mar 19, 2026
34 checks passed
@taimoorzaeem taimoorzaeem deleted the nix/postgrest-test-obs branch March 19, 2026 18:11
@taimoorzaeem
Copy link
Copy Markdown
Member Author

taimoorzaeem commented Mar 19, 2026

I think we should backport this so future fixes apply cleanly using our backport action.

To backport this, we first need to backport #4659 and maybe more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nix related to Nix tooling

Development

Successfully merging this pull request may close these issues.

2 participants