diff --git a/agent/agent-profiler/agent-profiler-api/src/main/java/com/microsoft/applicationinsights/profiler/config/FrontendEndpoints.java b/agent/agent-profiler/agent-profiler-api/src/main/java/com/microsoft/applicationinsights/profiler/config/FrontendEndpoints.java deleted file mode 100644 index 980a30e8d41..00000000000 --- a/agent/agent-profiler/agent-profiler-api/src/main/java/com/microsoft/applicationinsights/profiler/config/FrontendEndpoints.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ApplicationInsights-Java - * Copyright (c) Microsoft Corporation - * All rights reserved. - * - * MIT License - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the ""Software""), to deal in the Software - * without restriction, including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package com.microsoft.applicationinsights.profiler.config; - -/** - * {@code FrontendEndpoints} class defines well-known addresses for Application Insights Service - * Profiler frontend service. - * - *

This class is intended for internal Java profiler use. - */ -public class FrontendEndpoints { - public static final String PRODUCT_GLOBAL = "https://agent.azureserviceprofiler.net"; - public static final String TEST_GLOBAL = "https://agent-test.azureserviceprofiler.net"; - -} diff --git a/agent/agent-profiler/agent-profiler-api/src/main/java/com/microsoft/applicationinsights/profiler/config/ServiceProfilerServiceConfig.java b/agent/agent-profiler/agent-profiler-api/src/main/java/com/microsoft/applicationinsights/profiler/config/ServiceProfilerServiceConfig.java index 997fa250a9d..71d533775a6 100644 --- a/agent/agent-profiler/agent-profiler-api/src/main/java/com/microsoft/applicationinsights/profiler/config/ServiceProfilerServiceConfig.java +++ b/agent/agent-profiler/agent-profiler-api/src/main/java/com/microsoft/applicationinsights/profiler/config/ServiceProfilerServiceConfig.java @@ -24,6 +24,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.URI; + /** * Configuration of the service profiler subsystem */ @@ -43,7 +45,7 @@ public class ServiceProfilerServiceConfig { // default interval of periodic profiles private final int periodicRecordingInterval; - private final String serviceProfilerFrontEndPoint; + private final URI serviceProfilerFrontEndPoint; // Enable entire service profiler subsystem private final boolean enabled; @@ -58,7 +60,7 @@ public ServiceProfilerServiceConfig( int configPollPeriod, int periodicRecordingDuration, int periodicRecordingInterval, - String serviceProfilerFrontEndPoint, + URI serviceProfilerFrontEndPoint, boolean enabled, String memoryTriggeredSettings, String cpuTriggeredSettings @@ -84,8 +86,8 @@ public long getPeriodicRecordingInterval() { return periodicRecordingInterval != -1 ? periodicRecordingInterval : DEFAULT_PERIODIC_RECORDING_INTERVAL_IN_S; } - public String getServiceProfilerFrontEndPoint() { - return serviceProfilerFrontEndPoint != null ? serviceProfilerFrontEndPoint : FrontendEndpoints.PRODUCT_GLOBAL; + public URI getServiceProfilerFrontEndPoint() { + return serviceProfilerFrontEndPoint; } public boolean enabled() { diff --git a/agent/agent-profiler/agent-service-profiler/src/main/java/com/microsoft/applicationinsights/serviceprofilerapi/client/ProfilerFrontendClientV2.java b/agent/agent-profiler/agent-service-profiler/src/main/java/com/microsoft/applicationinsights/serviceprofilerapi/client/ProfilerFrontendClientV2.java index 715f0f36661..029c6b664d1 100644 --- a/agent/agent-profiler/agent-service-profiler/src/main/java/com/microsoft/applicationinsights/serviceprofilerapi/client/ProfilerFrontendClientV2.java +++ b/agent/agent-profiler/agent-service-profiler/src/main/java/com/microsoft/applicationinsights/serviceprofilerapi/client/ProfilerFrontendClientV2.java @@ -63,14 +63,14 @@ public class ProfilerFrontendClientV2 implements ServiceProfilerClientV2 { public static final String FEATURE_VERSION = "1.0.0"; public static final String API_FEATURE_VERSION = "2020-10-14-preview"; - private final String hostUrl; + private final URI hostUrl; private final String instrumentationKey; private final CloseableHttpClient httpClient; private final String userAgent; private boolean closed; - public ProfilerFrontendClientV2(String hostUrl, String instrumentationKey, CloseableHttpClient httpClient, String userAgent) { + public ProfilerFrontendClientV2(URI hostUrl, String instrumentationKey, CloseableHttpClient httpClient, String userAgent) { this.hostUrl = hostUrl; this.instrumentationKey = instrumentationKey; this.httpClient = httpClient; @@ -78,7 +78,7 @@ public ProfilerFrontendClientV2(String hostUrl, String instrumentationKey, Close closed = false; } - public ProfilerFrontendClientV2(String hostUrl, String instrumentationKey, CloseableHttpClient httpClient) { + public ProfilerFrontendClientV2(URI hostUrl, String instrumentationKey, CloseableHttpClient httpClient) { this(hostUrl, instrumentationKey, httpClient, null); } diff --git a/agent/agent-profiler/agent-service-profiler/src/test/java/com/microsoft/applicationinsights/serviceprofilerapi/upload/ProfilerFrontendClientV2Test.java b/agent/agent-profiler/agent-service-profiler/src/test/java/com/microsoft/applicationinsights/serviceprofilerapi/upload/ProfilerFrontendClientV2Test.java index 8208cbe1c64..681144bc80b 100644 --- a/agent/agent-profiler/agent-service-profiler/src/test/java/com/microsoft/applicationinsights/serviceprofilerapi/upload/ProfilerFrontendClientV2Test.java +++ b/agent/agent-profiler/agent-service-profiler/src/test/java/com/microsoft/applicationinsights/serviceprofilerapi/upload/ProfilerFrontendClientV2Test.java @@ -21,6 +21,7 @@ package com.microsoft.applicationinsights.serviceprofilerapi.upload; import java.io.IOException; +import java.net.URI; import java.net.URISyntaxException; import java.time.Instant; import java.util.Date; @@ -42,7 +43,7 @@ public void settingsPullHitsCorrectUrl() throws ClientClosedException, IOExcepti CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class); - ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2("a-host", "a-instrumentation-key", httpClient); + ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2(new URI("http://a-host"), "a-instrumentation-key", httpClient); Date now = Date.from(Instant.now()); profilerFrontendClientV2.getSettings(now); @@ -79,7 +80,7 @@ public void uploadHitsCorrectUrl() throws ClientClosedException, IOException, UR CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class); - ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2("a-host", "a-instrumentation-key", httpClient); + ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2(new URI("http://a-host"), "a-instrumentation-key", httpClient); profilerFrontendClientV2.getUploadAccess(id); Mockito.verify(httpClient, Mockito.times(1)) @@ -94,7 +95,7 @@ public void uploadFinishedHitsCorrectUrl() throws ClientClosedException, IOExcep CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class); - ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2("a-host", "a-instrumentation-key", httpClient); + ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2(new URI("http://a-host"), "a-instrumentation-key", httpClient); UUID id = UUID.randomUUID(); profilerFrontendClientV2.reportUploadFinish(id, "an-etag"); diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/AiComponentInstaller.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/AiComponentInstaller.java index e5d27911c73..7986379933f 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/AiComponentInstaller.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/AiComponentInstaller.java @@ -70,6 +70,7 @@ import java.io.File; import java.lang.instrument.Instrumentation; +import java.net.URI; import java.util.ArrayList; import java.util.concurrent.CountDownLatch; @@ -228,11 +229,12 @@ private static String formApplicationInsightsUserAgent() { } private static ServiceProfilerServiceConfig formServiceProfilerConfig(ProfilerConfiguration configuration) { + URI serviceProfilerFrontEndPoint = TelemetryConfiguration.getActive().getEndpointProvider().getProfilerEndpoint(); return new ServiceProfilerServiceConfig( configuration.configPollPeriodSeconds, configuration.periodicRecordingDurationSeconds, configuration.periodicRecordingIntervalSeconds, - configuration.serviceProfilerFrontEndPoint, + serviceProfilerFrontEndPoint, configuration.enabled, configuration.memoryTriggeredSettings, configuration.cpuTriggeredSettings diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/wasbootstrap/configuration/Configuration.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/wasbootstrap/configuration/Configuration.java index a0047aff672..022abd16c12 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/wasbootstrap/configuration/Configuration.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/wasbootstrap/configuration/Configuration.java @@ -587,7 +587,6 @@ public static class ProfilerConfiguration { public int configPollPeriodSeconds = 60; public int periodicRecordingDurationSeconds = 120; public int periodicRecordingIntervalSeconds = 60 * 60; - public String serviceProfilerFrontEndPoint = null; public boolean enabled = false; public String memoryTriggeredSettings = "profile"; public String cpuTriggeredSettings = "profile"; diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/wasbootstrap/configuration/ConfigurationBuilder.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/wasbootstrap/configuration/ConfigurationBuilder.java index 5b759a91452..4b3df7318c9 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/wasbootstrap/configuration/ConfigurationBuilder.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/wasbootstrap/configuration/ConfigurationBuilder.java @@ -78,7 +78,6 @@ public class ConfigurationBuilder { private static final String WEBSITE_INSTANCE_ID = "WEBSITE_INSTANCE_ID"; private static final String APPLICATIONINSIGHTS_PROFILER_ENABLED = "APPLICATIONINSIGHTS_PROFILER_ENABLED"; - private static final String APPLICATIONINSIGHTS_PROFILER_FRONTEND_POINT = "APPLICATIONINSIGHTS_PROFILER_FRONTEND_POINT"; private static final String APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS = "APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS"; @@ -112,8 +111,6 @@ public static Configuration create(Path agentJarPath, RpConfiguration rpConfigur private static void overlayProfilerConfiguration(Configuration config) { config.preview.profiler.enabled = Boolean .parseBoolean(overlayWithEnvVar(APPLICATIONINSIGHTS_PROFILER_ENABLED, Boolean.toString(config.preview.profiler.enabled))); - config.preview.profiler.serviceProfilerFrontEndPoint = - overlayWithEnvVar(APPLICATIONINSIGHTS_PROFILER_FRONTEND_POINT, config.preview.profiler.serviceProfilerFrontEndPoint); } private static void loadLogCaptureEnvVar(Configuration config) { diff --git a/core/src/test/java/com/microsoft/applicationinsights/internal/profiler/ProfilerServiceTest.java b/core/src/test/java/com/microsoft/applicationinsights/internal/profiler/ProfilerServiceTest.java index e8521218c22..b72cf6c4263 100644 --- a/core/src/test/java/com/microsoft/applicationinsights/internal/profiler/ProfilerServiceTest.java +++ b/core/src/test/java/com/microsoft/applicationinsights/internal/profiler/ProfilerServiceTest.java @@ -47,12 +47,13 @@ import java.io.File; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.charset.UnsupportedCharsetException; import java.time.Duration; import java.time.Instant; import java.util.Date; import java.util.UUID; -import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicBoolean; @@ -72,7 +73,7 @@ public class ProfilerServiceTest { final String jfrExtension = "jfr"; @Test - public void endToEndAlertTriggerCpu() throws InterruptedException, ExecutionException { + public void endToEndAlertTriggerCpu() throws Exception { endToEndAlertTriggerCycle( false, new MetricTelemetry(TOTAL_CPU_PC_METRIC_NAME, 100.0), @@ -84,7 +85,7 @@ public void endToEndAlertTriggerCpu() throws InterruptedException, ExecutionExce } @Test - public void endToEndAlertTriggerManual() throws InterruptedException, ExecutionException { + public void endToEndAlertTriggerManual() throws Exception { endToEndAlertTriggerCycle( true, new MetricTelemetry(HEAP_MEM_USED_PERCENTAGE, 0.0), @@ -95,7 +96,7 @@ public void endToEndAlertTriggerManual() throws InterruptedException, ExecutionE }); } - public void endToEndAlertTriggerCycle(boolean triggerNow, MetricTelemetry metricTelemetry, Consumer assertTelemetry) throws InterruptedException, ExecutionException { + public void endToEndAlertTriggerCycle(boolean triggerNow, MetricTelemetry metricTelemetry, Consumer assertTelemetry) throws Exception { AtomicBoolean profileInvoked = new AtomicBoolean(false); AtomicReference serviceProfilerIndex = new AtomicReference<>(); @@ -147,7 +148,7 @@ public void track(Telemetry telemetry) { 1, 2, 3, - "localhost", + new URI("http://localhost"), true, null, null @@ -202,12 +203,12 @@ private ProfilerService awaitReferenceSet(AtomicReference servi return service.get(); } - private JfrProfiler getJfrDaemon(AtomicBoolean profileInvoked) { + private JfrProfiler getJfrDaemon(AtomicBoolean profileInvoked) throws URISyntaxException { return new JfrProfiler(new ServiceProfilerServiceConfig( 1, 2, 3, - "localhost", + new URI("http://localhost"), false, null, null)) {