diff --git a/apm-agent-core/src/main/java/co/elastic/apm/report/IntakeV2ReportingEventHandler.java b/apm-agent-core/src/main/java/co/elastic/apm/report/IntakeV2ReportingEventHandler.java index 31f0f0a168..0b66ffea7c 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/report/IntakeV2ReportingEventHandler.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/report/IntakeV2ReportingEventHandler.java @@ -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; @@ -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); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/report/IntakeV2ReportingEventHandlerTest.java b/apm-agent-core/src/test/java/co/elastic/apm/report/IntakeV2ReportingEventHandlerTest.java index 8116961938..b59096be02 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/report/IntakeV2ReportingEventHandlerTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/report/IntakeV2ReportingEventHandlerTest.java @@ -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; @@ -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); @@ -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 @@ -169,13 +170,13 @@ private void reportError() { private List 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)); } }