Skip to content
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
sudo: true
services:
- docker
language: java
jdk:
- oraclejdk9
Expand Down
5 changes: 2 additions & 3 deletions apm-agent-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<modelVersion>4.0.0</modelVersion>
<properties>
<maven-deploy-plugin.skip>true</maven-deploy-plugin.skip>
<okhttp.version>3.9.1</okhttp.version>
</properties>

<parent>
Expand Down Expand Up @@ -63,12 +62,12 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
<version>${version.okhttp}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>${okhttp.version}</version>
<version>${version.okhttp}</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ public void translateTo(ReportingEvent event, long sequence, ErrorCapture error)
private final AtomicInteger dropped = new AtomicInteger();
private final boolean dropTransactionIfQueueFull;
private final ReportingEventHandler reportingEventHandler;
private final boolean syncReport;
@Nullable
private ScheduledThreadPoolExecutor flushScheduler;

public ApmServerReporter(Service service, ProcessInfo process, SystemInfo system, PayloadSender payloadSender,
boolean dropTransactionIfQueueFull, ReporterConfiguration reporterConfiguration,
ProcessorEventHandler processorEventHandler) {
this.dropTransactionIfQueueFull = dropTransactionIfQueueFull;
this.syncReport = reporterConfiguration.isReportSynchronously();
disruptor = new Disruptor<>(new TransactionEventFactory(), MathUtils.getNextPowerOf2(reporterConfiguration.getMaxQueueSize()), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Expand Down Expand Up @@ -109,6 +111,17 @@ public void report(Transaction transaction) {
if (!tryAddEventToRingBuffer(transaction, TRANSACTION_EVENT_TRANSLATOR)) {
transaction.recycle();
}
if (syncReport) {
waitForFlush();
}
}

private void waitForFlush() {
try {
flush().get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
Expand Down Expand Up @@ -185,6 +198,9 @@ public void report(ErrorCapture error) {
if (!tryAddEventToRingBuffer(error, ERROR_EVENT_TRANSLATOR)) {
error.recycle();
}
if (syncReport) {
waitForFlush();
}
}

private <E extends Recyclable> boolean tryAddEventToRingBuffer(E event, EventTranslatorOneArg<ReportingEvent, E> eventTranslator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

import javax.annotation.Nullable;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class ReporterConfiguration extends ConfigurationOptionProvider {
public static final String REPORTER_CATEGORY = "Reporter";
Expand All @@ -45,6 +42,7 @@ public class ReporterConfiguration extends ConfigurationOptionProvider {
.configurationCategory(REPORTER_CATEGORY)
.label("The URL for your APM Server")
.description("The URL must be fully qualified, including protocol (http or https) and port.")
.dynamic(true)
.buildWithDefault(UrlValueConverter.INSTANCE.convert("http://localhost:8200"));

private final ConfigurationOption<Integer> serverTimeout = ConfigurationOption.integerOption()
Expand Down Expand Up @@ -85,6 +83,14 @@ public class ReporterConfiguration extends ConfigurationOptionProvider {
.dynamic(true)
.buildWithDefault(500);

private final ConfigurationOption<Boolean> reportSynchronously = ConfigurationOption.booleanOption()
.key("report_sync")
.tags("internal")
.configurationCategory(REPORTER_CATEGORY)
.description("Only to be used for testing purposes. " +
"Blocks the requests until the transaction has been reported to the APM server.")
.buildWithDefault(false);

@Nullable
public String getSecretToken() {
return secretToken.get();
Expand All @@ -109,4 +115,8 @@ public int getFlushInterval() {
public int getMaxQueueSize() {
return maxQueueSize.get();
}

public boolean isReportSynchronously() {
return reportSynchronously.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,12 +26,15 @@
import co.elastic.apm.impl.payload.SystemInfo;
import co.elastic.apm.impl.payload.TransactionPayload;
import com.lmax.disruptor.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static co.elastic.apm.report.ReportingEvent.ReportingEventType.ERROR;
import static co.elastic.apm.report.ReportingEvent.ReportingEventType.FLUSH;
import static co.elastic.apm.report.ReportingEvent.ReportingEventType.TRANSACTION;

class ReportingEventHandler implements EventHandler<ReportingEvent> {
private static final Logger logger = LoggerFactory.getLogger(ReportingEventHandler.class);
private final TransactionPayload transactionPayload;
private final ErrorPayload errorPayload;
private final PayloadSender payloadSender;
Expand All @@ -46,6 +49,7 @@ public ReportingEventHandler(Service service, ProcessInfo process, SystemInfo sy

@Override
public void onEvent(ReportingEvent event, long sequence, boolean endOfBatch) {
logger.debug("Receiving {} event (sequence {})", event.getType(), sequence);
if (event.getType() == FLUSH) {
flush(transactionPayload);
flush(errorPayload);
Expand All @@ -63,6 +67,7 @@ public void onEvent(ReportingEvent event, long sequence, boolean endOfBatch) {
flush(errorPayload);
}
}
logger.debug("Finished processing {} event (sequence {})", event.getType(), sequence);
event.resetState();
}

Expand Down
17 changes: 17 additions & 0 deletions apm-agent-core/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://ch.qos.logback/xml/ns/logback"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ch.qos.logback/xml/ns/logback https://raw.githubusercontent.com/enricopulatzo/logback-XSD/master/src/main/xsd/logback.xsd">

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="WARN">
<appender-ref ref="STDOUT"/>
</root>

<logger name="co.elastic.apm" level="DEBUG"/>
</configuration>
2 changes: 2 additions & 0 deletions apm-agent-java/src/test/resources/configuration.asciidoc.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ application_packages=org.example
[[${category?lower_case?replace(" ", "-")}]]
=== ${category} configuration options
<#list options as option>
<#if !option.tags?seq_contains("internal")>
[float]
[[config-${option.key?replace("[^a-z]", "-", "r")}]]
==== `${option.key}`
Expand All @@ -56,6 +57,7 @@ ${option.description}
| `elastic.apm.${option.key}` | `ELASTIC_APM_${option.key?upper_case}` | `${option.key}`
|============

</#if>
</#list>
</#list>

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ The URL must be fully qualified, including protocol (http or https) and port.
[options="header"]
|============
| Default | Type | Dynamic
| `pass:[http://localhost:8200]` | URL | false
| `pass:[http://localhost:8200]` | URL | true
|============


Expand Down
23 changes: 23 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-agent-parent</artifactId>
<groupId>co.elastic.apm</groupId>
<version>0.1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>integration-tests</artifactId>
<packaging>pom</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<modules>
<module>simple-webapp</module>
<module>simple-webapp-integration-test</module>
</modules>
<properties>
<maven-deploy-plugin.skip>true</maven-deploy-plugin.skip>
</properties>

</project>
73 changes: 73 additions & 0 deletions integration-tests/simple-webapp-integration-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>integration-tests</artifactId>
<groupId>co.elastic.apm</groupId>
<version>0.1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>simple-webapp-integration-test</artifactId>

<name>${project.groupId}:${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>simple-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-agent-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${version.okhttp}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>${version.okhttp}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${version.logback}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>${version.json-schema-validator}</version>
<scope>test</scope>
<exclusions>
<!--
mockserver-client does not work with the latest jackson version
see https://github.com/jamesdbloom/mockserver/issues/440
-->
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

</project>
Loading