Skip to content

Commit

Permalink
use newer retry handler, configurable number of retries
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Aug 20, 2024
1 parent 7058d64 commit 50e64b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/main/java/io/cryostat/agent/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public abstract class ConfigModule {
public static final Pattern CRYOSTAT_AGENT_TRUSTSTORE_PATTERN =
Pattern.compile(
"^(?:cryostat\\.agent\\.webclient\\.tls\\.truststore\\.cert)\\[(?<index>\\d+)\\]\\.(?<property>.*)$");
public static final String CRYOSTAT_AGENT_WEBCLIENT_RESPONSE_RETRY_COUNT =
"cryostat.agent.webclient.response.retry-count";

public static final String CRYOSTAT_AGENT_WEBSERVER_HOST = "cryostat.agent.webserver.host";
public static final String CRYOSTAT_AGENT_WEBSERVER_PORT = "cryostat.agent.webserver.port";
Expand Down Expand Up @@ -311,6 +313,11 @@ public static List<TruststoreConfig> provideCryostatAgentWecblientTlsTruststoreC
return truststoreConfigs;
}

@Named(CRYOSTAT_AGENT_WEBCLIENT_RESPONSE_TIMEOUT_MS)
public static int provideCryostatAgentWebclientResponseRetryCount(Config config) {
return config.getValue(CRYOSTAT_AGENT_WEBCLIENT_RESPONSE_RETRY_COUNT, int.class);
}

@Provides
@Singleton
@Named(CRYOSTAT_AGENT_WEBSERVER_HOST)
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/cryostat/agent/MainModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -333,7 +334,8 @@ public static HttpClient provideHttpClient(
@Named(ConfigModule.CRYOSTAT_AGENT_WEBCLIENT_TLS_VERIFY_HOSTNAME)
boolean verifyHostname,
@Named(ConfigModule.CRYOSTAT_AGENT_WEBCLIENT_CONNECT_TIMEOUT_MS) int connectTimeout,
@Named(ConfigModule.CRYOSTAT_AGENT_WEBCLIENT_RESPONSE_TIMEOUT_MS) int responseTimeout) {
@Named(ConfigModule.CRYOSTAT_AGENT_WEBCLIENT_RESPONSE_TIMEOUT_MS) int responseTimeout,
@Named(ConfigModule.CRYOSTAT_AGENT_WEBCLIENT_RESPONSE_RETRY_COUNT) int retryCount) {
HttpClientBuilder builder =
HttpClients.custom()
.setSSLContext(sslContext)
Expand All @@ -344,7 +346,8 @@ public static HttpClient provideHttpClient(
.setConnectTimeout(connectTimeout)
.setSocketTimeout(responseTimeout)
.setRedirectsEnabled(true)
.build());
.build())
.setRetryHandler(new StandardHttpRequestRetryHandler(retryCount, true));

if (!verifyHostname) {
builder = builder.setSSLHostnameVerifier((hostname, session) -> true);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/microprofile-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cryostat.agent.webclient.tls.trust-all=false
cryostat.agent.webclient.tls.verify-hostname=true
cryostat.agent.webclient.connect.timeout-ms=1000
cryostat.agent.webclient.response.timeout-ms=1000
cryostat.agent.webclient.response.retry-count=3
cryostat.agent.webserver.host=0.0.0.0
cryostat.agent.webserver.port=9977
cryostat.agent.webserver.tls.version=${cryostat.agent.webclient.tls.version}
Expand Down

0 comments on commit 50e64b3

Please sign in to comment.