Skip to content

Commit

Permalink
elastic#3030: Introduce configuration API within SPI package that act…
Browse files Browse the repository at this point in the history
…s as a binary compatible mirror of the current configuration.
  • Loading branch information
raphw committed Feb 22, 2023
1 parent e89545a commit b31c3d5
Show file tree
Hide file tree
Showing 67 changed files with 756 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static WildcardMatcher matchAll() {
return MATCH_ALL;
}

public static List<WildcardMatcher> matchAllList() {
public static List<? extends WildcardMatcher> matchAllList() {
return MATCH_ALL_LIST;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public static WildcardMatcher valueOf(final String wildcardString) {
* @param s the string to match against
* @return {@code true}, if any of the matchers match the provided string
*/
public static boolean isAnyMatch(List<WildcardMatcher> matchers, @Nullable CharSequence s) {
public static boolean isAnyMatch(List<? extends WildcardMatcher> matchers, @Nullable CharSequence s) {
return anyMatch(matchers, s) != null;
}

Expand All @@ -149,7 +149,7 @@ public static boolean isAnyMatch(List<WildcardMatcher> matchers, @Nullable CharS
* @param s the string to match against
* @return {@code true}, if none of the matchers match the provided string
*/
public static boolean isNoneMatch(List<WildcardMatcher> matchers, @Nullable CharSequence s) {
public static boolean isNoneMatch(List<? extends WildcardMatcher> matchers, @Nullable CharSequence s) {
return !isAnyMatch(matchers, s);
}

Expand All @@ -161,7 +161,7 @@ public static boolean isNoneMatch(List<WildcardMatcher> matchers, @Nullable Char
* @return the first matching {@link WildcardMatcher}, or {@code null} if none match.
*/
@Nullable
public static WildcardMatcher anyMatch(List<WildcardMatcher> matchers, @Nullable CharSequence s) {
public static WildcardMatcher anyMatch(List<? extends WildcardMatcher> matchers, @Nullable CharSequence s) {
if (s == null || matchers.isEmpty()) {
return null;
}
Expand All @@ -178,7 +178,7 @@ public static WildcardMatcher anyMatch(List<WildcardMatcher> matchers, @Nullable
* @see #matches(CharSequence, CharSequence)
*/
@Nullable
public static WildcardMatcher anyMatch(List<WildcardMatcher> matchers, CharSequence firstPart, @Nullable CharSequence secondPart) {
public static WildcardMatcher anyMatch(List<? extends WildcardMatcher> matchers, CharSequence firstPart, @Nullable CharSequence secondPart) {
for (int i = 0; i < matchers.size(); i++) {
if (matchers.get(i).matches(firstPart, secondPart)) {
return matchers.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public String toString() {
};
}

public static ElementMatcher.Junction<NamedElement> anyMatch(final List<WildcardMatcher> matchers) {
public static ElementMatcher.Junction<NamedElement> anyMatch(final List<? extends WildcardMatcher> matchers) {
return new ElementMatcher.Junction.AbstractBase<NamedElement>() {
@Override
public boolean matches(NamedElement target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@
package co.elastic.apm.agent.configuration;

import co.elastic.apm.agent.bci.ElasticApmAgent;
import co.elastic.apm.agent.configuration.converter.ListValueConverter;
import co.elastic.apm.agent.configuration.converter.RoundedDoubleConverter;
import co.elastic.apm.agent.configuration.converter.TimeDuration;
import co.elastic.apm.agent.configuration.converter.TimeDurationValueConverter;
import co.elastic.apm.agent.configuration.converter.*;
import co.elastic.apm.agent.configuration.validation.RegexValidator;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.matcher.MethodMatcher;
import co.elastic.apm.agent.matcher.MethodMatcherValueConverter;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
Expand Down Expand Up @@ -59,7 +55,7 @@
import static co.elastic.apm.agent.configuration.validation.RangeValidator.isInRange;
import static co.elastic.apm.agent.logging.LoggingConfiguration.AGENT_HOME_PLACEHOLDER;

public class CoreConfiguration extends ConfigurationOptionProvider {
public class CoreConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.plugin.spi.CoreConfiguration {

private final Logger logger = LoggerFactory.getLogger(getClass());

Expand Down Expand Up @@ -1077,6 +1073,11 @@ public TraceContinuationStrategy getTraceContinuationStrategy() {
return traceContinuationStrategy.get();
}

@Override
public boolean isCaptureBody() {
return getCaptureBody() != EventType.OFF;
}

public enum EventType {
/**
* Request bodies will never be reported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package co.elastic.apm.agent.configuration;

import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.configuration.converter.WildcardMatcher;
import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter;
import org.stagemonitor.configuration.ConfigurationOption;
import org.stagemonitor.configuration.ConfigurationOptionProvider;
Expand All @@ -28,7 +28,7 @@
import java.util.Collections;
import java.util.List;

public class MessagingConfiguration extends ConfigurationOptionProvider {
public class MessagingConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.plugin.spi.MessagingConfiguration {
private static final String MESSAGING_CATEGORY = "Messaging";
private static final String MESSAGE_POLLING_TRANSACTION_STRATEGY = "message_polling_transaction_strategy";
private static final String MESSAGE_BATCH_STRATEGY = "message_batch_strategy";
Expand Down Expand Up @@ -130,6 +130,21 @@ public Collection<String> getJmsListenerPackages() {
return jmsListenerPackages.get();
}

@Override
public boolean isMessageTransactionPolling() {
return getMessagePollingTransactionStrategy() != JmsStrategy.HANDLING;
}

@Override
public boolean isMessageTransactionHandling() {
return getMessagePollingTransactionStrategy() != JmsStrategy.POLLING;
}

@Override
public boolean isMessageBatchHandling() {
return getMessageBatchStrategy() == BatchStrategy.BATCH_HANDLING;
}

public enum JmsStrategy {
/**
* Create a transaction capturing JMS {@code receive} invocations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package co.elastic.apm.agent.configuration.converter;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;

public class WildcardMatcher extends co.elastic.apm.agent.common.util.WildcardMatcher implements co.elastic.apm.plugin.spi.WildcardMatcher {

private static final WildcardMatcher MATCH_ALL = new WildcardMatcher(co.elastic.apm.agent.common.util.WildcardMatcher.matchAll());
private static final List<WildcardMatcher> MATCH_ALL_LIST = Collections.singletonList(MATCH_ALL);

private final co.elastic.apm.agent.common.util.WildcardMatcher matcher;

public WildcardMatcher(co.elastic.apm.agent.common.util.WildcardMatcher matcher) {
this.matcher = matcher;
}

public static WildcardMatcher valueOf(String wildcardString) {
return new WildcardMatcher(co.elastic.apm.agent.common.util.WildcardMatcher.valueOf(wildcardString));
}

public static WildcardMatcher caseSensitiveMatcher(String matcher) {
return new WildcardMatcher(co.elastic.apm.agent.common.util.WildcardMatcher.caseSensitiveMatcher(matcher));
}

public static WildcardMatcher matchAll() {
return MATCH_ALL;
}

public static List<WildcardMatcher> matchAllList() {
return MATCH_ALL_LIST;
}

@Override
public boolean matches(CharSequence s) {
return matcher.matches(s);
}

@Override
public boolean matches(CharSequence firstPart, @Nullable CharSequence secondPart) {
return matcher.matches(firstPart, secondPart);
}

@Override
public String getMatcher() {
return matcher.getMatcher();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package co.elastic.apm.agent.impl.context.web;

import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.configuration.converter.WildcardMatcher;
import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter;
import org.stagemonitor.configuration.ConfigurationOption;
import org.stagemonitor.configuration.ConfigurationOptionProvider;
Expand All @@ -28,7 +28,7 @@
import java.util.Collections;
import java.util.List;

public class WebConfiguration extends ConfigurationOptionProvider {
public class WebConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.plugin.spi.WebConfiguration {

private static final String HTTP_CATEGORY = "HTTP";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.Collection;
import java.util.Collections;

public class StacktraceConfiguration extends ConfigurationOptionProvider {
public class StacktraceConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.plugin.spi.StacktraceConfiguration {

private static final String STACKTRACE_CATEGORY = "Stacktrace";
public static final String APPLICATION_PACKAGES = "application_packages";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import co.elastic.apm.agent.common.util.SystemStandardOutputLogger;
import co.elastic.apm.agent.configuration.converter.ByteValue;
import co.elastic.apm.agent.configuration.converter.ByteValueConverter;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.configuration.converter.WildcardMatcher;
import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
import org.apache.logging.log4j.Level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package co.elastic.apm.agent.matcher;

import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.configuration.converter.WildcardMatcher;
import org.stagemonitor.configuration.converter.ValueConverter;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
*/
package co.elastic.apm.agent.report;

import co.elastic.apm.agent.configuration.converter.ByteValue;
import co.elastic.apm.agent.configuration.converter.ByteValueConverter;
import co.elastic.apm.agent.configuration.converter.TimeDuration;
import co.elastic.apm.agent.configuration.converter.TimeDurationValueConverter;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.configuration.converter.*;
import co.elastic.apm.agent.matcher.WildcardMatcherValueConverter;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
import org.stagemonitor.configuration.ConfigurationOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ElementMatcher<? super TypeDescription> getTypeMatcher() {
public ElementMatcher<? super MethodDescription> getMethodMatcher() {
ElementMatcher.Junction<? super MethodDescription> matcher = matches(methodMatcher.getMethodMatcher());

final List<WildcardMatcher> methodsExcludedFromInstrumentation = config.getMethodsExcludedFromInstrumentation();
final List<? extends WildcardMatcher> methodsExcludedFromInstrumentation = config.getMethodsExcludedFromInstrumentation();
if (!methodsExcludedFromInstrumentation.isEmpty()) {
matcher = matcher.and(not(new ElementMatcher<MethodDescription>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
package co.elastic.apm.agent.util;

import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.plugin.spi.WildcardMatcher;
import co.elastic.apm.plugin.spi.WildcardMatcherUtil;

import javax.annotation.Nullable;
import java.util.List;
Expand Down Expand Up @@ -75,15 +76,15 @@ public static void setNameFromClassAndMethod(String className, @Nullable String

}

public static void setNameFromHttpRequestPath(String method, String path, @Nullable StringBuilder transactionName, List<WildcardMatcher> urlGroups) {
public static void setNameFromHttpRequestPath(String method, String path, @Nullable StringBuilder transactionName, List<? extends WildcardMatcher> urlGroups) {
setNameFromHttpRequestPath(method, path, null, transactionName, urlGroups);
}

public static void setNameFromHttpRequestPath(String method, String pathFirstPart, @Nullable String pathSecondPart, @Nullable StringBuilder transactionName, List<WildcardMatcher> urlGroups) {
public static void setNameFromHttpRequestPath(String method, String pathFirstPart, @Nullable String pathSecondPart, @Nullable StringBuilder transactionName, List<? extends WildcardMatcher> urlGroups) {
if (transactionName == null) {
return;
}
WildcardMatcher groupMatcher = WildcardMatcher.anyMatch(urlGroups, pathFirstPart, pathSecondPart);
WildcardMatcher groupMatcher = WildcardMatcherUtil.anyMatch(urlGroups, pathFirstPart, pathSecondPart);
if (groupMatcher != null) {
transactionName.append(method).append(' ').append(groupMatcher);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package co.elastic.apm.agent.configuration;

import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.agent.configuration.converter.WildcardMatcher;
import org.junit.jupiter.api.Test;
import org.stagemonitor.configuration.ConfigurationRegistry;
import org.stagemonitor.configuration.source.SimpleSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import co.elastic.apm.agent.AbstractInstrumentationTest;
import co.elastic.apm.agent.impl.context.web.WebConfiguration;
import co.elastic.apm.agent.common.util.WildcardMatcher;
import co.elastic.apm.plugin.spi.WildcardMatcher;
import co.elastic.apm.plugin.spi.WildcardMatcherUtil;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -97,9 +98,9 @@ void testClassAndMethodName() {

@Test
void setNameFromHttpRequestPath() {
List<WildcardMatcher> urlGroups = List.of(
WildcardMatcher.valueOf("/foo/bar/*/qux"),
WildcardMatcher.valueOf("/foo/bar/*")
List<co.elastic.apm.plugin.spi.WildcardMatcher> urlGroups = List.of(
WildcardMatcherUtil.valueOf("/foo/bar/*/qux"),
WildcardMatcherUtil.valueOf("/foo/bar/*")
);

// shuold be a no-op
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package co.elastic.apm.plugin.spi;

import java.util.List;

public interface CoreConfiguration {
boolean isEnablePublicApiAnnotationInheritance();

boolean isCaptureHeaders();

List<? extends WildcardMatcher> getSanitizeFieldNames();

boolean isCaptureBody();

boolean isInstrumentationEnabled(String instrumentationGroupName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package co.elastic.apm.plugin.spi;

public class DisabledObjectPool<T> implements ObjectPool<T> {

private final Allocator<T> allocator;

public DisabledObjectPool(Allocator<T> allocator) {
this.allocator = allocator;
}

@Override
public T createInstance() {
return allocator.createInstance();
}

@Override
public void recycle(T obj) {
}

@Override
public void clear() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package co.elastic.apm.plugin.spi;

public class DisabledObjectPoolFactory implements ObjectPoolFactory {

public static final ObjectPoolFactory INSTANCE = new DisabledObjectPoolFactory();

private DisabledObjectPoolFactory() {
}

@Override
public <T extends Recyclable> ObjectPool<T> createRecyclableObjectPool(int maxCapacity, Allocator<T> allocator) {
return new DisabledObjectPool<T>(allocator);
}
}
Loading

0 comments on commit b31c3d5

Please sign in to comment.