Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions src/main/java/org/prebid/cache/handlers/GetCacheHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

@Component
@Slf4j
Expand Down Expand Up @@ -113,23 +114,30 @@ private String resolveCacheUrl(final ServerRequest request) {
private Mono<ServerResponse> processProxyRequest(final ServerRequest request,
final String idKeyParam,
final String cacheUrl) {

final var webClient = clientsCache.computeIfAbsent(cacheUrl, WebClient::create);
final boolean isFirstConnection = !clientsCache.containsKey(cacheUrl);
final WebClient webClient = clientsCache.computeIfAbsent(cacheUrl, WebClient::create);

return webClient.get()
.uri(uriBuilder -> uriBuilder.queryParam(ID_KEY, idKeyParam).build())
.headers(httpHeaders -> httpHeaders.addAll(request.headers().asHttpHeaders()))
.exchange()
.transform(CircuitBreakerOperator.of(circuitBreaker))
.timeout(Duration.ofMillis(config.getTimeoutMs()))
.subscribeOn(Schedulers.parallel())
.handle(this::updateProxyMetrics)
.flatMap(GetCacheHandler::fromClientResponse)
.doOnError(error -> {
metricsRecorder.getProxyFailure().increment();
log.info("Failed to send request: '{}', cause: '{}'",
ExceptionUtils.getMessage(error), ExceptionUtils.getMessage(error));
});
.uri(uriBuilder -> uriBuilder.queryParam(ID_KEY, idKeyParam).build())
.headers(httpHeaders -> httpHeaders.addAll(request.headers().asHttpHeaders()))
.exchange()
.transform(CircuitBreakerOperator.of(circuitBreaker))
.timeout(Duration.ofMillis(config.getTimeoutMs()))
.subscribeOn(Schedulers.parallel())
.handle(this::updateProxyMetrics)
.flatMap(GetCacheHandler::fromClientResponse)
.doOnError(error -> {
metricsRecorder.getProxyFailure().increment();
if (error instanceof TimeoutException) {
log.info(
"The proxy request from {} to {} failed due to the timeout (the first connection = {})",
request.uri(),
cacheUrl,
isFirstConnection);
}
log.info("Failed to send request: '{}', cause: '{}'",
ExceptionUtils.getMessage(error), ExceptionUtils.getMessage(error));
});
}

private void updateProxyMetrics(final ClientResponse clientResponse,
Expand Down