From 00ec6a2cfce1f051efeae16b269dd991ef50d465 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Wed, 23 Nov 2022 11:53:19 +0000 Subject: [PATCH] Pre-flight requests to server /api/* endpoints Before serving /api requests, make a 'pre-flight' request to `/api/feature-flags/slow-database` and use the `X-Gitpod-Slow-Database` header in the response to decide where to send the actual request; either to the regular `server` service or the new `slow-server` service. --- components/proxy/conf/Caddyfile | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/components/proxy/conf/Caddyfile b/components/proxy/conf/Caddyfile index 8b7016d3821880..7d57aa6a5a795a 100644 --- a/components/proxy/conf/Caddyfile +++ b/components/proxy/conf/Caddyfile @@ -235,10 +235,30 @@ https://{$GITPOD_DOMAIN} { base_domain {$GITPOD_DOMAIN} } - # note: no compression, as that breaks streaming for headless logs + forward_auth server.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:3000 { + uri /feature-flags/slow-database + copy_headers X-Gitpod-Slow-Database + } + + @slow { + header X-Gitpod-Slow-Database "true" + } + + @fast { + not header X-Gitpod-Slow-Database "true" + } uri strip_prefix /api - reverse_proxy server.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:3000 { + + reverse_proxy @fast server.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:3000 { + import upstream_headers + import upstream_connection + + # required for smooth streaming of terminal logs + flush_interval -1 + } + + reverse_proxy @slow slow-server.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:3000 { import upstream_headers import upstream_connection