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

fix: reduce warm up time #72

Merged
merged 14 commits into from
Oct 23, 2023
23 changes: 20 additions & 3 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ resource "google_compute_region_network_endpoint_group" "default" {
resource "google_compute_global_address" "default" {
project = var.project_id
name = "${var.deployment_name}-reserved-ip"
depends_on = [
time_sleep.project_services
]
}

resource "google_compute_url_map" "default" {
Expand Down Expand Up @@ -290,12 +293,26 @@ resource "google_compute_global_forwarding_rule" "http" {
labels = var.labels
}

resource "time_sleep" "load_balancer_warm_up_time" {
# It may take more than 2 minutes for the newly provisioned load balancer
# to forward requests to the Cloud Run service. The following data source
# allows for terraform apply to finish running when the end-point resolves

data "http" "load_balancer_warm_up" {
url = "http://${google_compute_global_address.default.address}/"
# Attempt retry every 20 seconds 17 times, totaling to a 6 minute timeout.
Copy link
Contributor

Choose a reason for hiding this comment

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

question: why 6 minutes? Depending on the answer, that may be good to add to the inline comment because it would help future maintainers understand how to repeat the reasoning if the number should be changed in the future.

retry {
attempts = 17
max_delay_ms = 20000
min_delay_ms = 20000
}
Comment on lines +303 to +307
Copy link
Contributor

Choose a reason for hiding this comment

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

discussion: Was curious if there were any surprises here, I think these parameters are likely being used with https://github.com/hashicorp/go-retryablehttp/blob/v0.7.4/client.go#L520C23-L520C23. Based on my reading, min_delay_ms would not normally be linear, but setting the max to the same value caps the exponential computation.

No op here, just thought that may be interesting if others haven't delved that far.

# Begin trying after load balancer resources are created.
depends_on = [
google_compute_global_address.default,
google_compute_url_map.default,
google_compute_backend_service.default,
Copy link
Contributor

Choose a reason for hiding this comment

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

note: google_compute_url_map.default should have an implicit dependency on google_compute_backend_service.default if you want one fewer explicit dependency here, but clarifying we're waiting on all the load balancer resources may be a good thing given how complicated this is.

Alright, I've talked myself out of this being a suggestion and made it a "note".

google_compute_target_http_proxy.default,
google_compute_global_forwarding_rule.http
]

create_duration = "370s"
}

### Firestore ###
Expand Down
2 changes: 1 addition & 1 deletion infra/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

output "frontend_url" {
description = "IP address to site. Load balancer expected to take ~5 minutes for it to warm up."
value = "http://${google_compute_global_address.default.address}/"
value = data.http.load_balancer_warm_up.url
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: Nice simplification of the output configuration based on the http data.

}

output "neos_toc_url" {
Expand Down
Loading