Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ProfilerEndpoint from connection string #1694

Merged
merged 2 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;

/**
* Configuration of the service profiler subsystem
*/
Expand All @@ -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;
Expand All @@ -58,7 +60,7 @@ public ServiceProfilerServiceConfig(
int configPollPeriod,
int periodicRecordingDuration,
int periodicRecordingInterval,
String serviceProfilerFrontEndPoint,
URI serviceProfilerFrontEndPoint,
boolean enabled,
String memoryTriggeredSettings,
String cpuTriggeredSettings
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ 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;
this.userAgent = userAgent;
closed = false;
}

public ProfilerFrontendClientV2(String hostUrl, String instrumentationKey, CloseableHttpClient httpClient) {
public ProfilerFrontendClientV2(URI hostUrl, String instrumentationKey, CloseableHttpClient httpClient) {
this(hostUrl, instrumentationKey, httpClient, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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))
Expand All @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -95,7 +96,7 @@ public void endToEndAlertTriggerManual() throws InterruptedException, ExecutionE
});
}

public void endToEndAlertTriggerCycle(boolean triggerNow, MetricTelemetry metricTelemetry, Consumer<EventTelemetry> assertTelemetry) throws InterruptedException, ExecutionException {
public void endToEndAlertTriggerCycle(boolean triggerNow, MetricTelemetry metricTelemetry, Consumer<EventTelemetry> assertTelemetry) throws Exception {
AtomicBoolean profileInvoked = new AtomicBoolean(false);
AtomicReference<EventTelemetry> serviceProfilerIndex = new AtomicReference<>();

Expand Down Expand Up @@ -147,7 +148,7 @@ public void track(Telemetry telemetry) {
1,
2,
3,
"localhost",
new URI("http://localhost"),
true,
null,
null
Expand Down Expand Up @@ -202,12 +203,12 @@ private ProfilerService awaitReferenceSet(AtomicReference<ProfilerService> 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)) {
Expand Down