Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Release 2.1.11 fix stats d metrics #8

Merged
merged 3 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ When you build the latest code from source, you'll have access to the latest sna
<dependency>
<groupId>net.lightbody.bmp</groupId>
<artifactId>browsermob-core</artifactId>
<version>2.1.11-SNAPSHOT</version>
<version>2.1.12-SNAPSHOT</version>
<scope>test</scope>
</dependency>
```
2 changes: 1 addition & 1 deletion browsermob-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>browsermob-proxy</artifactId>
<groupId>net.lightbody.bmp</groupId>
<version>2.1.11-SNAPSHOT</version>
<version>2.1.12-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

public class HarCaptureFilter extends HttpsAwareFiltersAdapter {
private static final Logger log = LoggerFactory.getLogger(HarCaptureFilter.class);
private static final StatsDClient statsDClient = new NonBlockingStatsDClient("automated_tests", getStatsDHost(), getStatsDPort());
private static final ThreadLocal<StatsDClient> statsDClient = new InheritableThreadLocal<>();

/**
* The currently active HAR at the time the current request is received.
Expand Down Expand Up @@ -174,6 +174,8 @@ public HarCaptureFilter(HttpRequest originalRequest, ChannelHandlerContext ctx,
responseCaptureFilter = null;
}

createStatsDClient();

this.har = har;

this.harEntry = new HarEntry(currentPageRef);
Expand Down Expand Up @@ -205,8 +207,6 @@ public HttpResponse clientToProxyRequest(HttpObject httpObject) {
HarResponse defaultHarResponse = HarCaptureUtil.createHarResponseForFailure();
defaultHarResponse.setError(HarCaptureUtil.getNoResponseReceivedErrorMessage());
harEntry.setResponse(defaultHarResponse);
statsDClient.increment(getProxyPrefix().concat(prepareMetric(harEntry.getRequest().getUrl()))
.concat("." + harEntry.getResponse().getStatus()).concat(".client_proxy_connection_fail"));

captureQueryParameters(httpRequest);
// not capturing user agent: in many cases, it doesn't make sense to capture at the HarLog level, since the proxy could be
Expand Down Expand Up @@ -286,7 +286,8 @@ public void serverToProxyResponseTimedOut() {
// replace any existing HarResponse that was created if the server sent a partial response
HarResponse response = HarCaptureUtil.createHarResponseForFailure();
harEntry.setResponse(response);
statsDClient.increment(getProxyPrefix().concat(prepareMetric(harEntry.getRequest().getUrl()))
createStatsDClient();
statsDClient.get().increment(getProxyPrefix().concat(prepareMetric(harEntry.getRequest().getUrl()))
.concat("." + harEntry.getResponse().getStatus()).concat(".response_timeout"));

response.setError(HarCaptureUtil.getResponseTimedOutErrorMessage());
Expand Down Expand Up @@ -661,7 +662,8 @@ public InetSocketAddress proxyToServerResolutionStarted(String resolvingServerHo
public void proxyToServerResolutionFailed(String hostAndPort) {
HarResponse response = HarCaptureUtil.createHarResponseForFailure();
harEntry.setResponse(response);
statsDClient.increment(getProxyPrefix().concat(prepareMetric(harEntry.getRequest().getUrl()))
createStatsDClient();
statsDClient.get().increment(getProxyPrefix().concat(prepareMetric(harEntry.getRequest().getUrl()))
.concat("." + harEntry.getResponse().getStatus()).concat(".server_resolution_fail"));

response.setError(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));
Expand Down Expand Up @@ -704,7 +706,8 @@ public void proxyToServerConnectionStarted() {
@Override
public void proxyToServerConnectionFailed() {
HarResponse response = HarCaptureUtil.createHarResponseForFailure();
statsDClient.increment(getProxyPrefix().concat(prepareMetric(harEntry.getRequest().getUrl()))
createStatsDClient();
statsDClient.get().increment(getProxyPrefix().concat(prepareMetric(harEntry.getRequest().getUrl()))
.concat("." + harEntry.getResponse().getStatus()).concat(".server_connection_fail"));
harEntry.setResponse(response);

Expand Down Expand Up @@ -777,4 +780,11 @@ public void serverToProxyResponseReceived() {
harEntry.getTimings().setReceive(0L, TimeUnit.NANOSECONDS);
}
}


private void createStatsDClient() {
if (statsDClient.get() == null) {
statsDClient.set(new NonBlockingStatsDClient("automated_tests", getStatsDHost(), getStatsDPort()));
}
}
}
2 changes: 1 addition & 1 deletion browsermob-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>browsermob-proxy</artifactId>
<groupId>net.lightbody.bmp</groupId>
<version>2.1.11-SNAPSHOT</version>
<version>2.1.12-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion browsermob-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>browsermob-proxy</artifactId>
<groupId>net.lightbody.bmp</groupId>
<version>2.1.11-SNAPSHOT</version>
<version>2.1.12-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion browsermob-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>browsermob-proxy</artifactId>
<groupId>net.lightbody.bmp</groupId>
<version>2.1.11-SNAPSHOT</version>
<version>2.1.12-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion mitm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>browsermob-proxy</artifactId>
<groupId>net.lightbody.bmp</groupId>
<version>2.1.11-SNAPSHOT</version>
<version>2.1.12-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.lightbody.bmp</groupId>
<artifactId>browsermob-proxy</artifactId>
<version>2.1.11-SNAPSHOT</version>
<version>2.1.12-SNAPSHOT</version>
<modules>
<module>browsermob-core</module>
<module>browsermob-legacy</module>
Expand Down