Expose a configuration for HttpClient channel pools metrics

Fixes gh-2241
This commit is contained in:
Violeta Georgieva
2021-05-19 12:55:16 +03:00
committed by spencergibb
parent 0be612a572
commit b528c9dfc7
4 changed files with 22 additions and 4 deletions

View File

@@ -74,11 +74,12 @@
|spring.cloud.gateway.httpclient.connect-timeout | | The connect timeout in millis, the default is 45s.
|spring.cloud.gateway.httpclient.max-header-size | | The max response header size.
|spring.cloud.gateway.httpclient.max-initial-line-length | | The max initial line length.
|spring.cloud.gateway.httpclient.pool.acquire-timeout | | Only for type FIXED, the maximum time in millis to wait for aquiring.
|spring.cloud.gateway.httpclient.pool.acquire-timeout | | Only for type FIXED, the maximum time in millis to wait for acquiring.
|spring.cloud.gateway.httpclient.pool.eviction-interval | `0` | Perform regular eviction checks in the background at a specified interval. Disabled by default ({@link Duration#ZERO})
|spring.cloud.gateway.httpclient.pool.max-connections | | Only for type FIXED, the maximum number of connections before starting pending acquisition on existing ones.
|spring.cloud.gateway.httpclient.pool.max-idle-time | | Time in millis after which the channel will be closed. If NULL, there is no max idle time.
|spring.cloud.gateway.httpclient.pool.max-life-time | | Duration after which the channel will be closed. If NULL, there is no max life time.
|spring.cloud.gateway.httpclient.pool.metrics | `false` | Enables channel pools metrics to be collected and registered in Micrometer. Disabled by default.
|spring.cloud.gateway.httpclient.pool.name | `proxy` | The channel pool map name, defaults to proxy.
|spring.cloud.gateway.httpclient.pool.type | | Type of pool for HttpClient to use, defaults to ELASTIC.
|spring.cloud.gateway.httpclient.proxy.host | | Hostname for proxy configuration of Netty HttpClient.

View File

@@ -752,6 +752,7 @@ public class GatewayAutoConfiguration {
builder.maxLifeTime(pool.getMaxLifeTime());
}
builder.evictInBackground(pool.getEvictionInterval());
builder.metrics(pool.isMetrics());
connectionProvider = builder.build();
}
return connectionProvider;

View File

@@ -196,7 +196,7 @@ public class HttpClientProperties {
*/
private Integer maxConnections = ConnectionProvider.DEFAULT_POOL_MAX_CONNECTIONS;
/** Only for type FIXED, the maximum time in millis to wait for aquiring. */
/** Only for type FIXED, the maximum time in millis to wait for acquiring. */
private Long acquireTimeout = ConnectionProvider.DEFAULT_POOL_ACQUIRE_TIMEOUT;
/**
@@ -217,6 +217,12 @@ public class HttpClientProperties {
*/
private Duration evictionInterval = Duration.ZERO;
/**
* Enables channel pools metrics to be collected and registered in Micrometer.
* Disabled by default.
*/
private boolean metrics = false;
public PoolType getType() {
return type;
}
@@ -273,11 +279,19 @@ public class HttpClientProperties {
this.evictionInterval = evictionInterval;
}
public boolean isMetrics() {
return metrics;
}
public void setMetrics(boolean metrics) {
this.metrics = metrics;
}
@Override
public String toString() {
return "Pool{" + "type=" + type + ", name='" + name + '\'' + ", maxConnections=" + maxConnections
+ ", acquireTimeout=" + acquireTimeout + ", maxIdleTime=" + maxIdleTime + ", maxLifeTime="
+ maxLifeTime + ", evictionInterval=" + evictionInterval + '}';
+ maxLifeTime + ", evictionInterval=" + evictionInterval + ", metrics=" + metrics + '}';
}
public enum PoolType {

View File

@@ -100,8 +100,9 @@ public class GatewayAutoConfigurationTests {
"spring.cloud.gateway.httpclient.response-timeout=10s",
"spring.cloud.gateway.httpclient.pool.eviction-interval=10s",
"spring.cloud.gateway.httpclient.pool.type=fixed",
"spring.cloud.gateway.httpclient.pool.metrics=true",
"spring.cloud.gateway.httpclient.compression=true",
// greather than integer max value
// greater than integer max value
"spring.cloud.gateway.httpclient.max-initial-line-length=2147483647",
"spring.cloud.gateway.httpclient.proxy.host=myhost",
"spring.cloud.gateway.httpclient.websocket.max-frame-payload-length=1024")
@@ -112,6 +113,7 @@ public class GatewayAutoConfigurationTests {
assertThat(properties.getMaxInitialLineLength().toBytes()).isLessThanOrEqualTo(Integer.MAX_VALUE);
assertThat(properties.isCompression()).isEqualTo(true);
assertThat(properties.getPool().getEvictionInterval()).hasSeconds(10);
assertThat(properties.getPool().isMetrics()).isEqualTo(true);
/*
* FIXME: 2.1.0 HttpClientOptions options = httpClient.options();
*