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: 1 addition & 0 deletions custom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
testImplementation(project(":libs:sampling"))
testImplementation(project(":libs:shared"))
testImplementation(project(":libs:core"))
testImplementation(project(":libs:logging"))

testImplementation("io.opentelemetry:opentelemetry-api-incubator")
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-declarative-config")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ private void registerShutdownTasks() {
new Thread("SolarwindsAPM-shutdown-hook") {
@Override
public void run() {
if (ReporterProvider.getEventReporter() != null) {
ReporterProvider.getEventReporter()
.close(); // close event reporter properly to give it chance to send out pending
// events in queue
}
ClientManagerProvider
.closeAllManagers(); // close all rpc client, this should flush out all messages or
// stop immediately (if not connected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.auto.service.AutoService;
import com.solarwinds.joboe.config.ConfigContainer;
import com.solarwinds.joboe.config.ConfigGroup;
import com.solarwinds.joboe.config.ConfigManager;
import com.solarwinds.joboe.config.InvalidConfigException;
import com.solarwinds.joboe.config.JavaRuntimeVersionChecker;
import com.solarwinds.joboe.logging.Logger;
Expand All @@ -30,7 +31,6 @@
import io.opentelemetry.sdk.autoconfigure.declarativeconfig.DeclarativeConfigurationCustomizer;
import io.opentelemetry.sdk.autoconfigure.declarativeconfig.DeclarativeConfigurationCustomizerProvider;
import io.opentelemetry.sdk.autoconfigure.declarativeconfig.model.OpenTelemetryConfigurationModel;
import java.util.Objects;

@AutoService(DeclarativeConfigurationCustomizerProvider.class)
public class DeclarativeLoader implements DeclarativeConfigurationCustomizerProvider {
Expand All @@ -49,13 +49,10 @@ private void loadConfig(OpenTelemetryConfigurationModel configurationModel) {
DeclarativeConfigProperties configProperties =
DeclarativeConfiguration.toConfigProperties(configurationModel);

// SolarwindsConfigResolver merges the distribution and instrumentation nodes per key
// (distribution takes precedence, instrumentation fills the rest); it returns null when
// neither node carries any properties.
DeclarativeConfigProperties solarwinds =
Objects.requireNonNull(
SolarwindsConfigResolver.resolve(configProperties),
"Solarwinds configuration cannot be null.");
configProperties
.getStructured("distribution", DeclarativeConfigProperties.empty())
.getStructured("solarwinds", DeclarativeConfigProperties.empty());

ConfigContainer configContainer = new ConfigContainer();
DeclarativeConfigParser declarativeConfigParser = new DeclarativeConfigParser(configContainer);
Expand All @@ -66,16 +63,18 @@ private void loadConfig(OpenTelemetryConfigurationModel configurationModel) {
throw new RuntimeException(e);
}

try {
ConfigurationLoader.processConfigs(configContainer);
ConfigContainer agentConfig = configContainer.subset(ConfigGroup.AGENT);
LoggerFactory.init(LoggingConfigProvider.getLoggerConfiguration(agentConfig));

logger.info("Loaded via declarative config");
} catch (InvalidConfigException e) {
throw new RuntimeException(e);
ConfigContainer configs = ConfigManager.getInstance().getConfigContainer();
if (configs == null) {
configs = configContainer;
} else {
configs.merge(configContainer);
}

ConfigManager.initialize(configs);
ConfigContainer agentConfig = configs.subset(ConfigGroup.AGENT);
LoggerFactory.init(LoggingConfigProvider.getLoggerConfiguration(agentConfig));

logger.info("Loaded via declarative config");
if (!JavaRuntimeVersionChecker.isJdkVersionSupported()) {
logger.warn(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.solarwinds.opentelemetry.extensions.config.HttpSettingsFetcher;
import com.solarwinds.opentelemetry.extensions.config.HttpSettingsReader;
import com.solarwinds.opentelemetry.extensions.config.HttpSettingsReaderDelegate;
import com.solarwinds.opentelemetry.extensions.config.ProxyHelper;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import java.util.function.Function;
Expand All @@ -43,12 +44,6 @@ public class HttpSamplerComponentProvider extends AbstractSamplerComponentProvid

private static final String CONTEXT_MAX_BACKTRACES = "context_max_backtraces";

private static final String PROXY = "proxy";

private static final String PROXY_HOST = "host";

private static final String PROXY_PORT = "port";

private static final long POLLING_INTERVAL_SECONDS = 60;

private final Function<ProxyConfig, HttpSettingsReaderDelegate> delegateFactory;
Expand Down Expand Up @@ -101,7 +96,7 @@ protected SettingsFetcher createSettingsFetcher(DeclarativeConfigProperties prop
serviceKey = ServiceKeyUtils.transformServiceKey(serviceKey);
return new HttpSettingsFetcher(
HttpSettingsReader.forFileConfig(
delegateFactory.apply(parseProxy(properties)), collector, serviceKey),
delegateFactory.apply(ProxyHelper.toProxyConfig(properties)), collector, serviceKey),
POLLING_INTERVAL_SECONDS);
}

Expand All @@ -123,20 +118,4 @@ private static String parseNonEmpty(DeclarativeConfigProperties properties, Stri
}
return value;
}

private ProxyConfig parseProxy(DeclarativeConfigProperties properties)
throws InvalidConfigException {
DeclarativeConfigProperties proxy = properties.getStructured(PROXY);
if (proxy == null) {
return null;
}

String host = proxy.getString(PROXY_HOST);
Integer port = proxy.getInt(PROXY_PORT);
if (host == null || host.isEmpty() || port == null || port < 1 || port > 65535) {
throw new InvalidConfigException(
"Invalid sampler proxy config, both proxy.host and a valid proxy.port are required");
}
return new ProxyConfig(host, port, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import com.solarwinds.joboe.config.ConfigProperty;
import com.solarwinds.joboe.config.InvalidConfigException;
import com.solarwinds.joboe.config.JavaRuntimeVersionChecker;
import com.solarwinds.joboe.config.ProxyConfig;
import com.solarwinds.joboe.config.ServiceKeyUtils;
import com.solarwinds.joboe.core.profiler.ProfilerSetting;
import com.solarwinds.opentelemetry.extensions.SolarwindsProfilingSpanProcessor;
import com.solarwinds.opentelemetry.extensions.config.ProxyHelper;
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider;
import io.opentelemetry.sdk.trace.SpanProcessor;
Expand All @@ -35,6 +38,10 @@ public class ProfilingSpanProcessorComponentProvider implements ComponentProvide

public static final String COMPONENT_NAME = "swo_profiler";

private static final String SERVICE_KEY = "service_key";

private static final String COLLECTOR = "collector";

private static final List<String> DEFAULT_EXCLUDE_PACKAGES =
Arrays.asList("java", "javax", "com.sun", "sun", "sunw");

Expand All @@ -51,27 +58,29 @@ public String getName() {
@Override
public SpanProcessor create(DeclarativeConfigProperties declarativeConfigProperties) {
try {
ProfilerSetting convert = convert(declarativeConfigProperties);
ConfigManager.setConfig(ConfigProperty.PROFILER, convert);
ProfilerSetting profilerSetting = convert(declarativeConfigProperties);
ConfigManager.setConfig(ConfigProperty.PROFILER, profilerSetting);
} catch (InvalidConfigException e) {
throw new RuntimeException(e);
}

return new SolarwindsProfilingSpanProcessor();
}

ProfilerSetting convert(DeclarativeConfigProperties profilerSettings)
ProfilerSetting convert(DeclarativeConfigProperties profilerProperties)
throws InvalidConfigException {

boolean enabled =
JavaRuntimeVersionChecker.isJdkVersionSupported()
&& profilerSettings.getBoolean("enabled", false);
&& profilerProperties.getBoolean("enabled", false);

int circuitBreakerDurationThreshold =
profilerSettings.getInt("circuit_breaker_duration_threshold", 100);
profilerProperties.getInt("circuit_breaker_duration_threshold", 100);

int circuitBreakerCountThreshold =
profilerSettings.getInt("circuit_breaker_count_threshold", 2);
profilerProperties.getInt("circuit_breaker_count_threshold", 2);

int interval = profilerSettings.getInt("interval", 20);
int interval = profilerProperties.getInt("interval", 20);
if (interval != 0
&& interval
< ProfilerSetting
Expand All @@ -83,8 +92,41 @@ ProfilerSetting convert(DeclarativeConfigProperties profilerSettings)
+ interval);
}

// Under declarative config, swo_profiler is the only source of the agent-wide AGENT_PROXY,
// AGENT_SERVICE_KEY and AGENT_COLLECTOR values read by RpcClientManager, and GrpcClient.
// Without a swo_profiler block they stay unset.
ProxyConfig proxyConfig = ProxyHelper.toProxyConfig(profilerProperties);
if (proxyConfig != null) {
ConfigManager.setConfig(ConfigProperty.AGENT_PROXY, proxyConfig);
}

String serviceKey = profilerProperties.getString(SERVICE_KEY);
if (serviceKey != null) {
if (serviceKey.trim().isEmpty()) {
throw new InvalidConfigException(
"Invalid profiler " + SERVICE_KEY + " config, value cannot be empty");
}

ConfigManager.setConfig(
ConfigProperty.AGENT_SERVICE_KEY, ServiceKeyUtils.transformServiceKey(serviceKey));

} else if (enabled) {
throw new InvalidConfigException("Missing required profiler " + SERVICE_KEY + " config");
}

String collector = profilerProperties.getString(COLLECTOR);
if (collector != null) {
if (collector.trim().isEmpty()) {
throw new InvalidConfigException(
"Invalid profiler " + COLLECTOR + " config, value cannot be empty");
}

ConfigManager.setConfig(ConfigProperty.AGENT_COLLECTOR, collector);
}

List<String> excludePackages =
profilerSettings.getScalarList("exclude_packages", String.class, DEFAULT_EXCLUDE_PACKAGES);
profilerProperties.getScalarList(
"exclude_packages", String.class, DEFAULT_EXCLUDE_PACKAGES);
return new ProfilerSetting(
enabled,
new HashSet<>(excludePackages),
Expand Down
Loading
Loading