Skip to content
Open
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
54 changes: 54 additions & 0 deletions cf-java-logging-support-log4j2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-jmh-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/jmh/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -72,6 +91,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<systemPropertyVariables>
<log.generate.application.logging.custom.fields>true
Expand All @@ -81,4 +101,38 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>benchmark</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec.plugin.version}</version>
<executions>
<execution>
<id>run-benchmarks</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<classpathScope>test</classpathScope>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.sap.hcp.cf.log4j2.benchmark.BenchmarkRunner</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@

import static com.sap.hcp.cf.logging.common.request.RequestRecordBuilder.requestRecord;

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 10, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)
@Fork(1)
public class EncodingBenchmarks {

public static Logger LOG = LoggerFactory.getLogger(EncodingBenchmarks.class);
Expand Down
54 changes: 54 additions & 0 deletions cf-java-logging-support-logback/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,29 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-jmh-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/jmh/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<systemPropertyVariables>
<log.generate.application.logging.custom.fields>true
Expand All @@ -47,4 +67,38 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>benchmark</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec.plugin.version}</version>
<executions>
<execution>
<id>run-benchmarks</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<classpathScope>test</classpathScope>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.sap.hcp.cf.logback.benchmark.BenchmarkRunner</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@

import static com.sap.hcp.cf.logging.common.request.RequestRecordBuilder.requestRecord;

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)
@Fork(1)
public class EncodingBenchmarks {

public static Logger LOG = LoggerFactory.getLogger(EncodingBenchmarks.class);
Expand Down
64 changes: 63 additions & 1 deletion cf-java-logging-support-servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

<properties>
<maven-dependency-plugin.version>3.5.0</maven-dependency-plugin.version>
<build-helper-maven-plugin.version>3.3.0</build-helper-maven-plugin.version>
<maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
</properties>

Expand Down Expand Up @@ -74,4 +73,67 @@
</dependency>

</dependencies>

<build>
<plugins>
<!-- Register src/jmh/java as an additional test source root so it is
compiled in the normal testCompile pass alongside src/test/java.
The JMH annotation processor then has the full classpath available
and generates its benchmark harness correctly. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-jmh-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/jmh/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>benchmark</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec.plugin.version}</version>
<executions>
<execution>
<id>run-benchmarks</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<classpathScope>test</classpathScope>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.sap.hcp.cf.logging.servlet.filter.benchmark.BenchmarkRunner
</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sap.hcp.cf.logging.servlet.filter.benchmark;

import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

public class BenchmarkRunner {

public static void main(String[] args) throws RunnerException {
Options options =
new OptionsBuilder().include(RequestUriMatcherBenchmarks.class.getSimpleName()).forks(1).build();
new Runner(options).run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.sap.hcp.cf.logging.servlet.filter.benchmark;

import com.sap.hcp.cf.logging.servlet.filter.RequestUriMatcher;
import org.openjdk.jmh.annotations.*;

import java.util.concurrent.TimeUnit;

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 5, timeUnit = TimeUnit.SECONDS)
@Fork(1)
public class RequestUriMatcherBenchmarks {

@State(Scope.Benchmark)
public static class BenchmarkState {

// --- matchers ---
public final RequestUriMatcher noPatterns = new RequestUriMatcher(null);
public final RequestUriMatcher exactSingle = new RequestUriMatcher("/health");
public final RequestUriMatcher wildcardDouble = new RequestUriMatcher("/actuator/**");
public final RequestUriMatcher wildcardSingle = new RequestUriMatcher("/api/*/status");
public final RequestUriMatcher multiPattern =
new RequestUriMatcher("/health, /metrics, /actuator/**, /readyz, /livez");

// --- URIs ---
public final String uriHealth = "/health";
public final String uriApiOrders = "/api/orders";
public final String uriActuatorDeep = "/actuator/health/liveness";
public final String uriApiStatus = "/api/orders/status";
public final String uriNoMatch = "/api/v1/orders/123/items";
}

/** Baseline: no patterns configured — fastest possible path. */
@Benchmark
public boolean noPatterns(BenchmarkState s) {
return s.noPatterns.matches(s.uriApiOrders);
}

/** Single exact pattern, URI matches. */
@Benchmark
public boolean exactMatch(BenchmarkState s) {
return s.exactSingle.matches(s.uriHealth);
}

/** Single exact pattern, URI does not match. */
@Benchmark
public boolean exactNoMatch(BenchmarkState s) {
return s.exactSingle.matches(s.uriApiOrders);
}

/** Double-wildcard pattern (/actuator/**), deep URI matches. */
@Benchmark
public boolean doubleWildcardMatch(BenchmarkState s) {
return s.wildcardDouble.matches(s.uriActuatorDeep);
}

/** Double-wildcard pattern (/actuator/**), URI does not match. */
@Benchmark
public boolean doubleWildcardNoMatch(BenchmarkState s) {
return s.wildcardDouble.matches(s.uriNoMatch);
}

/** Single-segment wildcard ({@code /api/&#42;/status}), URI matches. */
@Benchmark
public boolean singleWildcardMatch(BenchmarkState s) {
return s.wildcardSingle.matches(s.uriApiStatus);
}

/**
* Realistic actuator-exclusion scenario: five patterns, URI matches the third one (/actuator/**) — worst-case
* traversal through the list.
*/
@Benchmark
public boolean multiPatternMatch(BenchmarkState s) {
return s.multiPattern.matches(s.uriActuatorDeep);
}

/**
* Realistic actuator-exclusion scenario: five patterns, URI matches none — full list traversal.
*/
@Benchmark
public boolean multiPatternNoMatch(BenchmarkState s) {
return s.multiPattern.matches(s.uriNoMatch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public class GenerateRequestLogFilter extends AbstractLoggingFilter {

public static final String WRAP_RESPONSE_INIT_PARAM = "wrapResponse";
public static final String WRAP_REQUEST_INIT_PARAM = "wrapRequest";
public static final String EXCLUDE_PATTERNS_INIT_PARAM = "excludePatterns";

private final RequestRecordFactory requestRecordFactory;

private boolean wrapResponse = true;
private boolean wrapRequest = true;
private RequestUriMatcher excludeMatcher = new RequestUriMatcher(null);

public GenerateRequestLogFilter() {
this(new RequestRecordFactory(new LogOptionalFieldsSettings(GenerateRequestLogFilter.class.getName())));
Expand All @@ -47,6 +49,7 @@ public void init(FilterConfig filterConfig) throws ServletException {
if ("false".equalsIgnoreCase(value)) {
wrapRequest = false;
}
excludeMatcher = new RequestUriMatcher(filterConfig.getInitParameter(EXCLUDE_PATTERNS_INIT_PARAM));
}

@Override
Expand Down Expand Up @@ -75,7 +78,7 @@ protected void doFilterRequest(HttpServletRequest request, HttpServletResponse r
try {
doFilter(chain, request, response);
} finally {
if (!request.isAsyncStarted()) {
if (!request.isAsyncStarted() && !excludeMatcher.matches(request.getRequestURI())) {
logger.logRequest();
}

Expand Down
Loading
Loading