From 05e28546c320275ce8093017962dc1168f2ff1ea Mon Sep 17 00:00:00 2001 From: Helen <56097766+heyams@users.noreply.github.com> Date: Tue, 31 Jan 2023 12:51:01 -0800 Subject: [PATCH] Support metircIntervalSeconds backward compatibility (#2893) #2875 --------- Co-authored-by: Trask Stalnaker --- .../internal/configuration/Configuration.java | 3 +- .../configuration/ConfigurationBuilder.java | 29 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java index 7cf3c633c5d..1a28973a7d0 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/Configuration.java @@ -303,7 +303,8 @@ public static class PreviewConfiguration { // this is just here to detect if using this old setting in order to give a helpful message @Deprecated public boolean openTelemetryApiSupport; public PreviewInstrumentation instrumentation = new PreviewInstrumentation(); - // this is just here to detect if using this old setting in order to give a helpful message + // these are just here to detect if using this old setting in order to give a helpful message + @Deprecated public int metricIntervalSeconds = 60; @Deprecated public Boolean ignoreRemoteParentNotSampled; public boolean captureControllerSpans; // this is just here to detect if using this old setting in order to give a helpful message diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java index 9d3d58f4a65..6a42248f379 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java @@ -99,6 +99,10 @@ public class ConfigurationBuilder { private static final String APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLEDIAGNOSTICS = "APPLICATIONINSIGHTS_PREVIEW_PROFILER_ENABLEDIAGNOSTICS"; + @Deprecated + private static final String APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS = + "APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS"; + private static final String APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS = "APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS"; @@ -149,6 +153,13 @@ private static void logConfigurationWarnings(Configuration config) { "\"openTelemetryApiSupport\" is no longer in preview and it is now the" + " (one and only) default behavior"); } + if (config.preview.metricIntervalSeconds != 60) { + configurationLogger.warn( + "\"metricIntervalSeconds\" is no longer in preview and it has been GA since 3.4.9"); + if (config.metricIntervalSeconds == 60) { + config.metricIntervalSeconds = config.preview.metricIntervalSeconds; + } + } if (config.preview.instrumentation.azureSdk.enabled) { configurationLogger.warn( "\"azureSdk\" instrumentation is no longer in preview" @@ -557,9 +568,21 @@ static void overlayFromEnv(Configuration config, Path baseDir) throws IOExceptio overlayWithEnvVar( APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_FILE_PATH, config.selfDiagnostics.file.path); - config.metricIntervalSeconds = - overlayWithEnvVar( - APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS, config.metricIntervalSeconds); + String deprecatedMetricIntervalSeconds = + getEnvVar(APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS); + String metricIntervalSeconds = getEnvVar(APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS); + if (metricIntervalSeconds != null) { + config.metricIntervalSeconds = + overlayWithEnvVar( + APPLICATIONINSIGHTS_METRIC_INTERVAL_SECONDS, config.metricIntervalSeconds); + } 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); + } config.preview.instrumentation.springIntegration.enabled = overlayWithEnvVar(