diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-06-20 22:41:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-20 22:41:50 +0200 |
commit | fc1604631cb71e1df1affb4c0980b9d166501ccd (patch) | |
tree | a41e9300cbcdb234cd113549649ba23c94b84d85 /container-core | |
parent | bad536f44f5f0f62eb6fd2df8783dfedd71f6022 (diff) | |
parent | 8e4148724284d27c0dd99d8b7d2753df400abc95 (diff) |
Merge pull request #23174 from vespa-engine/bjorncs/health-check-proxy
Bjorncs/health check proxy
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/HealthCheckProxyHandler.java | 39 |
1 files changed, 17 insertions, 22 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 97ea30b3867..a40d8acacef 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 @@ -33,6 +33,7 @@ import java.util.Map; import java.util.Optional; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -182,6 +183,8 @@ class HealthCheckProxyHandler extends HandlerWrapper { private StatusResponse getStatusResponse() { try { var request = client().newRequest("https://localhost:" + port + HEALTH_CHECK_PATH); + request.timeout(timeout.toMillis(), TimeUnit.MILLISECONDS); + request.idleTimeout(timeout.toMillis(), TimeUnit.MILLISECONDS); if (proxyProtocol) { request.tag(new ProxyProtocolClientConnectionFactory.V1.Tag()); } @@ -204,18 +207,18 @@ class HealthCheckProxyHandler extends HandlerWrapper { synchronized (this) { if (client == null) { int timeoutMillis = (int) timeout.toMillis(); - SslContextFactory.Client clientSsl = new SslContextFactory.Client(); - clientSsl.setHostnameVerifier((__, ___) -> true); - clientSsl.setSslContext(getSslContext(serverSsl)); - HttpClient client = new HttpClient(clientSsl); - client.setMaxConnectionsPerDestination(4); - client.setConnectTimeout(timeoutMillis); - client.setStopTimeout(timeoutMillis); - client.setIdleTimeout(timeoutMillis); - client.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, "health-check-proxy-client")); - client.start(); - this.client = client; - } + SslContextFactory.Client clientSsl = new SslContextFactory.Client(); + clientSsl.setHostnameVerifier((__, ___) -> true); + clientSsl.setSslContext(getSslContext(serverSsl)); + HttpClient client = new HttpClient(clientSsl); + client.setMaxConnectionsPerDestination(4); + client.setConnectTimeout(timeoutMillis); + client.setStopTimeout(timeoutMillis); + client.setIdleTimeout(timeoutMillis); + client.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, "health-check-proxy-client")); + client.start(); + this.client = client; + } } } return client; @@ -256,18 +259,10 @@ class HealthCheckProxyHandler extends HandlerWrapper { } } - private static class StatusResponse { - final long createdAt = System.nanoTime(); - final int statusCode; - final String contentType; - final byte[] content; - + private record StatusResponse(long createdAt, int statusCode, String contentType, byte[] content) { StatusResponse(int statusCode, String contentType, byte[] content) { - this.statusCode = statusCode; - this.contentType = contentType; - this.content = content; + this(System.nanoTime(), statusCode, contentType, content); } - boolean isExpired() { return System.nanoTime() - createdAt > Duration.ofSeconds(1).toNanos(); } } } |