Skip to content

Commit

Permalink
fixes #2134 change the config server timeout to startup.yml and defau…
Browse files Browse the repository at this point in the history
…lt to 3 sec (#2135)
  • Loading branch information
stevehu authored Feb 14, 2024
1 parent 7f08fb7 commit 13eb18b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<version.jsr305>3.0.2</version.jsr305>
<version.json-schema-validator>1.0.65</version.json-schema-validator>
<version.yaml-rule>1.0.3</version.yaml-rule>
<version.http-client>1.0.6</version.http-client>
<version.http-client>1.0.7</version.http-client>
<version.snakeyaml>2.2</version.snakeyaml>
<version.caffeine>3.1.5</version.caffeine>
<version.prometheus>0.16.0</version.prometheus>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import ch.qos.logback.core.joran.spi.JoranException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.networknt.client.ClientConfig;
import com.networknt.config.Config;
import com.networknt.config.ConfigInjection;
import com.networknt.config.JsonMapper;
Expand Down Expand Up @@ -84,6 +83,8 @@ public class DefaultConfigLoader implements IConfigLoader{
public static final String API_VERSION = "apiVersion";
public static final String ENV_TAG = "envTag";
public static final String ACCEPT_HEADER = "acceptHeader";
public static final String TIMEOUT = "timeout";

public static String lightEnv = null;
public static String configServerUri = null;
public static String targetConfigsDirectory = null;
Expand All @@ -99,9 +100,11 @@ private HttpClient createHttpClient() {
final Properties props = System.getProperties();
props.setProperty("jdk.internal.httpclient.disableHostnameVerification", Boolean.TRUE.toString());
}
int timeout = 3000;
if(startupConfig.get(TIMEOUT) != null) timeout = Config.loadIntegerValue(TIMEOUT, startupConfig.get(TIMEOUT));
HttpClient.Builder clientBuilder = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NORMAL)
.connectTimeout(Duration.ofMillis(ClientConfig.get().getTimeout())) // client.timeout from the client.yml
.connectTimeout(Duration.ofMillis(timeout)) // timeout from the startup.yml
.version(HttpClient.Version.HTTP_2)
.sslContext(createBootstrapContext());
return clientBuilder.build();
Expand Down
3 changes: 3 additions & 0 deletions server/src/main/resources/config/startup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ dummy: dummyEntry
# apiId: com.networknt.petstore-1.0.0
# apiVersion: 1.0.0
# envTag: dev
# Indicate to the config server we prefer yaml format over json format. default is json.
# acceptHeader: application/yaml
# The connect timeout for bootstrap from the config server. Default is 3 seconds.
# timeout: 3000

0 comments on commit 13eb18b

Please sign in to comment.