Bump com.fasterxml.jackson:jackson-bom from 2.16.2 to 2.17.0 (#3597)

This commit is contained in:
dependabot[bot] 2024-04-14 15:04:28 +02:00 коммит произвёл GitHub
Родитель fa7e50ec2d
Коммит 1e5b8f663d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
63 изменённых файлов: 580 добавлений и 367 удалений

3
.github/dependabot.yml поставляемый
Просмотреть файл

@ -32,9 +32,6 @@ updates:
- dependency-name: "org.mockito:*"
# mockito 5 requires Java 11
versions: [ "[5,)" ]
- dependency-name: "uk.org.webcompere:system-stubs-jupiter"
# system-stubs-jupiter 2.1+ requires Java 11+
versions: [ "[2.1,)" ]
schedule:
interval: "daily"
open-pull-requests-limit: 10

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.26.1=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.26.1=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -82,7 +82,6 @@ dependencies {
testImplementation("org.assertj:assertj-core")
testImplementation("org.awaitility:awaitility")
testImplementation("org.mockito:mockito-core")
testImplementation("uk.org.webcompere:system-stubs-jupiter:2.0.3")
testImplementation("io.github.hakky54:logcaptor")
testCompileOnly("com.google.code.findbugs:jsr305")
@ -92,3 +91,9 @@ configurations.all {
// temporarily overriding version until next azure-bom release in order to address CVE
resolutionStrategy.force("com.azure:azure-identity:1.12.0")
}
configurations {
"implementation" {
exclude(group = "net.bytebuddy", module = "byte-buddy") // we use byte-buddy-dep
}
}

Просмотреть файл

@ -14,13 +14,13 @@ com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.azure:azure-storage-blob:12.25.3=runtimeClasspath
com.azure:azure-storage-common:12.24.3=runtimeClasspath
com.azure:azure-storage-internal-avro:12.10.3=runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.16.2=runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.16.2=runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.16.2=runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.16.2=runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.5.1=runtimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.17.0=runtimeClasspath
com.fasterxml.jackson.core:jackson-core:2.17.0=runtimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.17.0=runtimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.17.0=runtimeClasspath
com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.0=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.fasterxml.woodstox:woodstox-core:6.6.1=runtimeClasspath
com.github.oshi:oshi-core:6.5.0=runtimeClasspath
com.github.stephenc.jcip:jcip-annotations:1.0-1=runtimeClasspath
com.google.errorprone:error_prone_annotations:2.26.1=runtimeClasspath
@ -79,7 +79,7 @@ net.minidev:accessors-smart:2.5.0=runtimeClasspath
net.minidev:json-smart:2.5.0=runtimeClasspath
org.apache.commons:commons-lang3:3.13.0=runtimeClasspath
org.apache.commons:commons-text:1.11.0=runtimeClasspath
org.codehaus.woodstox:stax2-api:4.2.1=runtimeClasspath
org.codehaus.woodstox:stax2-api:4.2.2=runtimeClasspath
org.junit:junit-bom:5.10.2=runtimeClasspath
org.reactivestreams:reactive-streams:1.0.4=runtimeClasspath
org.slf4j:jcl-over-slf4j:2.0.12=runtimeClasspath

Просмотреть файл

@ -33,6 +33,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.apache.commons.text.StringSubstitutor;
import org.apache.commons.text.lookup.StringLookup;
@ -126,11 +127,17 @@ public class ConfigurationBuilder {
"https://go.microsoft.com/fwlink/?linkid=2153358";
// using deprecated fields to give warning message to user if they are still using them
public static Configuration create(Path agentJarPath, @Nullable RpConfiguration rpConfiguration)
public static Configuration create(
Path agentJarPath,
@Nullable RpConfiguration rpConfiguration,
Function<String, String> envVarsFunction,
Function<String, String> systemPropsFunction)
throws IOException {
Configuration config = loadConfigurationFile(agentJarPath);
Configuration config =
loadConfigurationFile(agentJarPath, envVarsFunction, systemPropsFunction);
logConfigurationWarnings(config);
overlayConfiguration(agentJarPath, rpConfiguration, config);
overlayConfiguration(
agentJarPath, rpConfiguration, config, envVarsFunction, systemPropsFunction);
return config;
}
@ -271,8 +278,13 @@ public class ConfigurationBuilder {
}
private static void overlayConfiguration(
Path agentJarPath, RpConfiguration rpConfiguration, Configuration config) throws IOException {
overlayFromEnv(config, agentJarPath.getParent());
Path agentJarPath,
RpConfiguration rpConfiguration,
Configuration config,
Function<String, String> envVarsFunction,
Function<String, String> systemPropsFunction)
throws IOException {
overlayFromEnv(config, agentJarPath.getParent(), envVarsFunction, systemPropsFunction);
config.sampling.percentage = roundToNearest(config.sampling.percentage, true);
for (SamplingOverride override : config.sampling.overrides) {
supportSamplingOverridesOldSemConv(override);
@ -281,7 +293,7 @@ public class ConfigurationBuilder {
// rp configuration should always be last (so it takes precedence)
// currently applicationinsights-rp.json is only used by Azure Spring Cloud
if (rpConfiguration != null) {
overlayFromEnv(rpConfiguration);
overlayFromEnv(rpConfiguration, envVarsFunction, systemPropsFunction);
overlayRpConfiguration(config, rpConfiguration);
}
// only fall back to default sampling configuration after all overlays have been performed
@ -432,11 +444,13 @@ public class ConfigurationBuilder {
}
}
static void overlayProfilerEnvVars(Configuration config) {
static void overlayProfilerEnvVars(
Configuration config, Function<String, String> envVarsFunction) {
String enabledString = Boolean.toString(config.preview.profiler.enabled);
String overlayedValue =
overlayWithEnvVar(APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLED, enabledString);
overlayWithEnvVar(
APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLED, enabledString, envVarsFunction);
if (overlayedValue != null) {
config.preview.profiler.enabled = Boolean.parseBoolean(overlayedValue);
@ -452,7 +466,8 @@ public class ConfigurationBuilder {
Boolean.parseBoolean(
overlayWithEnvVar(
APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLEDIAGNOSTICS,
Boolean.toString(config.preview.profiler.enableDiagnostics)));
Boolean.toString(config.preview.profiler.enableDiagnostics),
envVarsFunction));
}
private static boolean isOpenJ9Jvm() {
@ -460,8 +475,9 @@ public class ConfigurationBuilder {
return jvmName != null && jvmName.contains("OpenJ9");
}
private static void overlayAadEnvVars(Configuration config) {
String aadAuthString = getEnvVar(APPLICATIONINSIGHTS_AUTHENTICATION_STRING);
private static void overlayAadEnvVars(
Configuration config, Function<String, String> envVarsFunction) {
String aadAuthString = getEnvVar(APPLICATIONINSIGHTS_AUTHENTICATION_STRING, envVarsFunction);
if (aadAuthString != null) {
Map<String, String> keyValueMap;
try {
@ -488,8 +504,10 @@ public class ConfigurationBuilder {
}
}
private static void loadLogCaptureEnvVar(Configuration config) {
String loggingEnabled = getEnvVar(APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_ENABLED);
private static void loadLogCaptureEnvVar(
Configuration config, Function<String, String> envVarsFunction) {
String loggingEnabled =
getEnvVar(APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_ENABLED, envVarsFunction);
if (loggingEnabled != null) {
configurationLogger.debug(
"applying environment variable: {}={}",
@ -498,7 +516,8 @@ public class ConfigurationBuilder {
config.instrumentation.logging.enabled = Boolean.parseBoolean(loggingEnabled);
}
if (config.instrumentation.logging.enabled) {
String loggingLevel = getEnvVar(APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL);
String loggingLevel =
getEnvVar(APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL, envVarsFunction);
if (loggingLevel != null) {
configurationLogger.debug(
"applying environment variable: {}={}",
@ -510,8 +529,9 @@ public class ConfigurationBuilder {
}
// TODO deprecate this
private static void loadJmxMetricsEnvVar(Configuration config) throws IOException {
String jmxMetricsEnvVarJson = getEnvVar(APPLICATIONINSIGHTS_JMX_METRICS);
private static void loadJmxMetricsEnvVar(
Configuration config, Function<String, String> envVarsFunction) throws IOException {
String jmxMetricsEnvVarJson = getEnvVar(APPLICATIONINSIGHTS_JMX_METRICS, envVarsFunction);
// JmxMetrics env variable has higher precedence over jmxMetrics config from
// applicationinsights.json
@ -554,61 +574,79 @@ public class ConfigurationBuilder {
return false;
}
private static void overlayInstrumentationEnabledEnvVars(Configuration config) {
private static void overlayInstrumentationEnabledEnvVars(
Configuration config, Function<String, String> envVarsFunction) {
config.instrumentation.azureSdk.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_AZURE_SDK_ENABLED",
config.instrumentation.azureSdk.enabled);
config.instrumentation.azureSdk.enabled,
envVarsFunction);
config.instrumentation.cassandra.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_CASSANDRA_ENABLED",
config.instrumentation.cassandra.enabled);
config.instrumentation.cassandra.enabled,
envVarsFunction);
config.instrumentation.jdbc.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_JDBC_ENABLED",
config.instrumentation.jdbc.enabled);
config.instrumentation.jdbc.enabled,
envVarsFunction);
config.instrumentation.jms.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_JMS_ENABLED", config.instrumentation.jms.enabled);
"APPLICATIONINSIGHTS_INSTRUMENTATION_JMS_ENABLED",
config.instrumentation.jms.enabled,
envVarsFunction);
config.instrumentation.kafka.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_KAFKA_ENABLED",
config.instrumentation.kafka.enabled);
config.instrumentation.kafka.enabled,
envVarsFunction);
config.instrumentation.micrometer.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_MICROMETER_ENABLED",
config.instrumentation.micrometer.enabled);
config.instrumentation.micrometer.enabled,
envVarsFunction);
config.instrumentation.mongo.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_MONGO_ENABLED",
config.instrumentation.mongo.enabled);
config.instrumentation.mongo.enabled,
envVarsFunction);
config.instrumentation.rabbitmq.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_RABBITMQ_ENABLED",
config.instrumentation.rabbitmq.enabled);
config.instrumentation.rabbitmq.enabled,
envVarsFunction);
config.instrumentation.redis.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_REDIS_ENABLED",
config.instrumentation.redis.enabled);
config.instrumentation.redis.enabled,
envVarsFunction);
config.instrumentation.springScheduling.enabled =
overlayWithEnvVar(
"APPLICATIONINSIGHTS_INSTRUMENTATION_SPRING_SCHEDULING_ENABLED",
config.instrumentation.springScheduling.enabled);
config.instrumentation.springScheduling.enabled,
envVarsFunction);
}
private static Configuration loadConfigurationFile(Path agentJarPath) {
String configurationContent = getEnvVar(APPLICATIONINSIGHTS_CONFIGURATION_CONTENT);
private static Configuration loadConfigurationFile(
Path agentJarPath,
Function<String, String> envVarsFunction,
Function<String, String> systemPropsFunction) {
String configurationContent =
getEnvVar(APPLICATIONINSIGHTS_CONFIGURATION_CONTENT, envVarsFunction);
if (configurationContent != null) {
return getConfigurationFromEnvVar(configurationContent);
return getConfigurationFromEnvVar(configurationContent, envVarsFunction);
}
Configuration configFromProperty = extractConfigFromProperty(agentJarPath);
Configuration configFromProperty =
extractConfigFromProperty(agentJarPath, envVarsFunction, systemPropsFunction);
if (configFromProperty != null) {
return configFromProperty;
}
String runtimeAttachedConfigurationContent =
getSystemProperty(APPLICATIONINSIGHTS_RUNTIME_ATTACHED_CONFIGURATION_CONTENT);
getSystemProperty(
APPLICATIONINSIGHTS_RUNTIME_ATTACHED_CONFIGURATION_CONTENT, systemPropsFunction);
if (runtimeAttachedConfigurationContent != null) {
return getConfiguration(runtimeAttachedConfigurationContent, JsonOrigin.RUNTIME_ATTACHED);
}
@ -626,7 +664,7 @@ public class ConfigurationBuilder {
return configFromJsonNextToAgent;
}
if (getEnvVar("APPLICATIONINSIGHTS_PREVIEW_BSP_SCHEDULE_DELAY") != null) {
if (getEnvVar("APPLICATIONINSIGHTS_PREVIEW_BSP_SCHEDULE_DELAY", System::getenv) != null) {
// Note: OTEL_BSP_SCHEDULE_DELAY and OTEL_BLRP_SCHEDULE_DELAY could be used,
// but should not be needed now that the default delay has been properly tuned
configurationLogger.warn(
@ -640,8 +678,11 @@ public class ConfigurationBuilder {
}
@Nullable
private static Configuration extractConfigFromProperty(Path agentJarPath) {
String configPathStr = getConfigPath();
private static Configuration extractConfigFromProperty(
Path agentJarPath,
Function<String, String> envVarsFunction,
Function<String, String> systemPropsFunction) {
String configPathStr = getConfigPath(envVarsFunction, systemPropsFunction);
if (configPathStr != null) {
Path configPath = agentJarPath.resolveSibling(configPathStr);
if (Files.exists(configPath)) {
@ -675,7 +716,12 @@ public class ConfigurationBuilder {
}
// visible for testing
static void overlayFromEnv(Configuration config, Path baseDir) throws IOException {
static void overlayFromEnv(
Configuration config,
Path baseDir,
Function<String, String> envVarsFunction,
Function<String, String> systemPropertiesFunction)
throws IOException {
// load connection string from a file if connection string is in the format of
// "${file:mounted_connection_string_file.txt}"
Map<String, StringLookup> stringLookupMap =
@ -695,98 +741,135 @@ public class ConfigurationBuilder {
+ "\n{ \"connectionString\": \"${file:connection-string-file.txt}\" }\n",
"Learn more about configuration options here: " + CONFIGURATION_OPTIONS_LINK);
}
config.connectionString = overlayConnectionStringFromEnv(replacedConnectionString);
config.connectionString =
overlayConnectionStringFromEnv(
replacedConnectionString, envVarsFunction, systemPropertiesFunction);
if (isTrimEmpty(config.role.name)) {
// only use WEBSITE_SITE_NAME as a fallback
config.role.name = getWebsiteSiteNameEnvVar();
config.role.name = getWebsiteSiteNameEnvVar(envVarsFunction);
}
config.role.name =
overlayWithSysPropEnvVar(
APPLICATIONINSIGHTS_ROLE_NAME_SYS, APPLICATIONINSIGHTS_ROLE_NAME_ENV, config.role.name);
APPLICATIONINSIGHTS_ROLE_NAME_SYS,
APPLICATIONINSIGHTS_ROLE_NAME_ENV,
config.role.name,
envVarsFunction,
systemPropertiesFunction);
if (isTrimEmpty(config.role.instance)) {
// only use WEBSITE_INSTANCE_ID as a fallback
config.role.instance = getEnvVar(WEBSITE_INSTANCE_ID);
config.role.instance = getEnvVar(WEBSITE_INSTANCE_ID, envVarsFunction);
}
config.role.instance =
overlayWithSysPropEnvVar(
APPLICATIONINSIGHTS_ROLE_INSTANCE_SYS,
APPLICATIONINSIGHTS_ROLE_INSTANCE_ENV,
config.role.instance);
config.role.instance,
envVarsFunction,
systemPropertiesFunction);
config.sampling.percentage =
overlayWithEnvVar(APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE, config.sampling.percentage);
overlayWithEnvVar(
APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE, config.sampling.percentage, envVarsFunction);
config.sampling.requestsPerSecond =
overlayWithEnvVar(
APPLICATIONINSIGHTS_SAMPLING_REQUESTS_PER_SECOND, config.sampling.requestsPerSecond);
APPLICATIONINSIGHTS_SAMPLING_REQUESTS_PER_SECOND,
config.sampling.requestsPerSecond,
envVarsFunction);
config.proxy = overlayProxyFromEnv(config.proxy);
config.proxy = overlayProxyFromEnv(config.proxy, envVarsFunction);
config.selfDiagnostics.level =
overlayWithEnvVar(APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_LEVEL, config.selfDiagnostics.level);
overlayWithEnvVar(
APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_LEVEL,
config.selfDiagnostics.level,
envVarsFunction);
config.selfDiagnostics.file.path =
overlayWithEnvVar(
APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_FILE_PATH, config.selfDiagnostics.file.path);
APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_FILE_PATH,
config.selfDiagnostics.file.path,
envVarsFunction);
String deprecatedMetricIntervalSeconds =
getEnvVar(APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS);
String metricIntervalSeconds = getEnvVar(APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS);
getEnvVar(APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS, envVarsFunction);
String metricIntervalSeconds =
getEnvVar(APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS, envVarsFunction);
if (metricIntervalSeconds != null) {
config.metricIntervalSeconds =
overlayWithEnvVar(
APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS, config.metricIntervalSeconds);
APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS,
config.metricIntervalSeconds,
envVarsFunction);
} else if (deprecatedMetricIntervalSeconds != null) {
configurationLogger.warn(
"\"APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS\" has been renamed to \"APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS\""
+ " in 3.4.9 (GA)");
config.metricIntervalSeconds =
overlayWithEnvVar(
APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS, config.metricIntervalSeconds);
APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS,
config.metricIntervalSeconds,
envVarsFunction);
}
config.preview.instrumentation.springIntegration.enabled =
overlayWithEnvVar(
APPLICATIONINSIGHTS_PREVIEW_INSTRUMENTATION_SPRING_INTEGRATION_ENABLED,
config.preview.instrumentation.springIntegration.enabled);
config.preview.instrumentation.springIntegration.enabled,
envVarsFunction);
config.preview.liveMetrics.enabled =
overlayWithEnvVar(
APPLICATIONINSIGHTS_PREVIEW_LIVE_METRICS_ENABLED, config.preview.liveMetrics.enabled);
APPLICATIONINSIGHTS_PREVIEW_LIVE_METRICS_ENABLED,
config.preview.liveMetrics.enabled,
envVarsFunction);
config.preview.statsbeat.disabled =
overlayWithEnvVar(
APPLICATIONINSIGHTS_STATSBEAT_DISABLED, config.preview.statsbeat.disabled);
APPLICATIONINSIGHTS_STATSBEAT_DISABLED,
config.preview.statsbeat.disabled,
envVarsFunction);
loadLogCaptureEnvVar(config);
loadJmxMetricsEnvVar(config);
loadLogCaptureEnvVar(config, envVarsFunction);
loadJmxMetricsEnvVar(config, envVarsFunction);
addDefaultJmxMetricsIfNotPresent(config);
overlayProfilerEnvVars(config);
overlayAadEnvVars(config);
overlayInstrumentationEnabledEnvVars(config);
overlayProfilerEnvVars(config, envVarsFunction);
overlayAadEnvVars(config, envVarsFunction);
overlayInstrumentationEnabledEnvVars(config, envVarsFunction);
}
public static void overlayFromEnv(RpConfiguration config) {
config.connectionString = overlayConnectionStringFromEnv(config.connectionString);
public static void overlayFromEnv(
RpConfiguration config,
Function<String, String> envVarsFunction,
Function<String, String> systemPropertiesFunction) {
config.connectionString =
overlayConnectionStringFromEnv(
config.connectionString, envVarsFunction, systemPropertiesFunction);
config.sampling.percentage =
overlayWithEnvVar(APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE, config.sampling.percentage);
overlayWithEnvVar(
APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE, config.sampling.percentage, envVarsFunction);
}
@Nullable
private static String overlayConnectionStringFromEnv(String connectionString) {
private static String overlayConnectionStringFromEnv(
String connectionString,
Function<String, String> envVarsFunction,
Function<String, String> systemPropertiesFunction) {
String value =
overlayWithSysPropEnvVar(
APPLICATIONINSIGHTS_CONNECTION_STRING_SYS,
APPLICATIONINSIGHTS_CONNECTION_STRING_ENV,
connectionString);
connectionString,
envVarsFunction,
systemPropertiesFunction);
if (value != null) {
return value;
}
// this is for backwards compatibility only
String instrumentationKey = getEnvVar(APPINSIGHTS_INSTRUMENTATIONKEY);
String instrumentationKey = getEnvVar(APPINSIGHTS_INSTRUMENTATIONKEY, envVarsFunction);
if (instrumentationKey != null) {
configurationLogger.warn(
"APPINSIGHTS_INSTRUMENTATIONKEY is only supported for backwards compatibility,"
@ -797,9 +880,9 @@ public class ConfigurationBuilder {
return null;
}
private static Configuration.Proxy overlayProxyFromEnv(Configuration.Proxy proxy) {
String proxyEnvVar = getEnvVar(APPLICATIONINSIGHTS_PROXY);
private static Configuration.Proxy overlayProxyFromEnv(
Configuration.Proxy proxy, Function<String, String> envVarsFunction) {
String proxyEnvVar = getEnvVar(APPLICATIONINSIGHTS_PROXY, envVarsFunction);
if (proxyEnvVar == null) {
if (proxy.password != null) {
configurationLogger.warn(
@ -862,19 +945,20 @@ public class ConfigurationBuilder {
}
}
private static String getConfigPath() {
String configPath = getEnvVar(APPLICATIONINSIGHTS_CONFIGURATION_FILE);
private static String getConfigPath(
Function<String, String> envVarsFunction, Function<String, String> systemPropertiesFunction) {
String configPath = getEnvVar(APPLICATIONINSIGHTS_CONFIGURATION_FILE, envVarsFunction);
if (configPath != null) {
return configPath;
}
// intentionally not checking system properties for other system properties
// with the intention to keep configuration paths minimal to help with supportability
return getSystemProperty("applicationinsights.configuration.file");
return getSystemProperty("applicationinsights.configuration.file", systemPropertiesFunction);
}
private static String getWebsiteSiteNameEnvVar() {
String websiteSiteName = getEnvVar(WEBSITE_SITE_NAME);
if (websiteSiteName != null && inAzureFunctionsWorker()) {
private static String getWebsiteSiteNameEnvVar(Function<String, String> envVarsFunction) {
String websiteSiteName = getEnvVar(WEBSITE_SITE_NAME, envVarsFunction);
if (websiteSiteName != null && inAzureFunctionsWorker(envVarsFunction)) {
// special case for Azure Functions
return websiteSiteName.toLowerCase(Locale.ROOT);
}
@ -883,27 +967,32 @@ public class ConfigurationBuilder {
public static boolean inAzureFunctionsConsumptionWorker() {
// for now its the same, but in future should be different check
return inAzureFunctionsWorker();
return inAzureFunctionsWorker(System::getenv);
}
public static boolean inAzureFunctionsWorker() {
public static boolean inAzureFunctionsWorker(Function<String, String> envVarsFunction) {
// supporting both Azure Functions RP Integration, as well as bring your own agent deployments
// in Azure Functions
return "java".equals(System.getenv("FUNCTIONS_WORKER_RUNTIME"));
return "java".equals(envVarsFunction.apply("FUNCTIONS_WORKER_RUNTIME"));
}
public static String overlayWithSysPropEnvVar(
String systemPropertyName, String envVarName, String defaultValue) {
String value = getSystemProperty(systemPropertyName);
String systemPropertyName,
String envVarName,
String defaultValue,
Function<String, String> envVarsFunction,
Function<String, String> systemPropertiesFunction) {
String value = getSystemProperty(systemPropertyName, systemPropertiesFunction);
if (value != null) {
configurationLogger.debug("using system property: {}", systemPropertyName);
return value;
}
return overlayWithEnvVar(envVarName, defaultValue);
return overlayWithEnvVar(envVarName, defaultValue, envVarsFunction);
}
public static String overlayWithEnvVar(String name, String defaultValue) {
String value = getEnvVar(name);
public static String overlayWithEnvVar(
String name, String defaultValue, Function<String, String> envVarsFunction) {
String value = getEnvVar(name, envVarsFunction);
if (value != null) {
return value;
}
@ -911,8 +1000,9 @@ public class ConfigurationBuilder {
}
@Nullable
static Double overlayWithEnvVar(String name, @Nullable Double defaultValue) {
String value = getEnvVar(name);
static Double overlayWithEnvVar(
String name, @Nullable Double defaultValue, Function<String, String> envVarsFunction) {
String value = getEnvVar(name, envVarsFunction);
if (value != null) {
configurationLogger.debug("applying environment variable: {}={}", name, value);
// intentionally allowing NumberFormatException to bubble up as invalid configuration and
@ -922,8 +1012,9 @@ public class ConfigurationBuilder {
return defaultValue;
}
static int overlayWithEnvVar(String name, int defaultValue) {
String value = getEnvVar(name);
static int overlayWithEnvVar(
String name, int defaultValue, Function<String, String> envVarsFunction) {
String value = getEnvVar(name, envVarsFunction);
if (value != null) {
configurationLogger.debug("using environment variable: {}", name);
// intentionally allowing NumberFormatException to bubble up as invalid configuration and
@ -933,8 +1024,9 @@ public class ConfigurationBuilder {
return defaultValue;
}
static boolean overlayWithEnvVar(String name, boolean defaultValue) {
String value = getEnvVar(name);
static boolean overlayWithEnvVar(
String name, boolean defaultValue, Function<String, String> envVarsFunction) {
String value = getEnvVar(name, envVarsFunction);
if (value != null) {
configurationLogger.debug("applying environment variable: {}={}", name, value);
return Boolean.parseBoolean(value);
@ -943,8 +1035,12 @@ public class ConfigurationBuilder {
}
// never returns empty string (empty string is normalized to null)
protected static String getSystemProperty(String name) {
String value = Strings.trimAndEmptyToNull(System.getProperty(name));
protected static String getSystemProperty(
String name, @Nullable Function<String, String> systemPropertiesFunction) {
if (systemPropertiesFunction == null) {
systemPropertiesFunction = System::getProperty;
}
String value = Strings.trimAndEmptyToNull(systemPropertiesFunction.apply(name));
if (value != null) {
configurationLogger.debug("read system property: {}={}", name, value);
}
@ -952,8 +1048,12 @@ public class ConfigurationBuilder {
}
// never returns empty string (empty string is normalized to null)
protected static String getEnvVar(String name) {
String value = Strings.trimAndEmptyToNull(System.getenv(name));
protected static String getEnvVar(
String name, @Nullable Function<String, String> envVarsFunction) {
if (envVarsFunction == null) {
envVarsFunction = System::getenv;
}
String value = Strings.trimAndEmptyToNull(envVarsFunction.apply(name));
if (value != null) {
configurationLogger.debug("read environment variable: {}={}", name, value);
}
@ -998,7 +1098,8 @@ public class ConfigurationBuilder {
}
}
static Configuration getConfigurationFromEnvVar(String json) {
static Configuration getConfigurationFromEnvVar(
String json, Function<String, String> envVarsFunction) {
Configuration configuration = getConfiguration(json, JsonOrigin.ENV_VAR);

Просмотреть файл

@ -27,7 +27,7 @@ public class RpConfigurationBuilder {
public static RpConfiguration create(Path agentJarPath) throws IOException {
Path configPath;
String configPathString =
ConfigurationBuilder.getEnvVar(APPLICATIONINSIGHTS_RP_CONFIGURATION_FILE);
ConfigurationBuilder.getEnvVar(APPLICATIONINSIGHTS_RP_CONFIGURATION_FILE, System::getenv);
if (configPathString != null) {
configPath = new File(configPathString).toPath();

Просмотреть файл

@ -3,6 +3,8 @@
package com.microsoft.applicationinsights.agent.internal.diagnostics;
import java.util.function.Function;
public class AgentExtensionVersionFinder extends CachedDiagnosticsValueFinder {
/**
@ -13,8 +15,8 @@ public class AgentExtensionVersionFinder extends CachedDiagnosticsValueFinder {
"ApplicationInsightsAgent_EXTENSION_VERSION";
@Override
protected String populateValue() {
return System.getenv(AGENT_EXTENSION_VERSION_ENVIRONMENT_VARIABLE);
protected String populateValue(Function<String, String> envVarsFunction) {
return envVarsFunction.apply(AGENT_EXTENSION_VERSION_ENVIRONMENT_VARIABLE);
}
@Override

Просмотреть файл

@ -3,16 +3,18 @@
package com.microsoft.applicationinsights.agent.internal.diagnostics;
import java.util.function.Function;
public abstract class CachedDiagnosticsValueFinder implements DiagnosticsValueFinder {
private volatile String value;
@Override
public String getValue() {
public String getValue(Function<String, String> envVarsFunction) {
if (value == null) {
value = populateValue();
value = populateValue(envVarsFunction);
}
return value;
}
protected abstract String populateValue();
protected abstract String populateValue(Function<String, String> envVarsFunction);
}

Просмотреть файл

@ -3,9 +3,12 @@
package com.microsoft.applicationinsights.agent.internal.diagnostics;
import java.util.function.Function;
import javax.annotation.Nullable;
public interface DiagnosticsValueFinder {
String getName();
String getValue();
String getValue(@Nullable Function<String, String> envVarsFunction);
}

Просмотреть файл

@ -3,6 +3,8 @@
package com.microsoft.applicationinsights.agent.internal.diagnostics;
import java.util.function.Function;
public class InstrumentationKeyFinder implements DiagnosticsValueFinder {
private static final String PREFIX = "InstrumentationKey=";
@ -13,8 +15,8 @@ public class InstrumentationKeyFinder implements DiagnosticsValueFinder {
}
@Override
public String getValue() {
String connStr = System.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING");
public String getValue(Function<String, String> envVarsFunction) {
String connStr = envVarsFunction.apply("APPLICATIONINSIGHTS_CONNECTION_STRING");
if (connStr != null && !connStr.isEmpty()) {
String[] parts = connStr.split(";");
String instrumentationKey = null;
@ -27,6 +29,6 @@ public class InstrumentationKeyFinder implements DiagnosticsValueFinder {
// return the last instrumentation key to match ConnectionString::parseInto
return instrumentationKey;
}
return System.getenv("APPINSIGHTS_INSTRUMENTATIONKEY");
return envVarsFunction.apply("APPINSIGHTS_INSTRUMENTATIONKEY");
}
}

Просмотреть файл

@ -3,6 +3,7 @@
package com.microsoft.applicationinsights.agent.internal.diagnostics;
import java.util.function.Function;
import javax.annotation.Nullable;
public class MachineNameFinder extends CachedDiagnosticsValueFinder {
@ -10,12 +11,12 @@ public class MachineNameFinder extends CachedDiagnosticsValueFinder {
@Override
@Nullable
protected String populateValue() {
String computerName = System.getenv("COMPUTERNAME");
protected String populateValue(Function<String, String> envVarsFunction) {
String computerName = envVarsFunction.apply("COMPUTERNAME");
if (computerName != null) {
return computerName;
}
String hostname = System.getenv("HOSTNAME");
String hostname = envVarsFunction.apply("HOSTNAME");
if (hostname != null) {
return hostname;
}

Просмотреть файл

@ -6,13 +6,14 @@ package com.microsoft.applicationinsights.agent.internal.diagnostics;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Method;
import java.util.function.Function;
import javax.annotation.Nullable;
public class PidFinder extends CachedDiagnosticsValueFinder {
public static final String PROPERTY_NAME = "PID";
@Override
protected String populateValue() {
protected String populateValue(Function<String, String> envVarsFunction) {
String java9pid = getPidUsingProcessHandle();
if (java9pid != null) {
return java9pid;

Просмотреть файл

@ -7,6 +7,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Properties;
import java.util.function.Function;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@ -20,7 +21,7 @@ public class SdkVersionFinder extends CachedDiagnosticsValueFinder {
}
@Override
protected String populateValue() {
protected String populateValue(Function<String, String> envVarsFunction) {
return value;
}

Просмотреть файл

@ -3,6 +3,7 @@
package com.microsoft.applicationinsights.agent.internal.diagnostics;
import java.util.function.Function;
import javax.annotation.Nullable;
public class SiteNameFinder extends CachedDiagnosticsValueFinder {
@ -18,8 +19,8 @@ public class SiteNameFinder extends CachedDiagnosticsValueFinder {
@Override
@Nullable
protected String populateValue() {
String value = System.getenv(SiteNameFinder.WEBSITE_SITE_NAME_ENV_VAR);
protected String populateValue(Function<String, String> envVarsFunction) {
String value = envVarsFunction.apply(SiteNameFinder.WEBSITE_SITE_NAME_ENV_VAR);
return value == null || value.isEmpty() ? null : value;
}
}

Просмотреть файл

@ -3,14 +3,16 @@
package com.microsoft.applicationinsights.agent.internal.diagnostics;
import java.util.function.Function;
public class SubscriptionIdFinder extends CachedDiagnosticsValueFinder {
// visible for testing
static final String WEBSITE_OWNER_NAME_ENV_VAR = "WEBSITE_OWNER_NAME";
@Override
protected String populateValue() {
String envValue = System.getenv(WEBSITE_OWNER_NAME_ENV_VAR);
protected String populateValue(Function<String, String> envVarsFunction) {
String envValue = envVarsFunction.apply(WEBSITE_OWNER_NAME_ENV_VAR);
if (envValue == null || envValue.isEmpty()) {
return "unknown";
}

Просмотреть файл

@ -29,11 +29,11 @@ public class EtwAppender extends AppenderBase<ILoggingEvent> {
ApplicationMetadataFactory metadata = DiagnosticsHelper.getMetadataFactory();
proto = new IpaInfo();
proto.setAppName(metadata.getSiteName().getValue());
proto.setExtensionVersion(metadata.getSdkVersion().getValue());
proto.setSubscriptionId(metadata.getSubscriptionId().getValue());
proto.setInstrumentationKey(metadata.getInstrumentationKey().getValue());
etwProvider = new EtwProvider(metadata.getSdkVersion().getValue());
proto.setAppName(metadata.getSiteName().getValue(System::getenv));
proto.setExtensionVersion(metadata.getSdkVersion().getValue(System::getenv));
proto.setSubscriptionId(metadata.getSubscriptionId().getValue(System::getenv));
proto.setInstrumentationKey(metadata.getInstrumentationKey().getValue(System::getenv));
etwProvider = new EtwProvider(metadata.getSdkVersion().getValue(System::getenv));
}
@Override

Просмотреть файл

@ -56,9 +56,9 @@ public class ApplicationInsightsCsvLayout extends PatternLayout {
+ formatForCsv(message)
+ "\""
+ ","
+ applicationMetadataFactory.getSiteName().getValue()
+ applicationMetadataFactory.getSiteName().getValue(System::getenv)
+ ","
+ applicationMetadataFactory.getInstrumentationKey().getValue()
+ applicationMetadataFactory.getInstrumentationKey().getValue(System::getenv)
+ ","
+ qualifiedSdkVersion
+ ","

Просмотреть файл

@ -51,7 +51,7 @@ public class ApplicationInsightsJsonLayout extends JsonLayout {
add(OPERATION_NAME_PROP_NAME, true, getOperationName(event), jsonMap);
add(DiagnosticsHelper.MDC_MESSAGE_ID, true, getMessageId(event), jsonMap);
for (DiagnosticsValueFinder finder : valueFinders) {
String value = finder.getValue();
String value = finder.getValue(null);
add(
finder.getName(),
true,

Просмотреть файл

@ -267,7 +267,7 @@ public class StatusFile {
static Map<String, Object> getJsonMap() {
Map<String, Object> map = new LinkedHashMap<>(CONSTANT_VALUES);
for (DiagnosticsValueFinder finder : VALUE_FINDERS) {
String value = finder.getValue();
String value = finder.getValue(System::getenv);
if (value != null && !value.isEmpty()) {
map.put(capitalize(finder.getName()), value);
}

Просмотреть файл

@ -27,7 +27,7 @@ public class AzureMonitorSpanProcessor implements SpanProcessor {
// Azure function host is emitting request, java agent doesn't.
// parentSpan is not an instanceof ReadableSpan here, thus need to update operationName before
// checking for ReadableSpan
if (ConfigurationBuilder.inAzureFunctionsWorker()) {
if (ConfigurationBuilder.inAzureFunctionsWorker(System::getenv)) {
AzureFunctionsCustomDimensions customDimensions =
AzureFunctionsCustomDimensions.fromContext(parentContext);
if (customDimensions != null && customDimensions.operationName != null) {

Просмотреть файл

@ -88,7 +88,9 @@ public class FirstEntryPoint implements LoggingCustomizer {
DiagnosticsHelper.initRpIntegration(agentPath);
// configuration is only read this early in order to extract logging configuration
rpConfiguration = RpConfigurationBuilder.create(agentPath);
configuration = ConfigurationBuilder.create(agentPath, rpConfiguration);
configuration =
ConfigurationBuilder.create(
agentPath, rpConfiguration, System::getenv, System::getProperty);
String codelessSdkNamePrefix = getCodelessSdkNamePrefix();
if (codelessSdkNamePrefix != null) {
@ -168,7 +170,7 @@ public class FirstEntryPoint implements LoggingCustomizer {
startupLogger.info(
"Application Insights Java Agent {} started successfully (PID {}, JVM running for {} s)",
agentVersion,
new PidFinder().getValue(),
new PidFinder().getValue(System::getenv),
findJvmUptimeInSeconds());
String javaVersion = System.getProperty("java.version");
@ -203,7 +205,7 @@ public class FirstEntryPoint implements LoggingCustomizer {
"Application Insights Java Agent "
+ agentVersion
+ " startup failed (PID "
+ new PidFinder().getValue()
+ new PidFinder().getValue(System::getenv)
+ ")";
if (friendlyException != null) {
@ -256,7 +258,8 @@ public class FirstEntryPoint implements LoggingCustomizer {
selfDiagnostics.file.path =
ConfigurationBuilder.overlayWithEnvVar(
ConfigurationBuilder.APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_FILE_PATH,
selfDiagnostics.file.path);
selfDiagnostics.file.path,
System::getenv);
startupLogger = configureLogging(selfDiagnostics, agentPath);
logStartupFailure(isFriendlyException, message, t);

Просмотреть файл

@ -41,6 +41,6 @@ class JvmCompiler {
}
private static String pid() {
return new PidFinder().getValue();
return new PidFinder().getValue(System::getenv);
}
}

Просмотреть файл

@ -16,6 +16,7 @@ import java.nio.file.attribute.FileTime;
import java.util.Objects;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -25,15 +26,24 @@ public class RpConfigurationPolling implements Runnable {
private volatile RpConfiguration rpConfiguration;
private final RuntimeConfigurator runtimeConfigurator;
private final Function<String, String> envVarsFunction;
private final Function<String, String> systemPropertiesFunction;
public static void startPolling(
RpConfiguration rpConfiguration, RuntimeConfigurator runtimeConfigurator) {
RpConfiguration rpConfiguration,
RuntimeConfigurator runtimeConfigurator,
Function<String, String> envVarsFunction,
Function<String, String> systemPropertiesFunction) {
ScheduledExecutorService executor =
Executors.newSingleThreadScheduledExecutor(
ThreadPoolUtils.createDaemonThreadFactory(RpConfigurationPolling.class));
executor.scheduleWithFixedDelay(
new RpConfigurationPolling(rpConfiguration, runtimeConfigurator), 60, 60, SECONDS);
new RpConfigurationPolling(
rpConfiguration, runtimeConfigurator, envVarsFunction, systemPropertiesFunction),
60,
60,
SECONDS);
// the condition below will always be false, but by referencing the executor it ensures the
// executor can't become unreachable in the middle of the scheduleWithFixedDelay() method
// execution above (and prior to the task being registered), which can lead to the executor
@ -45,9 +55,15 @@ public class RpConfigurationPolling implements Runnable {
}
// visible for testing
RpConfigurationPolling(RpConfiguration rpConfiguration, RuntimeConfigurator runtimeConfigurator) {
RpConfigurationPolling(
RpConfiguration rpConfiguration,
RuntimeConfigurator runtimeConfigurator,
Function<String, String> envVarsFunction,
Function<String, String> systemPropertiesFunction) {
this.rpConfiguration = rpConfiguration;
this.runtimeConfigurator = runtimeConfigurator;
this.envVarsFunction = envVarsFunction;
this.systemPropertiesFunction = systemPropertiesFunction;
}
@Override
@ -69,7 +85,8 @@ public class RpConfigurationPolling implements Runnable {
RpConfiguration newRpConfiguration =
RpConfigurationBuilder.loadJsonConfigFile(rpConfiguration.configPath);
ConfigurationBuilder.overlayFromEnv(newRpConfiguration);
ConfigurationBuilder.overlayFromEnv(
newRpConfiguration, envVarsFunction, systemPropertiesFunction);
RuntimeConfiguration config = runtimeConfigurator.getCurrentConfigCopy();

Просмотреть файл

@ -189,7 +189,8 @@ public class SecondEntryPoint
RpConfiguration rpConfiguration = FirstEntryPoint.getRpConfiguration();
if (rpConfiguration != null) {
RpConfigurationPolling.startPolling(rpConfiguration, runtimeConfigurator);
RpConfigurationPolling.startPolling(
rpConfiguration, runtimeConfigurator, System::getenv, System::getProperty);
}
// initialize StatsbeatModule
@ -620,7 +621,7 @@ public class SecondEntryPoint
builder.addLogRecordProcessor(new AzureMonitorLogProcessor());
if (ConfigurationBuilder.inAzureFunctionsWorker()) {
if (ConfigurationBuilder.inAzureFunctionsWorker(System::getenv)) {
builder.addLogRecordProcessor(new AzureFunctionsLogProcessor());
}
@ -647,7 +648,7 @@ public class SecondEntryPoint
LogDataMapper mapper =
new LogDataMapper(
configuration.preview.captureLoggingLevelAsCustomDimension,
ConfigurationBuilder.inAzureFunctionsWorker(),
ConfigurationBuilder.inAzureFunctionsWorker(System::getenv),
telemetryClient::populateDefaults);
List<Configuration.SamplingOverride> logSamplingOverrides =

Просмотреть файл

@ -129,6 +129,6 @@ class StartupDiagnostics {
}
private static String pid() {
return new PidFinder().getValue();
return new PidFinder().getValue(System::getenv);
}
}

Просмотреть файл

@ -148,7 +148,7 @@ public class PerformanceMonitoringService {
diagnosticEngineFactory.create(diagnosticEngineExecutorService);
if (diagnosticEngine != null) {
diagnosticEngine.init(Integer.parseInt(new PidFinder().getValue()));
diagnosticEngine.init(Integer.parseInt(new PidFinder().getValue(System::getenv)));
} else {
diagnosticEngineExecutorService.shutdown();
}

Просмотреть файл

@ -6,7 +6,6 @@ package com.microsoft.applicationinsights.agent.internal.configuration;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariable;
import com.microsoft.applicationinsights.agent.internal.common.FriendlyException;
import java.io.File;
@ -15,6 +14,8 @@ import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -27,10 +28,15 @@ class ConfigurationBuilderTest {
private File connectionStringFile;
@TempDir File temp;
private static final Map<String, String> envVars = new HashMap<>();
private static final Map<String, String> systemProperties = new HashMap<>();
// TODO (heya) clean up the rest of resource files. We can create them at test runtime. Be
// consistent with connectionStringFile.
@BeforeEach
public void setup() throws IOException {
envVars.clear();
systemProperties.clear();
connectionStringFile = File.createTempFile("test", ".txt", temp);
Writer writer = Files.newBufferedWriter(connectionStringFile.toPath(), UTF_8);
writer.write(CONNECTION_STRING);
@ -124,7 +130,7 @@ class ConfigurationBuilderTest {
config.connectionString = testConnectionString;
config.sampling.percentage = testSamplingPercentage;
ConfigurationBuilder.overlayFromEnv(config);
ConfigurationBuilder.overlayFromEnv(config, this::envVars, this::systemProperties);
assertThat(config.connectionString).isEqualTo(testConnectionString);
assertThat(config.sampling.percentage).isEqualTo(testSamplingPercentage);
@ -134,28 +140,35 @@ class ConfigurationBuilderTest {
void testRpConfigurationOverlayWithEnvVarAndSysPropPopulated() throws Exception {
String testConnectionString = "test-connection-string";
double testSamplingPercentage = 10.0;
envVars.put("APPLICATIONINSIGHTS_CONNECTION_STRING", testConnectionString);
envVars.put("APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE", String.valueOf(testSamplingPercentage));
RpConfiguration config = new RpConfiguration();
withEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING", testConnectionString)
.and("APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE", String.valueOf(testSamplingPercentage))
.execute(
() -> {
RpConfiguration config = new RpConfiguration();
config.connectionString = String.format("original-%s", testConnectionString);
config.sampling.percentage = testSamplingPercentage + 1.0;
config.connectionString = String.format("original-%s", testConnectionString);
config.sampling.percentage = testSamplingPercentage + 1.0;
ConfigurationBuilder.overlayFromEnv(config, this::envVars, this::systemProperties);
ConfigurationBuilder.overlayFromEnv(config);
assertThat(config.connectionString).isEqualTo(testConnectionString);
assertThat(config.sampling.percentage).isEqualTo(testSamplingPercentage);
}
assertThat(config.connectionString).isEqualTo(testConnectionString);
assertThat(config.sampling.percentage).isEqualTo(testSamplingPercentage);
});
@SuppressWarnings("MethodCanBeStatic")
private String envVars(String key) {
return envVars.get(key);
}
@SuppressWarnings("MethodCanBeStatic")
private String systemProperties(String key) {
return systemProperties.get(key);
}
@Test
void testOverlayWithEnvVarWithGoodFileStringLookupFormat() throws Exception {
Configuration configuration = new Configuration();
configuration.connectionString = "${file:" + connectionStringFile.getAbsolutePath() + "}";
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.connectionString).isEqualTo(CONNECTION_STRING);
}
@ -179,12 +192,16 @@ class ConfigurationBuilderTest {
assertFriendlyExceptionThrown(configuration, filename);
configuration.connectionString = CONNECTION_STRING;
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), System::getenv, System::getProperty);
assertThat(configuration.connectionString).isEqualTo(CONNECTION_STRING);
}
private static void assertFriendlyExceptionThrown(Configuration configuration, String filename) {
assertThatThrownBy(() -> ConfigurationBuilder.overlayFromEnv(configuration, Paths.get(".")))
assertThatThrownBy(
() ->
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), System::getenv, System::getProperty))
.isInstanceOf(FriendlyException.class);
assertThat(configuration.connectionString).isEqualTo(filename);
}
@ -192,52 +209,48 @@ class ConfigurationBuilderTest {
@Test
void testConnectionStringEnvVarHasHigherPrecedenceOverFileLookup() throws Exception {
String testConnectionString = "test-connection-string";
withEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING", testConnectionString)
.execute(
() -> {
Configuration configuration = new Configuration();
envVars.put("APPLICATIONINSIGHTS_CONNECTION_STRING", testConnectionString);
configuration.connectionString =
"${file:" + connectionStringFile.getAbsolutePath() + "}";
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
Configuration configuration = new Configuration();
assertThat(configuration.connectionString).isEqualTo(testConnectionString);
});
configuration.connectionString = "${file:" + connectionStringFile.getAbsolutePath() + "}";
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.connectionString).isEqualTo(testConnectionString);
}
@Test
void testProxyEnvOverlay() throws Exception {
withEnvironmentVariable("APPLICATIONINSIGHTS_PROXY", "https://me:passw@host:1234")
.execute(
() -> {
Configuration configuration = new Configuration();
envVars.put("APPLICATIONINSIGHTS_PROXY", "https://me:passw@host:1234");
Configuration configuration = new Configuration();
configuration.proxy.host = "old";
configuration.proxy.port = 555;
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
configuration.proxy.host = "old";
configuration.proxy.port = 555;
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.proxy.host).isEqualTo("host");
assertThat(configuration.proxy.port).isEqualTo(1234);
assertThat(configuration.proxy.username).isEqualTo("me");
assertThat(configuration.proxy.password).isEqualTo("passw");
});
assertThat(configuration.proxy.host).isEqualTo("host");
assertThat(configuration.proxy.port).isEqualTo(1234);
assertThat(configuration.proxy.username).isEqualTo("me");
assertThat(configuration.proxy.password).isEqualTo("passw");
}
private static void runProfilerEnvOverlay(boolean fileValue, boolean expected) {
private void runProfilerEnvOverlay(boolean fileValue, boolean expected) {
Configuration configuration = new Configuration();
configuration.preview.profiler.enabled = fileValue;
ConfigurationBuilder.overlayProfilerEnvVars(configuration);
ConfigurationBuilder.overlayProfilerEnvVars(configuration, this::envVars);
assertThat(configuration.preview.profiler.enabled).isEqualTo(expected);
}
@Test
void testProfilerEnvOverlay() throws Exception {
// Enabled in file overlayed false is disabled
withEnvironmentVariable("APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLED", "false")
.execute(() -> runProfilerEnvOverlay(true, false));
envVars.put("APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLED", "false");
runProfilerEnvOverlay(true, false);
// Disabled in file overlayed true is enabled
withEnvironmentVariable("APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLED", "true")
.execute(() -> runProfilerEnvOverlay(false, true));
envVars.put("APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLED", "true");
runProfilerEnvOverlay(false, true);
}
}

Просмотреть файл

@ -21,24 +21,27 @@ import io.opentelemetry.api.common.AttributeKey;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.extension.ExtendWith;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import uk.org.webcompere.systemstubs.properties.SystemProperties;
@ExtendWith(SystemStubsExtension.class)
class ConfigurationTest {
@SystemStub EnvironmentVariables envVars = new EnvironmentVariables();
@SystemStub SystemProperties systemProperties = new SystemProperties();
private static final Map<String, String> envVars = new HashMap<>();
private static final Map<String, String> systemProperties = new HashMap<>();
@BeforeEach
void setup() {
envVars.clear();
systemProperties.clear();
}
@Test
void shouldParse() throws IOException {
@ -82,12 +85,13 @@ class ConfigurationTest {
+ "\"display\":\"Code Cache Used from EnvVar\"}]";
String contentJson =
"{\"jmxMetrics\": " + jmxMetricsJson + "," + "\"role\":{" + "\"name\":\"testrole\"" + "}}";
envVars.set("APPLICATIONINSIGHTS_CONFIGURATION_CONTENT", contentJson);
envVars.set(
envVars.put("APPLICATIONINSIGHTS_CONFIGURATION_CONTENT", contentJson);
envVars.put(
"APPLICATIONINSIGHTS_CONNECTION_STRING",
"InstrumentationKey=11111111-1111-1111-1111-111111111111");
Configuration configuration = ConfigurationBuilder.create(Paths.get("."), null);
Configuration configuration =
ConfigurationBuilder.create(Paths.get("."), null, this::envVars, this::systemProperties);
assertThat(configuration.connectionString)
.isEqualTo("InstrumentationKey=11111111-1111-1111-1111-111111111111");
@ -110,9 +114,12 @@ class ConfigurationTest {
String contentJson =
"{\"connectionString\":\"InstrumentationKey=55555555-5555-5555-5555-555555555555\","
+ "\"role\":{\"name\":\"testrole\"}}";
envVars.set("APPLICATIONINSIGHTS_CONFIGURATION_CONTENT", contentJson);
envVars.put("APPLICATIONINSIGHTS_CONFIGURATION_CONTENT", contentJson);
assertThatThrownBy(() -> ConfigurationBuilder.create(Paths.get("."), null))
assertThatThrownBy(
() ->
ConfigurationBuilder.create(
Paths.get("."), null, this::envVars, this::systemProperties))
.isInstanceOf(ConfigurationBuilder.ConfigurationException.class);
} finally {
DiagnosticsHelper.setAppSvcRpIntegratedAuto(false);
@ -240,7 +247,6 @@ class ConfigurationTest {
@Test
void shouldParseAuthenticationConfiguration() throws IOException {
Configuration configuration = loadConfiguration("applicationinsights_aadauth.json");
assertThat(configuration.connectionString)
.isEqualTo("InstrumentationKey=00000000-0000-0000-0000-000000000000");
@ -254,10 +260,12 @@ class ConfigurationTest {
@Test
void shouldUseDefaults() throws IOException {
envVars.set("WEBSITE_SITE_NAME", "Role Name From Website Env");
envVars.set("WEBSITE_INSTANCE_ID", "role instance from website env");
envVars.put("WEBSITE_SITE_NAME", "Role Name From Website Env");
envVars.put("WEBSITE_INSTANCE_ID", "role instance from website env");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.connectionString)
.isEqualTo("InstrumentationKey=00000000-0000-0000-0000-000000000000");
@ -271,25 +279,36 @@ class ConfigurationTest {
@Test
void shouldOverrideConnectionStringWithEnvVar() throws IOException {
envVars.set(
envVars.put(
"APPLICATIONINSIGHTS_CONNECTION_STRING",
"InstrumentationKey=11111111-1111-1111-1111-111111111111");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.connectionString)
.isEqualTo("InstrumentationKey=11111111-1111-1111-1111-111111111111");
}
@SuppressWarnings("MethodCanBeStatic")
private String envVars(String key) {
return envVars.get(key);
}
@SuppressWarnings("MethodCanBeStatic")
private String systemProperties(String key) {
return systemProperties.get(key);
}
@Test
void shouldOverrideConnectionStringWithSysProp() throws IOException {
systemProperties.set(
systemProperties.put(
"applicationinsights.connection.string",
"InstrumentationKey=11111111-1111-1111-1111-111111111111");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.connectionString)
.isEqualTo("InstrumentationKey=11111111-1111-1111-1111-111111111111");
@ -297,15 +316,16 @@ class ConfigurationTest {
@Test
void shouldOverrideConnectionStringWithBothEnvVarAndSysProp() throws IOException {
envVars.set(
envVars.put(
"APPLICATIONINSIGHTS_CONNECTION_STRING",
"InstrumentationKey=11111111-1111-1111-1111-111111111111");
systemProperties.set(
systemProperties.put(
"applicationinsights.connection.string",
"InstrumentationKey=22222222-2222-2222-2222-222222222222");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.connectionString)
.isEqualTo("InstrumentationKey=22222222-2222-2222-2222-222222222222");
@ -313,155 +333,169 @@ class ConfigurationTest {
@Test
void shouldOverrideRoleNameWithEnvVar() throws IOException {
envVars.set("APPLICATIONINSIGHTS_ROLE_NAME", "role name from env");
envVars.put("APPLICATIONINSIGHTS_ROLE_NAME", "role name from env");
envVars.set("WEBSITE_SITE_NAME", "Role Name From Website Env");
envVars.put("WEBSITE_SITE_NAME", "Role Name From Website Env");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.name).isEqualTo("role name from env");
}
@Test
void shouldOverrideRoleNameWithSysProp() throws IOException {
systemProperties.set("applicationinsights.role.name", "role name from sys");
systemProperties.put("applicationinsights.role.name", "role name from sys");
envVars.set("WEBSITE_SITE_NAME", "Role Name From Website Env");
envVars.put("WEBSITE_SITE_NAME", "Role Name From Website Env");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.name).isEqualTo("role name from sys");
}
@Test
void shouldOverrideRoleNameWithBothEnvVarAndSysProp() throws IOException {
envVars.set("APPLICATIONINSIGHTS_ROLE_NAME", "role name from env");
systemProperties.set("applicationinsights.role.name", "role name from sys");
envVars.put("APPLICATIONINSIGHTS_ROLE_NAME", "role name from env");
systemProperties.put("applicationinsights.role.name", "role name from sys");
envVars.set("WEBSITE_SITE_NAME", "Role Name From Website Env");
envVars.put("WEBSITE_SITE_NAME", "Role Name From Website Env");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.name).isEqualTo("role name from sys");
}
@Test
void shouldOverrideRoleNameWithWebsiteEnvVar() throws IOException {
envVars.set("WEBSITE_SITE_NAME", "Role Name From Website Env");
envVars.put("WEBSITE_SITE_NAME", "Role Name From Website Env");
Configuration configuration = loadConfiguration("applicationinsights_NoRole.json");
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.name).isEqualTo("Role Name From Website Env");
}
@Test
void shouldNotOverrideRoleNameWithWebsiteEnvVar() throws IOException {
envVars.set("WEBSITE_SITE_NAME", "Role Name From Website Env");
envVars.put("WEBSITE_SITE_NAME", "Role Name From Website Env");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.name).isEqualTo("Something Good");
}
@Test
void shouldOverrideRoleNameWithLowercaseWebsiteEnvVarOnAzFn() throws IOException {
envVars.set("FUNCTIONS_WORKER_RUNTIME", "java");
envVars.set("WEBSITE_SITE_NAME", "Role Name From Website Env");
void con() throws IOException {
envVars.put("FUNCTIONS_WORKER_RUNTIME", "java");
envVars.put("WEBSITE_SITE_NAME", "Role Name From Website Env");
Configuration configuration = loadConfiguration("applicationinsights_NoRole.json");
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.name).isEqualTo("role name from website env");
}
@Test
void shouldOverrideRoleInstanceWithEnvVar() throws IOException {
envVars.set("APPLICATIONINSIGHTS_ROLE_INSTANCE", "role instance from env");
envVars.put("APPLICATIONINSIGHTS_ROLE_INSTANCE", "role instance from env");
envVars.set("WEBSITE_INSTANCE_ID", "role instance from website env");
envVars.put("WEBSITE_INSTANCE_ID", "role instance from website env");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.instance).isEqualTo("role instance from env");
}
@Test
void shouldOverrideRoleInstanceWithSysProp() throws IOException {
systemProperties.set("applicationinsights.role.instance", "role instance from sys");
systemProperties.put("applicationinsights.role.instance", "role instance from sys");
envVars.set("WEBSITE_INSTANCE_ID", "role instance from website env");
envVars.put("WEBSITE_INSTANCE_ID", "role instance from website env");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.instance).isEqualTo("role instance from sys");
}
@Test
void shouldOverrideRoleInstanceWithBothEnvVarAndSysProp() throws IOException {
envVars.set("APPLICATIONINSIGHTS_ROLE_INSTANCE", "role instance from env");
systemProperties.set("applicationinsights.role.instance", "role instance from sys");
envVars.put("APPLICATIONINSIGHTS_ROLE_INSTANCE", "role instance from env");
systemProperties.put("applicationinsights.role.instance", "role instance from sys");
envVars.set("WEBSITE_INSTANCE_ID", "role instance from website env");
envVars.put("WEBSITE_INSTANCE_ID", "role instance from website env");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.instance).isEqualTo("role instance from sys");
}
@Test
void shouldOverrideRoleInstanceWithWebsiteEnvVar() throws IOException {
envVars.set("WEBSITE_INSTANCE_ID", "role instance from website env");
envVars.put("WEBSITE_INSTANCE_ID", "role instance from website env");
Configuration configuration = loadConfiguration("applicationinsights_NoRole.json");
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.instance).isEqualTo("role instance from website env");
}
@Test
void shouldNotOverrideRoleInstanceWithWebsiteEnvVar() throws IOException {
envVars.set("WEBSITE_INSTANCE_ID", "role instance from website env");
envVars.put("WEBSITE_INSTANCE_ID", "role instance from website env");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.role.instance).isEqualTo("xyz123");
}
@Test
void shouldOverrideSamplingPercentage() throws IOException {
envVars.set("APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE", "0.25");
envVars.put("APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE", "0.25");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.sampling.percentage).isEqualTo(0.25f);
}
@Test
void shouldOverrideLogCaptureThreshold() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL", "TRACE");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_LEVEL", "TRACE");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.logging.level).isEqualTo("TRACE");
}
@Test
void shouldOverrideLoggingEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_LOGGING_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.logging.enabled).isEqualTo(false);
}
@ -471,10 +505,11 @@ class ConfigurationTest {
String jmxMetricsJson =
"[{\"objectName\": \"java.lang:type=ClassLoading\",\"attribute\": \"LoadedClassCount\",\"display\": \"Loaded Class Count from EnvVar\"},"
+ "{\"objectName\": \"java.lang:type=MemoryPool,name=Code Cache\",\"attribute\": \"Usage.used\",\"display\": \"Code Cache Used from EnvVar\"}]";
envVars.set("APPLICATIONINSIGHTS_JMX_METRICS", jmxMetricsJson);
envVars.put("APPLICATIONINSIGHTS_JMX_METRICS", jmxMetricsJson);
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
List<JmxMetric> jmxMetrics = parseJmxMetricsJson(jmxMetricsJson);
assertThat(jmxMetrics.size()).isEqualTo(2);
@ -488,160 +523,176 @@ class ConfigurationTest {
@Test
void shouldOverrideSelfDiagnosticsLevel() throws IOException {
envVars.set("APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_LEVEL", "DEBUG");
envVars.put("APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_LEVEL", "DEBUG");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.selfDiagnostics.level).isEqualTo("DEBUG");
}
@Test
void shouldOverrideSelfDiagnosticsFilePath() throws IOException {
envVars.set("APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_FILE_PATH", "/tmp/ai.log");
envVars.put("APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_FILE_PATH", "/tmp/ai.log");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.selfDiagnostics.file.path).isEqualTo("/tmp/ai.log");
}
@Test
void shouldOverridePreviewSpringIntegrationInstrumentation() throws IOException {
envVars.set("APPLICATIONINSIGHTS_PREVIEW_INSTRUMENTATION_SPRING_INTEGRATION_ENABLED", "true");
envVars.put("APPLICATIONINSIGHTS_PREVIEW_INSTRUMENTATION_SPRING_INTEGRATION_ENABLED", "true");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.preview.instrumentation.springIntegration.enabled).isTrue();
}
@Test
void shouldOverridePreviewLiveMetricsEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_PREVIEW_LIVE_METRICS_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_PREVIEW_LIVE_METRICS_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.preview.liveMetrics.enabled).isFalse();
}
@Test
void shouldOverrideInstrumentationAzureSdkEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_AZURE_SDK_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_AZURE_SDK_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.azureSdk.enabled).isFalse();
}
@Test
void shouldOverrideInstrumentationCassandraEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_CASSANDRA_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_CASSANDRA_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.cassandra.enabled).isFalse();
}
@Test
void shouldOverrideInstrumentationJdbcEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_JDBC_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_JDBC_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.jdbc.enabled).isFalse();
}
@Test
void shouldOverrideInstrumentationJmsEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_JMS_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_JMS_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.jms.enabled).isFalse();
}
@Test
void shouldOverrideInstrumentationKafkaEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_KAFKA_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_KAFKA_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.kafka.enabled).isFalse();
}
@Test
void shouldOverrideInstrumentationMicrometerEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_MICROMETER_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_MICROMETER_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.micrometer.enabled).isFalse();
}
@Test
void shouldOverrideInstrumentationMongoEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_MONGO_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_MONGO_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.mongo.enabled).isFalse();
}
@Test
void shouldOverrideInstrumentationRabbitmqEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_RABBITMQ_ENABLED", "true");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_RABBITMQ_ENABLED", "true");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.rabbitmq.enabled).isTrue();
}
@Test
void shouldOverrideInstrumentationRedisEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_REDIS_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_REDIS_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.redis.enabled).isFalse();
}
@Test
void shouldOverrideInstrumentationSpringSchedulingEnabled() throws IOException {
envVars.set("APPLICATIONINSIGHTS_INSTRUMENTATION_SPRING_SCHEDULING_ENABLED", "false");
envVars.put("APPLICATIONINSIGHTS_INSTRUMENTATION_SPRING_SCHEDULING_ENABLED", "false");
Configuration configuration = loadConfiguration();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.instrumentation.springScheduling.enabled).isFalse();
}
@Test
void shouldOverrideAadAuthenticationConfig() throws IOException {
envVars.set("APPLICATIONINSIGHTS_AUTHENTICATION_STRING", "Authorization=AAD;ClientId=12345678");
envVars.put("APPLICATIONINSIGHTS_AUTHENTICATION_STRING", "Authorization=AAD;ClientId=12345678");
Configuration configuration = loadConfiguration("applicationinsights_aadauthenv.json");
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.authentication.enabled).isTrue();
assertThat(configuration.authentication.type).isEqualTo(Configuration.AuthenticationType.UAMI);
assertThat(configuration.authentication.clientId).isEqualTo("12345678");
assertThat(configuration.authentication.clientSecret).isNull();
envVars.set("APPLICATIONINSIGHTS_AUTHENTICATION_STRING", "Authorization=AAD;ClientId=");
envVars.put("APPLICATIONINSIGHTS_AUTHENTICATION_STRING", "Authorization=AAD;ClientId=");
Configuration configuration2 = loadConfiguration("applicationinsights_aadauthenv.json");
ConfigurationBuilder.overlayFromEnv(configuration2, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration2, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration2.authentication.enabled).isTrue();
assertThat(configuration2.authentication.type).isEqualTo(Configuration.AuthenticationType.SAMI);
@ -651,21 +702,23 @@ class ConfigurationTest {
@Test
void shouldOverrideStatsbeatDisabledConfig() throws IOException {
envVars.set("APPLICATIONINSIGHTS_STATSBEAT_DISABLED", "true");
envVars.put("APPLICATIONINSIGHTS_STATSBEAT_DISABLED", "true");
Configuration configuration =
loadConfiguration("applicationinsights_statsbeatdisabledenv.json");
assertThat(configuration.preview.statsbeat.disabled).isFalse();
ConfigurationBuilder.overlayFromEnv(configuration, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration.preview.statsbeat.disabled).isTrue();
envVars.set("APPLICATIONINSIGHTS_STATSBEAT_DISABLED", "false");
envVars.put("APPLICATIONINSIGHTS_STATSBEAT_DISABLED", "false");
Configuration configuration2 =
loadConfiguration("applicationinsights_statsbeatdisabledenv.json");
assertThat(configuration2.preview.statsbeat.disabled).isFalse();
ConfigurationBuilder.overlayFromEnv(configuration2, Paths.get("."));
ConfigurationBuilder.overlayFromEnv(
configuration2, Paths.get("."), this::envVars, this::systemProperties);
assertThat(configuration2.preview.statsbeat.disabled).isFalse();
}

Просмотреть файл

@ -5,25 +5,23 @@ package com.microsoft.applicationinsights.agent.internal.diagnostics;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
@ExtendWith(SystemStubsExtension.class)
class SubscriptionIdFinderTest {
@SystemStub EnvironmentVariables envVars = new EnvironmentVariables();
@Nullable private SubscriptionIdFinder subIdFinder;
private static final Map<String, String> envVars = new HashMap<>();
@BeforeEach
void setup() {
subIdFinder = new SubscriptionIdFinder();
envVars.clear();
}
@AfterEach
@ -33,19 +31,24 @@ class SubscriptionIdFinderTest {
@Test
void happyPathWithValidSubscriptionIdInsideWebsiteOwnerNameVar() {
envVars.set(SubscriptionIdFinder.WEBSITE_OWNER_NAME_ENV_VAR, "sub-id-123+NOT_SUB_ID");
String value = subIdFinder.getValue();
envVars.put(SubscriptionIdFinder.WEBSITE_OWNER_NAME_ENV_VAR, "sub-id-123+NOT_SUB_ID");
String value = subIdFinder.getValue(this::envVarsFunction);
assertThat(value).isEqualTo("sub-id-123");
}
@Test
void useUnknownWhenEnvVarIsUnset() {
assertThat(subIdFinder.getValue()).isEqualTo("unknown");
assertThat(subIdFinder.getValue(this::envVarsFunction)).isEqualTo("unknown");
}
@Test
void useUnknownIfEnvVarHasUnexpectedFormat() {
envVars.set(SubscriptionIdFinder.WEBSITE_OWNER_NAME_ENV_VAR, "NOT_VALID");
assertThat(subIdFinder.getValue()).isEqualTo("unknown");
envVars.put(SubscriptionIdFinder.WEBSITE_OWNER_NAME_ENV_VAR, "NOT_VALID");
assertThat(subIdFinder.getValue(this::envVarsFunction)).isEqualTo("unknown");
}
@SuppressWarnings("MethodCanBeStatic")
private String envVarsFunction(String key) {
return envVars.get(key);
}
}

Просмотреть файл

@ -74,13 +74,13 @@ class ApplicationInsightsJsonLayoutTests {
DiagnosticsValueFinder mockFinder = mock(DiagnosticsValueFinder.class);
when(mockFinder.getName()).thenReturn(key);
when(mockFinder.getValue()).thenReturn(value);
when(mockFinder.getValue(null)).thenReturn(value);
ourLayout.valueFinders.add(mockFinder);
Map<String, Object> jsonMap = ourLayout.toJsonMap(logEvent);
Map<String, Object> propertyMap = (Map<String, Object>) jsonMap.get(CUSTOM_FIELDS_PROP_NAME);
verify(mockFinder, atLeastOnce()).getName();
verify(mockFinder, atLeastOnce()).getValue();
verify(mockFinder, atLeastOnce()).getValue(null);
assertThat(propertyMap).containsEntry(key, value);
assertThat(propertyMap).containsEntry("language", "java");
}
@ -92,12 +92,12 @@ class ApplicationInsightsJsonLayoutTests {
DiagnosticsValueFinder nullValueFinder = mock(DiagnosticsValueFinder.class);
when(nullValueFinder.getName()).thenReturn(oneKey);
when(nullValueFinder.getValue()).thenReturn(null);
when(nullValueFinder.getValue(null)).thenReturn(null);
ourLayout.valueFinders.add(nullValueFinder);
DiagnosticsValueFinder emptyValueFinder = mock(DiagnosticsValueFinder.class);
when(emptyValueFinder.getName()).thenReturn(twoKey);
when(emptyValueFinder.getValue()).thenReturn("");
when(emptyValueFinder.getValue(null)).thenReturn("");
ourLayout.valueFinders.add(emptyValueFinder);
Map<String, Object> jsonMap = ourLayout.toJsonMap(logEvent);
@ -105,9 +105,9 @@ class ApplicationInsightsJsonLayoutTests {
Map<String, Object> propMap = (Map<String, Object>) jsonMap.get(CUSTOM_FIELDS_PROP_NAME);
verify(nullValueFinder, atLeastOnce()).getName();
verify(nullValueFinder, atLeastOnce()).getValue();
verify(nullValueFinder, atLeastOnce()).getValue(null);
verify(emptyValueFinder, atLeastOnce()).getName();
verify(emptyValueFinder, atLeastOnce()).getValue();
verify(emptyValueFinder, atLeastOnce()).getValue(null);
assertThat(propMap).containsEntry(twoKey, UNKNOWN_VALUE);
assertThat(propMap).containsEntry(oneKey, UNKNOWN_VALUE);
}

Просмотреть файл

@ -14,6 +14,7 @@ import com.microsoft.applicationinsights.agent.internal.diagnostics.DiagnosticsT
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
@ -21,29 +22,25 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
@Disabled("failing on CI when deleted the @TempDir")
@ExtendWith(SystemStubsExtension.class)
class StatusFileTests {
@TempDir File tempFolder;
@SystemStub EnvironmentVariables envVars = new EnvironmentVariables();
private static final String TEST_IKEY = "fake-ikey-123";
private static final String FAKE_VERSION = "0.0.1-test";
private static final Map<String, String> envVars = new HashMap<>();
@BeforeEach
void setup() {
envVars.clear();
// TODO these tests currently only pass on windows
assumeTrue(DiagnosticsHelper.isOsWindows());
envVars.set("APPINSIGHTS_INSTRUMENTATIONKEY", TEST_IKEY);
envVars.set(
envVars.put("APPINSIGHTS_INSTRUMENTATIONKEY", TEST_IKEY);
envVars.put(
AgentExtensionVersionFinder.AGENT_EXTENSION_VERSION_ENVIRONMENT_VARIABLE, FAKE_VERSION);
}
@ -69,14 +66,14 @@ class StatusFileTests {
@Test
void homeEnvVarUpdatesBaseDir() {
String homeDir = "/temp/test";
envVars.set(StatusFile.HOME_ENV_VAR, homeDir);
envVars.put(StatusFile.HOME_ENV_VAR, homeDir);
assertThat(StatusFile.initLogDir()).isEqualTo("/temp/test/LogFiles/ApplicationInsights");
}
@Test
void siteLogDirHasPrecedenceOverHome() {
String homeDir = "/this/is/wrong";
envVars.set(StatusFile.HOME_ENV_VAR, homeDir);
envVars.put(StatusFile.HOME_ENV_VAR, homeDir);
System.setProperty("site.logdir", "/the/correct/dir");
assertThat(StatusFile.initLogDir()).isEqualTo("/the/correct/dir/ApplicationInsights");
}
@ -110,7 +107,7 @@ class StatusFileTests {
@Test
void connectionStringWorksToo() {
String ikey = "a-different-ikey-456789";
envVars.set("APPLICATIONINSIGHTS_CONNECTION_STRING", "InstrumentationKey=" + ikey);
envVars.put("APPLICATIONINSIGHTS_CONNECTION_STRING", "InstrumentationKey=" + ikey);
Map<String, Object> jsonMap = StatusFile.getJsonMap();
assertThat(jsonMap).containsEntry("Ikey", ikey);
}

Просмотреть файл

@ -14,22 +14,20 @@ import com.microsoft.applicationinsights.agent.internal.sampling.Samplers;
import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
@ExtendWith(SystemStubsExtension.class)
class RpConfigurationPollingTest {
@SystemStub EnvironmentVariables envVars = new EnvironmentVariables();
public static final Map<String, String> envVars = new HashMap<>();
@BeforeEach
void beforeEach() {
envVars.clear();
// default sampler at startup is "Sampler.alwaysOff()", and this test relies on real sampler
Configuration config = new Configuration();
config.sampling.percentage = 100.0;
@ -76,7 +74,9 @@ class RpConfigurationPollingTest {
// when
RuntimeConfigurator runtimeConfigurator =
new RuntimeConfigurator(telemetryClient, () -> null, config, item -> {}, null);
new RpConfigurationPolling(rpConfiguration, runtimeConfigurator).run();
new RpConfigurationPolling(
rpConfiguration, runtimeConfigurator, this::envVars, System::getProperty)
.run();
// then
assertThat(telemetryClient.getInstrumentationKey())
@ -106,10 +106,10 @@ class RpConfigurationPollingTest {
RpConfigurationPollingTest.class.getResource("/applicationinsights-rp.json").toURI());
rpConfiguration.lastModifiedTime = 0;
envVars.set(
envVars.put(
"APPLICATIONINSIGHTS_CONNECTION_STRING",
"InstrumentationKey=22222222-2222-2222-2222-222222222222");
envVars.set("APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE", "24");
envVars.put("APPLICATIONINSIGHTS_SAMPLING_PERCENTAGE", "24");
// pre-check
assertThat(telemetryClient.getInstrumentationKey())
@ -120,7 +120,9 @@ class RpConfigurationPollingTest {
// when
RuntimeConfigurator runtimeConfigurator =
new RuntimeConfigurator(telemetryClient, () -> null, config, item -> {}, null);
new RpConfigurationPolling(rpConfiguration, runtimeConfigurator).run();
new RpConfigurationPolling(
rpConfiguration, runtimeConfigurator, this::envVars, System::getProperty)
.run();
// then
assertThat(telemetryClient.getInstrumentationKey())
@ -134,4 +136,9 @@ class RpConfigurationPollingTest {
private static Double getCurrentSamplingPercentage() {
return SamplingTestUtil.getCurrentSamplingPercentage(DelegatingSampler.getInstance());
}
@SuppressWarnings("MethodCanBeStatic")
private String envVars(String key) {
return envVars.get(key);
}
}

Просмотреть файл

@ -214,10 +214,11 @@ public class ProfilingInitializerTest {
null);
}
@SuppressWarnings("DirectInvocationOnMock")
private static ProfilingInitializer createProfilingInitializer() {
TelemetryClient client = Mockito.mock(TelemetryClient.class);
MessageTelemetryBuilder messageBuilder = Mockito.mock(MessageTelemetryBuilder.class);
Mockito.when(client.newMessageTelemetryBuilder()).thenReturn(messageBuilder);
MessageTelemetryBuilder messageTelemetryBuilder = MessageTelemetryBuilder.create();
Mockito.when(client.newMessageTelemetryBuilder()).thenReturn(messageTelemetryBuilder);
Mockito.when(client.getConnectionString())
.thenReturn(
ConnectionString.parse(

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.contrib:opentelemetry-runtime-attach-core:1.32.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -15,6 +15,7 @@ val otelVersion = "1.36.0"
val otelInstrumentationAlphaVersion = "2.2.0-alpha"
val otelInstrumentationVersion = "2.2.0"
val otelContribAlphaVersion = "1.32.0-alpha"
val byteBuddyVersion = "1.14.11"
rootProject.extra["otelVersion"] = otelVersion
rootProject.extra["otelInstrumentationVersion"] = otelInstrumentationVersion
@ -22,7 +23,7 @@ rootProject.extra["otelInstrumentationAlphaVersion"] = otelInstrumentationAlphaV
rootProject.extra["otelContribAlphaVersion"] = otelContribAlphaVersion
val DEPENDENCY_BOMS = listOf(
"com.fasterxml.jackson:jackson-bom:2.16.2",
"com.fasterxml.jackson:jackson-bom:2.17.0",
"com.google.guava:guava-bom:33.1.0-jre",
"io.opentelemetry:opentelemetry-bom:${otelVersion}",
"io.opentelemetry:opentelemetry-bom-alpha:${otelVersion}-alpha",
@ -37,7 +38,6 @@ val DEPENDENCY_BOMS = listOf(
val autoServiceVersion = "1.1.1"
val autoValueVersion = "1.10.4"
val errorProneVersion = "2.26.1"
val byteBuddyVersion = "1.12.18"
val jmhVersion = "1.37"
val mockitoVersion = "4.11.0"
val slf4jVersion = "2.0.12"

Просмотреть файл

@ -2,7 +2,7 @@
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.azure:azure-sdk-bom:1.2.22=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.16.2=runtimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.0=runtimeClasspath
com.google.guava:guava-bom:33.1.0-jre=runtimeClasspath
io.netty:netty-bom:4.1.108.Final=runtimeClasspath
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.2.0-alpha=runtimeClasspath

Просмотреть файл

@ -4,33 +4,33 @@
_2024-04-09 03:58:13 UTC_
## Apache License, Version 2.0
**1** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-annotations` **Version:** `2.16.2`
**1** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-annotations` **Version:** `2.17.0`
> - **Project URL**: [https://github.com/FasterXML/jackson](https://github.com/FasterXML/jackson)
> - **Manifest License**: Apache License, Version 2.0 (Not Packaged)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
> - **Embedded license files**: [jackson-annotations-2.16.2.jar/META-INF/LICENSE](jackson-annotations-2.16.2.jar/META-INF/LICENSE)
- [jackson-annotations-2.16.2.jar/META-INF/NOTICE](jackson-annotations-2.16.2.jar/META-INF/NOTICE)
> - **Embedded license files**: [jackson-annotations-2.17.0.jar/META-INF/LICENSE](jackson-annotations-2.17.0.jar/META-INF/LICENSE)
- [jackson-annotations-2.17.0.jar/META-INF/NOTICE](jackson-annotations-2.17.0.jar/META-INF/NOTICE)
**2** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-core` **Version:** `2.16.2`
**2** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-core` **Version:** `2.17.0`
> - **Project URL**: [https://github.com/FasterXML/jackson-core](https://github.com/FasterXML/jackson-core)
> - **Manifest License**: Apache License, Version 2.0 (Not Packaged)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
> - **Embedded license files**: [jackson-core-2.16.2.jar/META-INF/LICENSE](jackson-core-2.16.2.jar/META-INF/LICENSE)
- [jackson-core-2.16.2.jar/META-INF/NOTICE](jackson-core-2.16.2.jar/META-INF/NOTICE)
> - **Embedded license files**: [jackson-core-2.17.0.jar/META-INF/LICENSE](jackson-core-2.17.0.jar/META-INF/LICENSE)
- [jackson-core-2.17.0.jar/META-INF/NOTICE](jackson-core-2.17.0.jar/META-INF/NOTICE)
**3** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-databind` **Version:** `2.16.2`
**3** **Group:** `com.fasterxml.jackson.core` **Name:** `jackson-databind` **Version:** `2.17.0`
> - **Project URL**: [https://github.com/FasterXML/jackson](https://github.com/FasterXML/jackson)
> - **Manifest License**: Apache License, Version 2.0 (Not Packaged)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
> - **Embedded license files**: [jackson-databind-2.16.2.jar/META-INF/LICENSE](jackson-databind-2.16.2.jar/META-INF/LICENSE)
- [jackson-databind-2.16.2.jar/META-INF/NOTICE](jackson-databind-2.16.2.jar/META-INF/NOTICE)
> - **Embedded license files**: [jackson-databind-2.17.0.jar/META-INF/LICENSE](jackson-databind-2.17.0.jar/META-INF/LICENSE)
- [jackson-databind-2.17.0.jar/META-INF/NOTICE](jackson-databind-2.17.0.jar/META-INF/NOTICE)
**4** **Group:** `com.fasterxml.jackson.datatype` **Name:** `jackson-datatype-jsr310` **Version:** `2.16.2`
**4** **Group:** `com.fasterxml.jackson.datatype` **Name:** `jackson-datatype-jsr310` **Version:** `2.17.0`
> - **Manifest Project URL**: [https://github.com/FasterXML/jackson-modules-java8/jackson-datatype-jsr310](https://github.com/FasterXML/jackson-modules-java8/jackson-datatype-jsr310)
> - **Manifest License**: Apache License, Version 2.0 (Not Packaged)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
> - **Embedded license files**: [jackson-datatype-jsr310-2.16.2.jar/META-INF/LICENSE](jackson-datatype-jsr310-2.16.2.jar/META-INF/LICENSE)
- [jackson-datatype-jsr310-2.16.2.jar/META-INF/NOTICE](jackson-datatype-jsr310-2.16.2.jar/META-INF/NOTICE)
> - **Embedded license files**: [jackson-datatype-jsr310-2.17.0.jar/META-INF/LICENSE](jackson-datatype-jsr310-2.17.0.jar/META-INF/LICENSE)
- [jackson-datatype-jsr310-2.17.0.jar/META-INF/NOTICE](jackson-datatype-jsr310-2.17.0.jar/META-INF/NOTICE)
**5** **Group:** `com.github.stephenc.jcip` **Name:** `jcip-annotations` **Version:** `1.0-1`
> - **POM Project URL**: [http://stephenc.github.com/jcip-annotations](http://stephenc.github.com/jcip-annotations)