private static List<URL> shuffleUrls(ReporterConfiguration reporterConfiguration) { List<URL> serverUrls = new ArrayList<>(reporterConfiguration.getServerUrls()); // shuffling the URL list helps to distribute the load across the apm servers // when there are multiple agents, they should not all start connecting to the same apm server Collections.shuffle(serverUrls); return serverUrls; }
HttpURLConnection connection = null; try { URL url = new URL(reporterConfiguration.getServerUrls().get(0).toString() + "/"); if (logger.isDebugEnabled()) { logger.debug("Starting healthcheck to {}", url);
@BeforeEach void setUp() throws Exception { server = new Server(); final SslContextFactory sslContextFactory = new SslContextFactory(getClass().getResource("/keystore").getPath()); sslContextFactory.setKeyStorePassword("password"); sslContextFactory.getSslContext(); final HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.setSecureScheme("https"); httpConfiguration.setSecurePort(0); final HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration); httpsConfiguration.addCustomizer(new SecureRequestCustomizer()); final ServerConnector httpsConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfiguration)); httpsConnector.setPort(0); server.addConnector(httpsConnector); server.setHandler(new AbstractHandler() { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { baseRequest.setHandled(true); requestHandled.set(true); } }); server.start(); configuration = SpyConfiguration.createSpyConfig(); reporterConfiguration = configuration.getConfig(ReporterConfiguration.class); when(reporterConfiguration.getServerUrls()).thenReturn(Collections.singletonList(new URL("https://localhost:" + getPort()))); }
@BeforeEach void setUp() throws Exception { handler = exchange -> { if (!exchange.getRequestPath().equals("/healthcheck")) { receivedHttpRequests.incrementAndGet(); } exchange.setStatusCode(200).endExchange(); }; receivedHttpRequests.set(0); config = SpyConfiguration.createSpyConfig(); reporterConfiguration = config.getConfig(ReporterConfiguration.class); when(reporterConfiguration.getFlushInterval()).thenReturn(TimeDuration.of("-1s")); when(reporterConfiguration.getServerUrls()).thenReturn(Collections.singletonList(new URL("http://localhost:" + port))); SystemInfo system = new SystemInfo("x64", "localhost", "platform"); final Service service = new Service(); final ProcessInfo title = new ProcessInfo("title"); final ProcessorEventHandler processorEventHandler = ProcessorEventHandler.loadProcessors(config); final IntakeV2ReportingEventHandler v2handler = new IntakeV2ReportingEventHandler(service, title, system, reporterConfiguration, processorEventHandler, new DslJsonSerializer(mock(StacktraceConfiguration.class))); reporter = new ApmServerReporter(false, reporterConfiguration, v2handler); }