summaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HealthCheckProxyHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HealthCheckProxyHandler.java')
-rw-r--r--container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HealthCheckProxyHandler.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HealthCheckProxyHandler.java b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HealthCheckProxyHandler.java
index ae2871e266d..dd9bc9a14a5 100644
--- a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HealthCheckProxyHandler.java
+++ b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HealthCheckProxyHandler.java
@@ -63,7 +63,9 @@ class HealthCheckProxyHandler extends HandlerWrapper {
ConnectorConfig.HealthCheckProxy proxyConfig = connector.connectorConfig().healthCheckProxy();
if (proxyConfig.enable()) {
Duration targetTimeout = Duration.ofMillis((int) (proxyConfig.clientTimeout() * 1000));
- mapping.put(connector.listenPort(), createProxyTarget(proxyConfig.port(), targetTimeout, connectors));
+ Duration cacheExpiry = Duration.ofMillis((int) (proxyConfig.cacheExpiry() * 1000));
+ ProxyTarget target = createProxyTarget(proxyConfig.port(), targetTimeout, cacheExpiry, connectors);
+ mapping.put(connector.listenPort(), target);
log.info(String.format("Port %1$d is configured as a health check proxy for port %2$d. " +
"HTTP requests to '%3$s' on %1$d are proxied as HTTPS to %2$d.",
connector.listenPort(), proxyConfig.port(), HEALTH_CHECK_PATH));
@@ -72,7 +74,8 @@ class HealthCheckProxyHandler extends HandlerWrapper {
return mapping;
}
- private static ProxyTarget createProxyTarget(int targetPort, Duration targetTimeout, List<JDiscServerConnector> connectors) {
+ private static ProxyTarget createProxyTarget(int targetPort, Duration targetTimeout, Duration cacheExpiry,
+ List<JDiscServerConnector> connectors) {
JDiscServerConnector targetConnector = connectors.stream()
.filter(connector -> connector.listenPort() == targetPort)
.findAny()
@@ -85,7 +88,7 @@ class HealthCheckProxyHandler extends HandlerWrapper {
.orElseThrow(() -> new IllegalArgumentException("Health check proxy can only target https port"));
ConnectorConfig.ProxyProtocol proxyProtocolCfg = targetConnector.connectorConfig().proxyProtocol();
boolean proxyProtocol = proxyProtocolCfg.enabled() && !proxyProtocolCfg.mixedMode();
- return new ProxyTarget(targetPort, targetTimeout, sslContextFactory, proxyProtocol);
+ return new ProxyTarget(targetPort, targetTimeout, cacheExpiry, sslContextFactory, proxyProtocol);
}
@Override
@@ -160,21 +163,24 @@ class HealthCheckProxyHandler extends HandlerWrapper {
private static class ProxyTarget implements AutoCloseable {
final int port;
final Duration timeout;
+ final Duration cacheExpiry;
final SslContextFactory.Server serverSsl;
final boolean proxyProtocol;
volatile HttpClient client;
volatile StatusResponse lastResponse;
- ProxyTarget(int port, Duration timeout, SslContextFactory.Server serverSsl, boolean proxyProtocol) {
+ ProxyTarget(int port, Duration timeout, Duration cacheExpiry, SslContextFactory.Server serverSsl,
+ boolean proxyProtocol) {
this.port = port;
this.timeout = timeout;
+ this.cacheExpiry = cacheExpiry;
this.serverSsl = serverSsl;
this.proxyProtocol = proxyProtocol;
}
StatusResponse requestStatusHtml() {
StatusResponse response = lastResponse;
- if (response != null && !response.isExpired()) {
+ if (response != null && !response.isExpired(cacheExpiry)) {
return response;
}
return this.lastResponse = getStatusResponse();
@@ -271,6 +277,6 @@ class HealthCheckProxyHandler extends HandlerWrapper {
this.content = content;
}
- boolean isExpired() { return System.nanoTime() - createdAt > Duration.ofSeconds(1).toNanos(); }
+ boolean isExpired(Duration expiry) { return System.nanoTime() - createdAt > expiry.toNanos(); }
}
}