From 32396bc8219ab5fdc465a85f59323d5f54a7c798 Mon Sep 17 00:00:00 2001 From: Grzegorz Zagata Date: Thu, 23 Nov 2023 07:58:05 +0100 Subject: [PATCH] rewrite 502 as 503 --- .../com/ing/wbaa/rokku/proxy/api/ProxyService.scala | 11 ++++++++++- .../rokku/proxy/api/directive/ProxyDirectives.scala | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/ing/wbaa/rokku/proxy/api/ProxyService.scala b/src/main/scala/com/ing/wbaa/rokku/proxy/api/ProxyService.scala index 82ca9e0a..7bab41f8 100644 --- a/src/main/scala/com/ing/wbaa/rokku/proxy/api/ProxyService.scala +++ b/src/main/scala/com/ing/wbaa/rokku/proxy/api/ProxyService.scala @@ -17,7 +17,9 @@ import com.ing.wbaa.rokku.proxy.provider.aws.AwsErrorCodes import java.util.UUID import java.util.concurrent.TimeUnit +import scala.concurrent.Await import scala.concurrent.{ ExecutionContext, Future } +import scala.concurrent.duration.Duration import scala.util.{ Failure, Success } trait ProxyService { @@ -132,9 +134,16 @@ trait ProxyService { updateHeadersForRequest(httpRequest) { newHttpRequest => val httpResponse = executeRequest(newHttpRequest, userSTS, s3Request).andThen { case Success(response: HttpResponse) => + logger.debug("Got response from S3 with headers: {}", response.headers) handlePostRequestActions(response, httpRequest, s3Request, userSTS) } - complete(httpResponse) + val evaluatedResponse = Await.result(httpResponse, Duration("60 seconds")) + if (evaluatedResponse.status == StatusCodes.BadGateway) { + logger.debug("Got 502, rewriting as 503 to indicate S3 overload") + throw new RokkuThrottlingException("Got 502, rewriting as 503") + } + logger.debug("Got response from S3 other then 502, returning it to user") + complete(evaluatedResponse) } } diff --git a/src/main/scala/com/ing/wbaa/rokku/proxy/api/directive/ProxyDirectives.scala b/src/main/scala/com/ing/wbaa/rokku/proxy/api/directive/ProxyDirectives.scala index afae21e6..872f331e 100644 --- a/src/main/scala/com/ing/wbaa/rokku/proxy/api/directive/ProxyDirectives.scala +++ b/src/main/scala/com/ing/wbaa/rokku/proxy/api/directive/ProxyDirectives.scala @@ -235,6 +235,7 @@ object ProxyDirectives extends LazyLogging { RawHeader("Access-Control-Allow-Headers", "*")) ++ oldHeaders } } else { + logger.debug("Wont add CORS, request: {}", request) pass } }