Skip to content

Commit

Permalink
Merge pull request #305 from mozilla-services/iprepdto
Browse files Browse the repository at this point in the history
Update httpclient, add iprepd write timeouts
  • Loading branch information
Aaron Meihm authored Jan 22, 2020
2 parents e3689ba + c94e248 commit 33b4c9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
<version>4.5.11</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/mozilla/secops/IprepdIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
Expand Down Expand Up @@ -330,6 +331,15 @@ private static class WriteFn extends DoFn<String, Void> {
private String[] iprepdSpecs;
private String project;

/** Writer initial connection timeout */
public final int WRITER_TIMEOUT_CONNECTION = 5000;

/** Writer connection manager connection request timeout */
public final int WRITER_TIMEOUT_CONNECTION_REQUEST = 5000;

/** Writer socket timeout */
public final int WRITER_TIMEOUT_SOCKET = 5000;

private Counter violationWrites = Metrics.counter(METRICS_NAMESPACE, VIOLATION_WRITES_METRIC);

private static HashMap<String, String> decrypted = new HashMap<String, String>();
Expand All @@ -343,7 +353,13 @@ public WriteFn(Write wTransform) {
public void setup() throws IOException {
log = LoggerFactory.getLogger(WriteFn.class);
log.info("creating new HTTP client for iprepd submission");
httpClient = HttpClientBuilder.create().build();
RequestConfig rc =
RequestConfig.custom()
.setConnectTimeout(WRITER_TIMEOUT_CONNECTION)
.setConnectionRequestTimeout(WRITER_TIMEOUT_CONNECTION_REQUEST)
.setSocketTimeout(WRITER_TIMEOUT_SOCKET)
.build();
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(rc).build();

project = wTransform.getProject();
iprepdSpecs = wTransform.getIprepdSpecs();
Expand Down

0 comments on commit 33b4c9c

Please sign in to comment.