@Override public void run() { // if the ring buffer is full this waits until a slot becomes available // as this happens on a different thread, // the reporting does not block and thus there is no danger of deadlocks logger.debug("Request flush because the request timeout occurred"); flush = reporter.flush(); }
@Override public void report(Transaction transaction) { if (!tryAddEventToRingBuffer(transaction, TRANSACTION_EVENT_TRANSLATOR)) { transaction.recycle(); } if (syncReport) { waitForFlush(); } }
@Test void testReportTransaction() throws ExecutionException, InterruptedException { reporter.report(new Transaction(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedHttpRequests.get()).isEqualTo(1); }
public Reporter createReporter(ConfigurationRegistry configurationRegistry, @Nullable String frameworkName, @Nullable String frameworkVersion) { final ReporterConfiguration reporterConfiguration = configurationRegistry.getConfig(ReporterConfiguration.class); ExecutorService healthCheckExecutorService = Executors.newFixedThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { final Thread thread = new Thread(r); thread.setName("apm-server-healthcheck"); thread.setDaemon(true); return thread; } }); healthCheckExecutorService.submit(new ApmServerHealthChecker(reporterConfiguration)); healthCheckExecutorService.shutdown(); final ReportingEventHandler reportingEventHandler = getReportingEventHandler(configurationRegistry, frameworkName, frameworkVersion, reporterConfiguration); return new ApmServerReporter(true, reporterConfiguration, reportingEventHandler); }
@Test void testReportSpan() throws ExecutionException, InterruptedException { reporter.report(new Span(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedHttpRequests.get()).isEqualTo(1); }
@BeforeEach void setUp() { final ConfigurationRegistry configurationRegistry = SpyConfiguration.createSpyConfig(); ReporterConfiguration reporterConfiguration = configurationRegistry.getConfig(ReporterConfiguration.class); when(reporterConfiguration.getFlushInterval()).thenReturn(TimeDuration.of("-1ms")); when(reporterConfiguration.getMaxQueueSize()).thenReturn(0); reportingEventHandler = mock(ReportingEventHandler.class); reporter = new ApmServerReporter(true, reporterConfiguration, reportingEventHandler); }
@Test void testReportErrorCapture() throws ExecutionException, InterruptedException { reporter.report(new ErrorCapture(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedHttpRequests.get()).isEqualTo(1); }
@Override public void report(Span span) { if (!tryAddEventToRingBuffer(span, SPAN_EVENT_TRANSLATOR)) { span.recycle(); } if (syncReport) { waitForFlush(); } }
@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); }
private void waitForFlush() { try { flush().get(); } catch (Exception e) { throw new RuntimeException(e); } }
@Test void testTransactionProcessor() throws Exception { reporter.report(new Transaction(mock(ElasticApmTracer.class))); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); verify(reportingEventHandler).onEvent(notNull(ReportingEvent::getTransaction), anyLong(), anyBoolean()); }
@Override public void report(ErrorCapture error) { if (!tryAddEventToRingBuffer(error, ERROR_EVENT_TRANSLATOR)) { error.recycle(); } if (syncReport) { waitForFlush(); } }
@Test void testErrorProcessor() throws Exception { reporter.report(new ErrorCapture(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); verify(reportingEventHandler).onEvent(notNull(ReportingEvent::getError), anyLong(), anyBoolean()); }
@Test void testSecretToken() throws ExecutionException, InterruptedException { when(reporterConfiguration.getSecretToken()).thenReturn("token"); handler = exchange -> { assertThat(exchange.getRequestHeaders().get("Authorization").getFirst()).isEqualTo("Bearer token"); receivedHttpRequests.incrementAndGet(); exchange.setStatusCode(200).endExchange(); }; reporter.report(new Transaction(MockTracer.create())); reporter.flush().get(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedHttpRequests.get()).isEqualTo(1); }