Skip to content
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

Implement ctile #7

Merged
merged 23 commits into from
Aug 31, 2023
Merged

Implement ctile #7

merged 23 commits into from
Aug 31, 2023

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Aug 31, 2023

nota bene: land this change using the "rebase" method, so that these initial commits are preserved

jsha and others added 17 commits August 31, 2023 12:05
This adds context.Context to the various client calls made by the proxy
to enable deadlining, cancellation, and other handy things. This doesn't
choose a top-level request timeout, but allows for one to be set in
another PR.
Using the previous context code, apply some timeouts to ensure the HTTP
server stays up under traffic.

This weaves a default 4 second per-request timeout through the handler.
This timeout covers how long it takes the HTTP handler to return data
from S3 (if it exists) or to discover the tile isn't in S3, fetch the
tile data from S3 the backend, and write it before returning. This is
configurable.

This also sets the basic HTTP server timeouts that are required for
healthy Go HTTP servers. Those aren't configurable.

A good summary of Go's HTTP server timeouts and why they're needed can
be found at https://blog.cloudflare.com/exposing-go-on-the-internet/

The `TimeoutHandler` sets the timeout on the `http.Request`'s context,
so we can use `r.Context()` in the handler to propagate the deadline to
the S3 and HTTP clients.

The values for the timeouts were chosen arbitrarily but from values that
I understand to be safe for public consumption. The
`full-request-timeout` default is the one most likely to need a change
depending on how far from S3 this server is hosted (or if the work to
write to S3 is moved to a background goroutine or whatever).

Future work: Given that we're using `http.Server` directly now, it might
be time to break out the handler func as a top-level function but I
leave that for a possible follow-up.
Qualify the S3 key by the backend URL and the tile size.

Also, keep track of the backend URL in the `tile` object.
Also add -s3-prefix override (defaults to -backend)
This moves the HTTP code out of the main func and into its own type
called `tileCachingHandler`. It's a simple refactoring that adds some
fields to the new struct to keep the pattern of adding flags in main.
Copy link

@aarongable aarongable left a comment

Choose a reason for hiding this comment

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

Generally LGTM, I didn't spot any bugs. Just a few nits and organizational comments/questions.

.github/workflows/test.yml Outdated Show resolved Hide resolved
main.go Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
jsha and others added 4 commits August 31, 2023 13:25
Trillian only applies the align_getentries tweak for "maximally sized" requests, so CTile using a tile size smaller than max_get_entries is fine.

Co-authored-by: Preston Locke <me@prestonlocke.net>
Copy link

@aarongable aarongable left a comment

Choose a reason for hiding this comment

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

Huzzah for closed intervals and off-by-one errors.

@@ -4,7 +4,7 @@ on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches: '*'

Choose a reason for hiding this comment

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

You want ** so that it matches branches with / in their name

Suggested change
branches: '*'
branches: '**'

@jsha jsha merged commit 30ee926 into main Aug 31, 2023
1 check passed
@jsha jsha deleted the wip branch August 31, 2023 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants