-
Notifications
You must be signed in to change notification settings - Fork 12
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
Return timing data in response header(s) #438
Conversation
src/frontend/http.rs
Outdated
@@ -53,6 +53,7 @@ const BEARER_PREFIX: &str = "Bearer "; | |||
// We have a very lax CORS on this, so we don't mind browsers | |||
// caching it for as long as possible. | |||
const CORS_MAXAGE: u32 = 86400; | |||
const RUNTIME_HEADER: &str = "X-Seafowl-Runtime"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Runtime sounds weird to me in this context, maybe something like:
const RUNTIME_HEADER: &str = "X-Seafowl-Runtime"; | |
const QUERY_TIME_HEADER: &str = "X-Seafowl-Query-Time"; |
Also, there's the matter of CORS-safelisted headers that @milesrichardson raised in the original issue. I'm fine with having this info be in a separate header (i.e. not in Content-Type
), but we'd probably need to specify Access-Control-Expose-Headers
as well then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unfortunate thing about needing to specify Access-Control-Expose-Headers
is that there can only be one header Access-Control-Expose-Headers
, with a value containing a comma-separated list of exposed headers. That means that if we have two areas of the codebase that each add their own header, then they need to somehow be aware of the current value when merging theirs into the list - which makes for messier code. Also, if someone is running a proxy in front of Seafowl, then they need to perform similar logic if they want to add their own headers to the list.
Fwiw, I don't think this should be configurable (not for now at least); there are more pertinent knobs that still aren't customizable (e.g. see #50), and I'm wary of bloating up the config with less important items. I think just extending the existing tests should be sufficient to merge this. |
Thanks Marko, yes probably too soon to add new config options. In the future depending how we want to allow user customization e.g. once we return >1 timing measurement, it will presumably be time to consider. I will switch to
IIUC I think @mildbyte prefers option 1, and @milesrichardson prefers option 2. (at least, I had that impression based on MM chats.) What do you think @gruuya? |
- Adopt `X-Seafowl-Runtime` header - TODO: make it configurable - TODO: confirm that this is measuring what we want it to measure
- Decided to stick with one metric for now, so rename accordingly
- Improve safety by wrapping with Option - Apparently old Rust versions could panic when time "went backwards" in the OS, hopefully using types will help safeguard against that. - Optionally return a raw .elapsed(), or use formatted_elapsed() which is suitable for headers (Probably wasteful to return `ms` in every response)
440bf6a
to
1931ab2
Compare
- Add a Default attribute - Accept linter changes
I would prefer option 1 (always) too. But just note that it won't always be available to client code in a cross-origin browsing context unless the header is included in the CSV value of But I'm hesitant to always return I had originally said that the timing data shouldn't go into the So another question would be: what response headers does Cloudflare save in its cached objects? We know that it saves @gruuya @mildbyte What do you think about including the timing data in the |
f963c1d
to
c836955
Compare
Is this what you had in mind? Wasn't sure if you meant literally extending some already existing test, or adding to the existing test suite. If there's some recommended way to hit both |
One thing I just learned is that apparently even default CORS safelisted headers have some prerequisites:
In our case we have @milesrichardson given this, and the fact that @onpaws discovered some handy DataFusion-provided internal metrics (which we may want to supplement along with the request-to-response time as is done currently), I'd vote for going with a separate dedicated header (assuming that it is cached by CF). |
Cloudflare seems to cache a lot of response headers, if not all of them. This screenshot is from one of our pages with the cache disabled in Firefox and with a Cloudflare cache hit, showing X-Cache and X-Varnish headers (that are added by our own Varnish) being returned by Cloudflare in its cached response: |
Read that a bit more carefully: those restrictions are for the request |
Oh damn, good catch :D |
- Also add a test helper to testutils.rs
Ended up doing this approach, cheers. Agreed checking the header is "as expected" is worthwhile and added a second test for that. Verified the tests work by temporarily commenting out the header injection code, and re-running, and got the expected result. before/afterthe "before" test run, expected to fail b/c I commented out the header code
the "after" run
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments from a fellow Rust enthusiast, feel free to ignore them, since they're mostly about the API of the newly added Timer
- Previously we wrapped with Option, per the warnings at https://doc.rust-lang.org/src/std/time.rs.html#86 - After code review perhaps the fact we still call .unwrap() obviates the benefit anyway, thus dropped.
CI passed and it seems we've probably reviewed this PR sufficiently. Any objections to merging? |
I haven't reviewed the code (and don't intend to), but once you merge it, can you update the docs in the marketing repo to reference the header? |
Thanks Marko! Merging now |
Seeks to implement #357
X-Seafowl-Runtime
(currently hardcoded)seafowl.toml
, or at theINFO
/DEBUG
level, or some other way[1] https://www.w3.org/TR/server-timing/
[2] https://arrow.apache.org/datafusion/user-guide/sql/explain.html