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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.solarwinds.joboe.logging.LogSanitizer;
import com.solarwinds.joboe.logging.Logger;
import com.solarwinds.joboe.logging.LoggerFactory;
import com.solarwinds.joboe.sampling.TraceConfigs;
import com.solarwinds.opentelemetry.extensions.Constants;
import com.solarwinds.opentelemetry.extensions.LoggingConfigProvider;
import com.solarwinds.opentelemetry.extensions.NamingScheme;
Expand All @@ -49,7 +48,6 @@
import com.solarwinds.opentelemetry.extensions.config.parser.json.TracingModeParser;
import com.solarwinds.opentelemetry.extensions.config.parser.json.TransactionNamingSchemesParser;
import com.solarwinds.opentelemetry.extensions.config.parser.json.TransactionSettingsConfigParser;
import com.solarwinds.opentelemetry.extensions.config.parser.json.UrlSampleRateConfigParser;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -91,7 +89,6 @@ public class ConfigurationLoader {
new RangeValidationParser<Integer>(
Constants.MAX_SQL_QUERY_LENGTH_LOWER_LIMIT,
Constants.MAX_SQL_QUERY_LENGTH_UPPER_LIMIT));
ConfigProperty.AGENT_URL_SAMPLE_RATE.setParser(UrlSampleRateConfigParser.INSTANCE);
ConfigProperty.AGENT_TRANSACTION_SETTINGS.setParser(TransactionSettingsConfigParser.INSTANCE);
ConfigProperty.AGENT_TRIGGER_TRACE_ENABLED.setParser(ModeStringToBooleanParser.INSTANCE);
ConfigProperty.AGENT_PROXY.setParser(ProxyConfigParser.INSTANCE);
Expand Down Expand Up @@ -441,25 +438,6 @@ public static void processConfigs(ConfigContainer configs) throws InvalidConfigE
}
}

TraceConfigs traceConfigs = null;
if (configs.containsProperty(ConfigProperty.AGENT_TRANSACTION_SETTINGS)) {
if (configs.containsProperty(ConfigProperty.AGENT_URL_SAMPLE_RATE)) {
logger.warn(
ConfigProperty.AGENT_URL_SAMPLE_RATE.getConfigFileKey()
+ " is ignored as "
+ ConfigProperty.AGENT_TRANSACTION_SETTINGS.getConfigFileKey()
+ " is also defined");
}
traceConfigs = (TraceConfigs) configs.get(ConfigProperty.AGENT_TRANSACTION_SETTINGS);

} else if (configs.containsProperty(ConfigProperty.AGENT_URL_SAMPLE_RATE)) {
traceConfigs = (TraceConfigs) configs.get(ConfigProperty.AGENT_URL_SAMPLE_RATE);
}

if (traceConfigs != null) {
configs.put(ConfigProperty.AGENT_INTERNAL_TRANSACTION_SETTINGS, traceConfigs);
}

if (configs.containsProperty(ConfigProperty.AGENT_TRANSACTION_NAMING_SCHEMES)) {
Object schemes = configs.get(ConfigProperty.AGENT_TRANSACTION_NAMING_SCHEMES);
if (schemes instanceof List<?>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public enum ConfigProperty {
new ConfigKey("agent.sqlQueryMaxLength", EnvPrefix.PRODUCT + "MAX_SQL_QUERY_LENGTH"),
ConfigGroup.AGENT,
Integer.class),
AGENT_URL_SAMPLE_RATE(new ConfigKey("agent.urlSampleRates"), ConfigGroup.AGENT, String.class),
AGENT_TIME_ADJUST_INTERVAL(
new ConfigKey("agent.timeAdjustInterval"), ConfigGroup.AGENT, Integer.class),
AGENT_CONTEXT_TTL(new ConfigKey("agent.contextTtl"), ConfigGroup.AGENT, Integer.class),
Expand Down Expand Up @@ -103,11 +102,6 @@ public enum ConfigProperty {
new ConfigKey("agent.transactionSettings"), ConfigGroup.AGENT, String.class),
AGENT_TRANSACTION_NAMING_SCHEMES(
new ConfigKey("agent.transactionNameSchemes"), ConfigGroup.AGENT, String.class),
// AGENT_INTERNAL_TRANSACTION_SETTINGS should NOT be specified directly in the json file. This is
// used to store the result after comparing AGENT_TRANSACTION_SETTINGS and AGENT_URL_SAMPLE_RATE -
// not an ideal solution as this is confusing
AGENT_INTERNAL_TRANSACTION_SETTINGS(
new ConfigKey("agent.internal.transactionSettings"), ConfigGroup.AGENT, String.class),
AGENT_EC2_METADATA_TIMEOUT(
new ConfigKey("agent.ec2MetadataTimeout", EnvPrefix.PRODUCT + "EC2_METADATA_TIMEOUT"),
ConfigGroup.AGENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
Expand All @@ -29,6 +32,9 @@
* @author Patson Luk
*/
public class JsonConfigReader extends ConfigReader {
private static final Set<String> REMOVED_KEYS =
Collections.unmodifiableSet(new HashSet<>(Collections.singletonList("agent.urlSampleRates")));

private final InputStream configStream;

/**
Expand All @@ -50,19 +56,24 @@ public void read(ConfigContainer container) throws InvalidConfigException {
try {
jsonObject = new JSONObject(new JSONTokener(configStream));

for (Object keyAsObject : jsonObject.keySet()) {
for (String keyAsObject : jsonObject.keySet()) {
if (REMOVED_KEYS.contains(keyAsObject)) {
logger.warn(
"Configuration key [" + keyAsObject + "] is no longer supported and will be ignored");
continue;
}

ConfigProperty key =
ConfigProperty.fromConfigFileKey(
(String)
keyAsObject); // attempt to retrieve the corresponding ConfigProperty as key
keyAsObject); // attempt to retrieve the corresponding ConfigProperty as key

if (key == null) {
exceptions.add(
new InvalidConfigException(
"Invalid line in configuration file : key [" + keyAsObject + "] is invalid"));
} else {
try {
Object value = jsonObject.get((String) keyAsObject);
Object value = jsonObject.get(keyAsObject);
if (value != null) {
container.putByStringValue(key, value.toString());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

public class JsonConfigReaderTest {
Expand Down Expand Up @@ -50,4 +52,17 @@ public void testPartialRead() {
assertEquals("info", container.get(ConfigProperty.AGENT_LOGGING));
assertEquals("some key", container.get(ConfigProperty.AGENT_SERVICE_KEY));
}

@Test
public void testRemovedKeyIsIgnored() throws InvalidConfigException {
String json =
"{\"agent.urlSampleRates\": [{\".*/greet\": {\"sampleRate\": 1000000}}],"
+ " \"agent.serviceKey\": \"some key\"}";
JsonConfigReader reader =
new JsonConfigReader(new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)));
ConfigContainer container = new ConfigContainer();
reader.read(container);

assertEquals("some key", container.get(ConfigProperty.AGENT_SERVICE_KEY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.solarwinds.joboe.logging.LogSanitizer;
import com.solarwinds.joboe.logging.Logger;
import com.solarwinds.joboe.logging.LoggerFactory;
import com.solarwinds.joboe.sampling.TraceConfigs;
import com.solarwinds.opentelemetry.extensions.config.parser.json.LogSettingParser;
import com.solarwinds.opentelemetry.extensions.config.parser.json.ModeStringToBooleanParser;
import com.solarwinds.opentelemetry.extensions.config.parser.json.RangeValidationParser;
Expand All @@ -38,7 +37,6 @@
import com.solarwinds.opentelemetry.extensions.config.parser.json.TracingModeParser;
import com.solarwinds.opentelemetry.extensions.config.parser.json.TransactionNamingSchemesParser;
import com.solarwinds.opentelemetry.extensions.config.parser.json.TransactionSettingsConfigParser;
import com.solarwinds.opentelemetry.extensions.config.parser.json.UrlSampleRateConfigParser;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -66,7 +64,6 @@ public class LambdaConfigurationLoader {
new RangeValidationParser<>(
Constants.MAX_SQL_QUERY_LENGTH_LOWER_LIMIT,
Constants.MAX_SQL_QUERY_LENGTH_UPPER_LIMIT));
ConfigProperty.AGENT_URL_SAMPLE_RATE.setParser(UrlSampleRateConfigParser.INSTANCE);
ConfigProperty.AGENT_TRANSACTION_SETTINGS.setParser(TransactionSettingsConfigParser.INSTANCE);
ConfigProperty.AGENT_TRIGGER_TRACE_ENABLED.setParser(ModeStringToBooleanParser.INSTANCE);
ConfigProperty.AGENT_TRANSACTION_NAMING_SCHEMES.setParser(new TransactionNamingSchemesParser());
Expand Down Expand Up @@ -286,25 +283,6 @@ public static void processConfigs(ConfigContainer configs) throws InvalidConfigE
configs.put(ConfigProperty.AGENT_LOGGING, false);
}

TraceConfigs traceConfigs = null;
if (configs.containsProperty(ConfigProperty.AGENT_TRANSACTION_SETTINGS)) {
if (configs.containsProperty(ConfigProperty.AGENT_URL_SAMPLE_RATE)) {
logger.warn(
ConfigProperty.AGENT_URL_SAMPLE_RATE.getConfigFileKey()
+ " is ignored as "
+ ConfigProperty.AGENT_TRANSACTION_SETTINGS.getConfigFileKey()
+ " is also defined");
}
traceConfigs = (TraceConfigs) configs.get(ConfigProperty.AGENT_TRANSACTION_SETTINGS);

} else if (configs.containsProperty(ConfigProperty.AGENT_URL_SAMPLE_RATE)) {
traceConfigs = (TraceConfigs) configs.get(ConfigProperty.AGENT_URL_SAMPLE_RATE);
}

if (traceConfigs != null) {
configs.put(ConfigProperty.AGENT_INTERNAL_TRANSACTION_SETTINGS, traceConfigs);
}

if (configs.containsProperty(ConfigProperty.AGENT_TRANSACTION_NAMING_SCHEMES)) {
Object schemes = configs.get(ConfigProperty.AGENT_TRANSACTION_NAMING_SCHEMES);
if (schemes instanceof List<?>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ public class SamplingConfiguration {

TracingMode tracingMode;

TraceConfigs internalTransactionSettings;
TraceConfigs transactionSettings;
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ private static TraceConfig getLocalUniversalTraceConfig() {
*/
private static TraceConfig getLocalSpecificTraceConfig(List<String> signals) {
if (signals != null
&& SettingsManager.getSamplingConfiguration().getInternalTransactionSettings() != null) {
&& SettingsManager.getSamplingConfiguration().getTransactionSettings() != null) {
return SettingsManager.getSamplingConfiguration()
.getInternalTransactionSettings()
.getTransactionSettings()
.getTraceConfig(signals);
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ public void testPrecedence() throws Exception {
// local URL : ENBALED/100%
// local universal : DISABLED/null
// remote : ENABLED/100%
TraceConfigs testingUrlSampleRateConfigs =
TraceConfigs testingTransactionSettings =
buildUrlConfigs(url -> true, TracingMode.ALWAYS, 1000000);
SettingsManager.initialize(
settingsFetcherMock,
SamplingConfiguration.builder()
.internalTransactionSettings(testingUrlSampleRateConfigs)
.transactionSettings(testingTransactionSettings)
.tracingMode(TracingMode.DISABLED)
.build());

Expand Down Expand Up @@ -284,7 +284,7 @@ public void testPrecedence() throws Exception {
SettingsManager.initialize(
settingsFetcherMock,
SamplingConfiguration.builder()
.internalTransactionSettings(new TraceConfigs(urlTraceConfigsByMatcher))
.transactionSettings(new TraceConfigs(urlTraceConfigsByMatcher))
.tracingMode(TracingMode.DISABLED)
.build());

Expand Down Expand Up @@ -346,13 +346,11 @@ public void testUrlConfigs() throws Exception {
.isReportMetrics());

// Add local URL rate, should override the SRv1 rate if pattern matches
TraceConfigs testingUrlSampleRateConfigs =
TraceConfigs testingTransactionSettings =
buildUrlConfigs(url -> url.endsWith(".html"), TracingMode.ALWAYS, 0);
SettingsManager.initialize(
settingsFetcherMock,
SamplingConfiguration.builder()
.internalTransactionSettings(testingUrlSampleRateConfigs)
.build());
SamplingConfiguration.builder().transactionSettings(testingTransactionSettings).build());

// pattern match, should all have sample rate 0% for new traces, but continuing/AVW trace should
// still go on
Expand Down Expand Up @@ -390,13 +388,11 @@ public void testUrlConfigs() throws Exception {
.isReportMetrics());

// Add local URL rate, should override the SRv1 rate if pattern matches
testingUrlSampleRateConfigs =
testingTransactionSettings =
buildUrlConfigs(url -> url.endsWith(".html"), TracingMode.NEVER, 0);
SettingsManager.initialize(
settingsFetcherMock,
SamplingConfiguration.builder()
.internalTransactionSettings(testingUrlSampleRateConfigs)
.build());
SamplingConfiguration.builder().transactionSettings(testingTransactionSettings).build());

// pattern match, should block all traffic even for continuing traces since the url tracingMode
// is never
Expand Down Expand Up @@ -448,7 +444,7 @@ public void testUrlConfigs() throws Exception {
SettingsManager.initialize(
settingsFetcherMock,
SamplingConfiguration.builder()
.internalTransactionSettings(new TraceConfigs(urlTraceConfigsByMatcher))
.transactionSettings(new TraceConfigs(urlTraceConfigsByMatcher))
.build());
TraceDecision traceDecision;

Expand Down Expand Up @@ -1134,13 +1130,11 @@ public void testLastSampleRate() throws Exception {
.thenReturn(SettingsStub.builder().withFlags(true, false, true, true, false).build());

// Add local URL rate, should override the SRv1 rate if pattern matches
TraceConfigs testingUrlSampleRateConfigs =
TraceConfigs testingTransactionSettings =
buildUrlConfigs(url -> url.endsWith("html"), TracingMode.NEVER, 0);
SettingsManager.initialize(
settingsFetcherMock,
SamplingConfiguration.builder()
.internalTransactionSettings(testingUrlSampleRateConfigs)
.build());
SamplingConfiguration.builder().transactionSettings(testingTransactionSettings).build());
TraceDecisionUtil.consumeLastTraceConfigs(); // clear it

when(settingsFetcherMock.getSettings())
Expand Down Expand Up @@ -1197,7 +1191,7 @@ public void testLastSampleRate() throws Exception {
SettingsManager.initialize(
settingsFetcherMock,
SamplingConfiguration.builder()
.internalTransactionSettings(testingUrlSampleRateConfigs)
.transactionSettings(testingTransactionSettings)
.sampleRate(500000)
.tracingMode(TracingMode.ALWAYS)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ public static SamplingConfiguration getSamplingConfiguration() {
SamplingConfiguration.SamplingConfigurationBuilder samplingConfigurationBuilder =
SamplingConfiguration.builder()
.tracingMode((TracingMode) ConfigManager.getConfig(ConfigProperty.AGENT_TRACING_MODE))
.internalTransactionSettings(
(TraceConfigs)
ConfigManager.getConfig(ConfigProperty.AGENT_INTERNAL_TRANSACTION_SETTINGS))
.transactionSettings(
(TraceConfigs) ConfigManager.getConfig(ConfigProperty.AGENT_TRANSACTION_SETTINGS))
.triggerTraceEnabled(
ConfigManager.getConfigOptional(
ConfigProperty.AGENT_TRIGGER_TRACE_ENABLED, true));
Expand Down
Loading
Loading