Skip to content

Commit

Permalink
fix: prom sink changed to PoolingHttpClientConnectionManager for idle…
Browse files Browse the repository at this point in the history
… connection eviction (#195) (#197)

* fix: prom sink changed to BasicHttpClientConnectionManager for idle connection eviction

* fix: update default SINK_PROM_MAX_CONNECTIONS

* fix: changed default value for max prom connection to use default PoolingHttpClientConnectionManager

* fix: styling

* fix: added default value in doc

Co-authored-by: Mayank Rai <mayank.rai@gojek.com>

Co-authored-by: Mayank Rai <92782366+mayankrai09@users.noreply.github.com>
Co-authored-by: Mayank Rai <mayank.rai@gojek.com>
  • Loading branch information
3 people committed Oct 31, 2022
1 parent 6e73a3f commit 5e794ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/docs/sinks/prometheus-sink.md
Expand Up @@ -17,6 +17,14 @@ Defines the connection timeout for the request in millis.
- Type: `required`
- Default value: `10000`

### `SINK_PROM_MAX_CONNECTIONS`

Defines the maximum number of HTTP connections with Prometheus.

- Example value: `10`
- Type: `optional`
- Default value: `default no more than 2 concurrent connections per given route and no more 20 connections`

### `SINK_PROM_RETRY_STATUS_CODE_RANGES`

Defines the range of HTTP status codes for which retry will be attempted.
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/odpf/firehose/config/PromSinkConfig.java
Expand Up @@ -22,6 +22,9 @@ public interface PromSinkConfig extends AppConfig {
@DefaultValue("10000")
Integer getSinkPromRequestTimeoutMs();

@Key("SINK_PROM_MAX_CONNECTIONS")
Integer getSinkPromMaxConnections();

@Key("SINK_PROM_SERVICE_URL")
String getSinkPromServiceUrl();

Expand Down
Expand Up @@ -13,7 +13,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;

import java.util.Map;

Expand Down Expand Up @@ -67,7 +67,12 @@ private static CloseableHttpClient newHttpClient(PromSinkConfig promSinkConfig)
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(promSinkConfig.getSinkPromRequestTimeoutMs())
.setConnectionRequestTimeout(promSinkConfig.getSinkPromRequestTimeoutMs())
.setConnectTimeout(promSinkConfig.getSinkPromRequestTimeoutMs()).build();
BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
if (promSinkConfig.getSinkPromMaxConnections() != null && promSinkConfig.getSinkPromMaxConnections() > 0) {
connectionManager.setMaxTotal(promSinkConfig.getSinkPromMaxConnections());
connectionManager.setDefaultMaxPerRoute(promSinkConfig.getSinkPromMaxConnections());
}

HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig);

return builder.build();
Expand Down

0 comments on commit 5e794ac

Please sign in to comment.