-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Server-Timing header with JWT duration #2937
Conversation
2c04650
to
60fe59c
Compare
@taimoorzaeem Interesting feature! So I've been playing a bit with it and I've noticed that: $ PGRST_JWT_SECRET="reallyreallyreallyreallyverysafe" PGRST_DB_PLAN_ENABLED="true" postgrest-with-postgresql-15 postgrest-run export JWT="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjk5OTk5OTk5OTksInJvbGUiOiJwb3N0Z3Jlc3RfdGVzdF9hdXRob3IiLCJpZCI6Impkb2UiLCJhdWQiOiJ5b3VyYXVkaW
VuY2UifQ.fJ4tLKSmolWGWehWN20qiU9dMO-WY0RI2VvacL7-ZGo"
$ curl 'localhost:3000/authors_only' -H "Authorization: Bearer $JWT" -D -
HTTP/1.1 200 OK
Server-Timing: jwt;dur=335.1
$ curl 'localhost:3000/authors_only' -H "Authorization: Bearer $JWT" -D -
HTTP/1.1 200 OK
Server-Timing: jwt;dur=147.7
$ curl 'localhost:3000/authors_only' -H "Authorization: Bearer $JWT" -D -
HTTP/1.1 200 OK
Server-Timing: jwt;dur=145.9
$ curl 'localhost:3000/authors_only' -H "Authorization: Bearer $JWT" -D -
Server-Timing: jwt;dur=146.2
# restarting the postgrest server
$ curl 'localhost:3000/authors_only' -H "Authorization: Bearer $JWT" -D -
HTTP/1.1 200 OK
Server-Timing: jwt;dur=327.1
$ curl 'localhost:3000/authors_only' -H "Authorization: Bearer $JWT" -D -
HTTP/1.1 200 OK
Server-Timing: jwt;dur=141.3
$ curl 'localhost:3000/authors_only' -H "Authorization: Bearer $JWT" -D -
HTTP/1.1 200 OK
Server-Timing: jwt;dur=143.9
$ curl 'localhost:3000/authors_only' -H "Authorization: Bearer $JWT" -D -
HTTP/1.1 200 OK
Server-Timing: jwt;dur=142.5 The first jwt decode always takes longer than the subsequent ones. Is this because of laziness? Related: #2450 |
@taimoorzaeem Also please rebase. Sorry, I wanted to do the refactoring for completing all the other durations (#2771 (comment)) but I got carried away and did other changes. |
Strange that the idempotence test fails. Maybe some mutations on the new tests are not rolled back (which is the default for all tests |
60fe59c
to
7bd2128
Compare
Hmm, I'll get into it. Would that be okay to test this using strict evaluation using |
7bd2128
to
8fb88e1
Compare
Yeah, not necessary to be strict. I mostly wanted to check if it's really because of laziness and why would it take more than double the time the first time. On #2450, it's clear it takes a while because the schema cache loading is an expensive process. On this case I don't know what initialization takes place. |
I think this is more than just mutations not being rollbacked. For instance:
Where is the |
8fb88e1
to
7b5eb8d
Compare
7b5eb8d
to
ee265de
Compare
I just tested and I observe the same thing. I wondered whether that was only the case with the same JWT token or also with different ones: It's the same, even when using different JWTs between requests. The first one will always be significantly slower. Any tests for the jwt caching feature will need to take this into account. They'd basically need a "warmup" before doing any testing. |
@taimoorzaeem Btw, could we make the JWT evaluation stricter with bang patterns?
Pros of doing this:
|
Hmm, I tried |
Part of #2771.