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
1 change: 0 additions & 1 deletion agent-lambda/script/solarwinds-apm-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"agent.logging": "info",
"monitor.jmx.enable": false,
"profiler": {
"enabled": false,
"excludePackages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ public void customize(DeclarativeConfigurationCustomizer customizer) {
customizer.addModelCustomizer(
configurationModel -> {
TracerProviderModel tracerProvider = configurationModel.getTracerProvider();
if (tracerProvider == null) {
tracerProvider = new TracerProviderModel();
configurationModel.withTracerProvider(tracerProvider);
if (tracerProvider != null) {
addProcessors(tracerProvider);
}

ResourceModel resourceModel = configurationModel.getResource();
Expand All @@ -51,7 +50,6 @@ public void customize(DeclarativeConfigurationCustomizer customizer) {
}

addResourceDetector(resourceModel);
addProcessors(tracerProvider);
return configurationModel;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mockStatic;
Expand Down Expand Up @@ -58,7 +59,7 @@ void verifyThatProfilingProcessorIsAddedWhenJdkVersionIsSupported() {
.thenReturn(true);

OpenTelemetryConfigurationModel openTelemetryConfigurationModel =
new OpenTelemetryConfigurationModel();
new OpenTelemetryConfigurationModel().withTracerProvider(new TracerProviderModel());

doNothing()
.when(declarativeConfigurationCustomizerMock)
Expand Down Expand Up @@ -88,7 +89,7 @@ void verifyThatProfilingProcessorIsNotAddedWhenJdkVersionIsNotSupported() {
.thenReturn(false);

OpenTelemetryConfigurationModel openTelemetryConfigurationModel =
new OpenTelemetryConfigurationModel();
new OpenTelemetryConfigurationModel().withTracerProvider(new TracerProviderModel());

doNothing()
.when(declarativeConfigurationCustomizerMock)
Expand Down Expand Up @@ -133,4 +134,27 @@ void verifyThatResourceDetectorIsAlwaysAdded() {
.isEmpty());
}
}

@Test
void processorsNotAddedWhenTracerProviderAbsent() {
try (MockedStatic<JavaRuntimeVersionChecker> javaRuntimeVersionCheckerMockedStatic =
mockStatic(JavaRuntimeVersionChecker.class)) {
javaRuntimeVersionCheckerMockedStatic
.when(JavaRuntimeVersionChecker::isJdkVersionSupported)
.thenReturn(true);

OpenTelemetryConfigurationModel openTelemetryConfigurationModel =
new OpenTelemetryConfigurationModel();

doNothing()
.when(declarativeConfigurationCustomizerMock)
.addModelCustomizer(functionArgumentCaptor.capture());

tested.customize(declarativeConfigurationCustomizerMock);
functionArgumentCaptor.getValue().apply(openTelemetryConfigurationModel);

assertNull(openTelemetryConfigurationModel.getTracerProvider());
assertNotNull(openTelemetryConfigurationModel.getResource());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@
*/
public enum ConfigGroup {
AGENT,
MONITOR,
PROFILER
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public enum ConfigProperty {
ConfigGroup.AGENT,
String.class),
AGENT_LOG_FILE(
new ConfigKey(null, EnvPrefix.PRODUCT + "JAVA_LOG_FILE"), ConfigGroup.AGENT, String.class),
new ConfigKey("agent.javaLogFile", EnvPrefix.PRODUCT + "JAVA_LOG_FILE"),
ConfigGroup.AGENT,
String.class),
AGENT_COLLECTOR(
new ConfigKey("agent.collector", EnvPrefix.PRODUCT + "COLLECTOR"),
ConfigGroup.AGENT,
Expand Down Expand Up @@ -146,19 +148,6 @@ public enum ConfigProperty {
new ConfigKey("agent.sqlTagDatabases", EnvPrefix.PRODUCT + "SQL_TAG_DATABASES"),
ConfigGroup.AGENT,
String.class),
MONITOR_JMX_SCOPES(new ConfigKey("monitor.jmx.scopes"), ConfigGroup.MONITOR, String.class),
MONITOR_JMX_ENABLE(new ConfigKey("monitor.jmx.enable"), ConfigGroup.MONITOR, Boolean.class),
MONITOR_JMX_MAX_ENTRY(new ConfigKey("monitor.jmx.maxEntry"), ConfigGroup.MONITOR, Integer.class),
MONITOR_METRICS_FLUSH_INTERVAL(
new ConfigKey(null, EnvPrefix.PRODUCT + "METRICS_FLUSH_INTERVAL"),
ConfigGroup.MONITOR,
Integer.class),

MONITOR_SPAN_METRICS_ENABLE(
new ConfigKey("monitor.spanMetrics.enable", EnvPrefix.PRODUCT + "SPAN_METRICS_ENABLE"),
ConfigGroup.MONITOR,
Boolean.class),

PROFILER(new ConfigKey("profiler"), ConfigGroup.PROFILER, String.class),
PROFILER_ENABLED_ENV_VAR(
new ConfigKey(null, EnvPrefix.PRODUCT + "PROFILER_ENABLED"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* © SolarWinds Worldwide, LLC. All rights reserved.
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.solarwinds.opentelemetry.extensions.config.parser.yaml;

import com.google.auto.service.AutoService;
import com.solarwinds.joboe.config.ConfigParser;
import com.solarwinds.joboe.config.InvalidConfigException;
import com.solarwinds.opentelemetry.extensions.Constants;
import com.solarwinds.opentelemetry.extensions.config.parser.json.RangeValidationParser;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;

@SuppressWarnings("rawtypes")
@AutoService(ConfigParser.class)
public class SqlQueryMaxLengthParser implements ConfigParser<DeclarativeConfigProperties, Integer> {
private static final String CONFIG_KEY = "agent.sqlQueryMaxLength";

private static final RangeValidationParser<Integer> RANGE_VALIDATOR =
new RangeValidationParser<>(
Constants.MAX_SQL_QUERY_LENGTH_LOWER_LIMIT, Constants.MAX_SQL_QUERY_LENGTH_UPPER_LIMIT);

@Override
public Integer convert(DeclarativeConfigProperties declarativeConfigProperties)
throws InvalidConfigException {
Integer value = declarativeConfigProperties.getInt(CONFIG_KEY);
if (value == null) {
return null;
}
return RANGE_VALIDATOR.convert(value);
}

@Override
public String configKey() {
return CONFIG_KEY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* © SolarWinds Worldwide, LLC. All rights reserved.
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.solarwinds.opentelemetry.extensions.config.parser.yaml;

import com.google.auto.service.AutoService;
import com.solarwinds.joboe.config.ConfigParser;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;

@SuppressWarnings("rawtypes")
@AutoService(ConfigParser.class)
public class TriggerTraceParser implements ConfigParser<DeclarativeConfigProperties, Boolean> {
private static final String CONFIG_KEY = "agent.triggerTrace";

@Override
public Boolean convert(DeclarativeConfigProperties declarativeConfigProperties) {
return declarativeConfigProperties.getBoolean(CONFIG_KEY, true);
}

@Override
public String configKey() {
return CONFIG_KEY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public TraceConfigs convert(DeclarativeConfigProperties declarativeConfigPropert
urlSampleRate.getStructured(url, DeclarativeConfigProperties.empty());
TraceConfig traceConfig = extractConfig(urlConfig, declarativeConfigProperties);

if (traceConfig != null) {
result.put(new StringPatternMatcher(pattern), traceConfig);
}
result.put(new StringPatternMatcher(pattern), traceConfig);
}

return new TraceConfigs(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,31 @@ public void customize(DeclarativeConfigurationCustomizer customizer) {
if (meterProvider == null) {
meterProvider = new MeterProviderModel();
configurationModel.withMeterProvider(meterProvider);
try {
ConfigManager.setConfig(ConfigProperty.AGENT_EXPORT_METRICS_ENABLED, false);
} catch (InvalidConfigException ignore) {
}
Comment thread
jerrytfleung marked this conversation as resolved.
}
addMetricExporter(configurationModel);

if (tracerProvider == null) {
tracerProvider = new TracerProviderModel();
configurationModel.withTracerProvider(tracerProvider);
}
if (tracerProvider != null) {
addSampler(tracerProvider);
addProcessors(tracerProvider);

if (loggerProvider == null) {
loggerProvider = new LoggerProviderModel();
configurationModel.withLoggerProvider(loggerProvider);
addSpanExporter(configurationModel);
}

addSampler(tracerProvider);
addProcessors(tracerProvider);
addMetricExporter(configurationModel);
if (loggerProvider != null) {
addLogExporter(configurationModel);
}

addLogExporter(configurationModel);
addSpanExporter(configurationModel);
PropagatorModel propagatorModel = new PropagatorModel();
PropagatorModel propagatorModel = configurationModel.getPropagator();
if (propagatorModel == null) {
propagatorModel = new PropagatorModel();
configurationModel.withPropagator(propagatorModel);
}

addContextPropagators(propagatorModel);
configurationModel.withPropagator(propagatorModel);
return configurationModel;
});
}
Expand Down Expand Up @@ -156,9 +159,15 @@ private void addSampler(TracerProviderModel model) {
}

private void addContextPropagators(PropagatorModel model) {
model.withCompositeList(
String.format(
"tracecontext,baggage,%s", ContextPropagatorComponentProvider.COMPONENT_NAME));
String compositeList = model.getCompositeList();
if (compositeList != null) {
model.withCompositeList(
String.format("%s,%s", compositeList, ContextPropagatorComponentProvider.COMPONENT_NAME));
} else {
model.withCompositeList(
String.format(
"tracecontext,baggage,%s", ContextPropagatorComponentProvider.COMPONENT_NAME));
}
Comment thread
jerrytfleung marked this conversation as resolved.
}

private void addSpanExporter(OpenTelemetryConfigurationModel model) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* © SolarWinds Worldwide, LLC. All rights reserved.
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.solarwinds.opentelemetry.extensions.config.parser.yaml;

import static org.junit.jupiter.api.Assertions.*;

import com.solarwinds.joboe.config.InvalidConfigException;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.extension.incubator.fileconfig.DeclarativeConfiguration;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

class SqlQueryMaxLengthParserTest {
private static DeclarativeConfigProperties declarativeConfigProperties;
private final SqlQueryMaxLengthParser tested = new SqlQueryMaxLengthParser();

@BeforeAll
static void setup() {
try (InputStream resourceAsStream =
SqlQueryMaxLengthParserTest.class.getResourceAsStream("/sdk-config.yaml")) {
DeclarativeConfigProperties configProperties =
DeclarativeConfiguration.toConfigProperties(resourceAsStream);
declarativeConfigProperties =
configProperties
.getStructured("instrumentation/development", DeclarativeConfigProperties.empty())
.getStructured("java", DeclarativeConfigProperties.empty())
.getStructured("solarwinds");
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Test
void testConvertValidValue() throws InvalidConfigException {
Integer result = tested.convert(declarativeConfigProperties);
assertEquals(4096, result);
}

@Test
void testConvertNull() throws InvalidConfigException {
Integer result = tested.convert(DeclarativeConfigProperties.empty());
assertNull(result);
}

@Test
void testConvertBelowRange() {
assertThrows(InvalidConfigException.class, () -> tested.convert(propsWithValue(100)));
}

@Test
void testConvertAboveRange() {
assertThrows(InvalidConfigException.class, () -> tested.convert(propsWithValue(200000)));
}

@Test
void configKey() {
assertEquals("agent.sqlQueryMaxLength", tested.configKey());
}

private DeclarativeConfigProperties propsWithValue(int value) {
String yaml = "agent.sqlQueryMaxLength: " + value + "\n";
return DeclarativeConfiguration.toConfigProperties(
new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
}
}
Loading
Loading