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

Memory consumption fix #17

Merged
merged 4 commits into from
Apr 4, 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.23-SNAPSHOT</version>
<version>2.1.24-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.23-SNAPSHOT</version>
<version>2.1.24-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,6 @@ public void serverToProxyResponseReceived() {
}

protected static void logFailedRequestIfRequired(HarRequest request, HarResponse response) {
System.out.println("TEST");
if (!isAlreadyLoggedIn.get() && (response.getStatus() >= 500 || response.getStatus() == 0)) {
MDC.put("caller", "mobproxy");
MDC.put("http_response_code", String.valueOf(response.getStatus()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,16 @@
import io.netty.handler.codec.http.HttpResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.littleshoot.proxy.HttpFiltersAdapter;

import java.net.URI;
import java.net.URISyntaxException;

public class StatsDMetricsFilter extends HttpsAwareFiltersAdapter {
private StatsDClient client;
private static InheritableThreadLocal<HttpRequest> HTTP_REQUEST_STORAGE = new InheritableThreadLocal<>();

public StatsDMetricsFilter(HttpRequest originalRequest, ChannelHandlerContext ctx) {
super(originalRequest, ctx);
this.client = new NonBlockingStatsDClient("automated_tests", getStatsDHost(), getStatsDPort());
}

@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
if (httpObject instanceof HttpRequest) {
HttpRequest httpRequest = (HttpRequest) httpObject;
HTTP_REQUEST_STORAGE.set(httpRequest);
}
return null;
}


@Override
public HttpObject serverToProxyResponse(HttpObject httpObject) {
if (HttpResponse.class.isAssignableFrom(httpObject.getClass())) {
Expand All @@ -43,30 +30,29 @@ public HttpObject serverToProxyResponse(HttpObject httpObject) {

private void prepareStatsDMetrics(int status) {
if (status > 399 || status == 0) {
String metric;
HttpRequest request = HTTP_REQUEST_STORAGE.get();
String url = getFullUrl(request);
metric = getProxyPrefix().concat(
String url = getFullUrl(originalRequest);
String metric = getProxyPrefix().concat(
prepareMetric(url)).concat(String.format(".%s", status));
StatsDClient client = new NonBlockingStatsDClient("automated_tests", getStatsDHost(), getStatsDPort());
client.increment(metric);
HTTP_REQUEST_STORAGE.remove();
client.stop();
}
}


static String getStatsDHost() {
protected static String getStatsDHost() {
return StringUtils.isEmpty(System.getenv("STATSD_HOST")) ? "localhost" : System.getenv("STATSD_HOST");
}

static int getStatsDPort() {
protected static int getStatsDPort() {
return StringUtils.isEmpty(System.getenv("STATSD_PORT")) ? 8125 : NumberUtils.toInt(System.getenv("STATSD_PORT"));
}

public static String getProxyPrefix() {
protected static String getProxyPrefix() {
return "proxy.";
}

public static String prepareMetric(String initialUrl) {
protected static String prepareMetric(String initialUrl) {
URI uri = null;
try {
uri = new URI(initialUrl);
Expand Down
2 changes: 1 addition & 1 deletion browsermob-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>browsermob-proxy</artifactId>
<groupId>net.lightbody.bmp</groupId>
<version>2.1.23-SNAPSHOT</version>
<version>2.1.24-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 @@ -6,7 +6,7 @@
<parent>
<artifactId>browsermob-proxy</artifactId>
<groupId>net.lightbody.bmp</groupId>
<version>2.1.23-SNAPSHOT</version>
<version>2.1.24-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.23-SNAPSHOT</version>
<version>2.1.24-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 @@ -4,7 +4,7 @@
<parent>
<artifactId>browsermob-proxy</artifactId>
<groupId>net.lightbody.bmp</groupId>
<version>2.1.23-SNAPSHOT</version>
<version>2.1.24-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.23-SNAPSHOT</version>
<version>2.1.24-SNAPSHOT</version>
<modules>
<module>browsermob-core</module>
<module>browsermob-legacy</module>
Expand Down