Skip to content

Commit

Permalink
Use updated /intake/v2/events url
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbarny committed Sep 13, 2018
1 parent e7379f5 commit de6e61c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@
import java.util.zip.DeflaterOutputStream;

/**
* This reporter supports the nd-json HTTP streaming based /v2/intake protocol
* This reporter supports the nd-json HTTP streaming based intake v2 protocol
*/
public class IntakeV2ReportingEventHandler implements ReportingEventHandler {

public static final String INTAKE_V2_URL = "/intake/v2/events";
private static final Logger logger = LoggerFactory.getLogger(IntakeV2ReportingEventHandler.class);
private static final int GZIP_COMPRESSION_LEVEL = 1;

Expand Down Expand Up @@ -180,8 +181,7 @@ private boolean shouldFlush() {
@Nullable
private HttpURLConnection startRequest() {
try {
URL url = null;
url = new URL(serverUrlIterator.get(), "/v2/intake");
URL url = new URL(serverUrlIterator.get(), INTAKE_V2_URL);
if (logger.isDebugEnabled()) {
logger.debug("Starting new request to {}", url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.stream.Stream;
import java.util.zip.InflaterInputStream;

import static co.elastic.apm.report.IntakeV2ReportingEventHandler.INTAKE_V2_URL;
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
Expand Down Expand Up @@ -81,7 +82,7 @@ private static JsonNode getReadTree(String s) {
void setUp() throws Exception {
List.of(mockApmServer1, mockApmServer2).forEach(apmServer -> {
apmServer.start();
apmServer.stubFor(post("/v2/intake").willReturn(ok()));
apmServer.stubFor(post(INTAKE_V2_URL).willReturn(ok()));
});
final ConfigurationRegistry configurationRegistry = SpyConfiguration.createSpyConfig();
final ReporterConfiguration reporterConfiguration = configurationRegistry.getConfig(ReporterConfiguration.class);
Expand Down Expand Up @@ -118,20 +119,20 @@ void testReport() {

@Test
void testReportRoundRobinOnServerError() {
mockApmServer1.stubFor(post("/v2/intake").willReturn(serviceUnavailable()));
mockApmServer1.stubFor(post(INTAKE_V2_URL).willReturn(serviceUnavailable()));

reportTransaction();
reportingEventHandler.flush();
mockApmServer1.verify(postRequestedFor(urlEqualTo("/v2/intake")));
mockApmServer2.verify(0, postRequestedFor(urlEqualTo("/v2/intake")));
mockApmServer1.verify(postRequestedFor(urlEqualTo(INTAKE_V2_URL)));
mockApmServer2.verify(0, postRequestedFor(urlEqualTo(INTAKE_V2_URL)));

mockApmServer1.resetRequests();
mockApmServer2.resetRequests();

reportTransaction();
reportingEventHandler.flush();
mockApmServer1.verify(0, postRequestedFor(urlEqualTo("/v2/intake")));
mockApmServer2.verify(postRequestedFor(urlEqualTo("/v2/intake")));
mockApmServer1.verify(0, postRequestedFor(urlEqualTo(INTAKE_V2_URL)));
mockApmServer2.verify(postRequestedFor(urlEqualTo(INTAKE_V2_URL)));
}

@Test
Expand Down Expand Up @@ -169,13 +170,13 @@ private void reportError() {

private List<JsonNode> getNdJsonNodes() {
return Stream.of(mockApmServer1, mockApmServer2)
.flatMap(apmServer -> apmServer.findAll(postRequestedFor(urlEqualTo("/v2/intake"))).stream())
.flatMap(apmServer -> apmServer.findAll(postRequestedFor(urlEqualTo(INTAKE_V2_URL))).stream())
.findFirst()
.map(request -> new BufferedReader(new InputStreamReader(new InflaterInputStream(new ByteArrayInputStream(request.getBody()))))
.lines()
.map(IntakeV2ReportingEventHandlerTest::getReadTree)
.collect(Collectors.toList()))
.orElseThrow(() -> new IllegalStateException("No matching requests for POST /v2/intake"));
.orElseThrow(() -> new IllegalStateException("No matching requests for POST " + INTAKE_V2_URL));
}

}

0 comments on commit de6e61c

Please sign in to comment.