use of com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2 in project ApplicationInsights-Java by microsoft.
the class ProfilerFrontendClientV2Test method uploadHitsCorrectUrl.
@Test
void uploadHitsCorrectUrl() throws IOException {
AtomicReference<HttpRequest> requestHolder = new AtomicReference<>();
HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> {
requestHolder.set(request);
return Mono.just(mockResponse(request));
}).build();
ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2(new URL("http://a-host"), "a-instrumentation-key", httpPipeline);
UUID id = UUID.randomUUID();
BlobAccessPass pass = profilerFrontendClientV2.getUploadAccess(id).block();
HttpRequest request = requestHolder.get();
String url = request.getUrl().toString();
assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(url.contains("/api/apps/a-instrumentation-key/artifactkinds/profile/artifacts/" + id)).isTrue();
assertThat(url.contains("action=gettoken")).isTrue();
assertThat(pass.getUriWithSasToken()).isEqualTo("http://localhost:99999");
}
use of com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2 in project ApplicationInsights-Java by microsoft.
the class ProfilerFrontendClientV2Test method settingsPullHitsCorrectUrl.
@Test
void settingsPullHitsCorrectUrl() throws IOException {
AtomicReference<HttpRequest> requestHolder = new AtomicReference<>();
HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> {
requestHolder.set(request);
return Mono.just(mockResponse(request, 200, "some-settings"));
}).build();
ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2(new URL("http://a-host"), "a-instrumentation-key", httpPipeline);
Date now = Date.from(Instant.now());
String settings = profilerFrontendClientV2.getSettings(now).block();
HttpRequest request = requestHolder.get();
String url = request.getUrl().toString();
assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(url.contains("a-instrumentation-key")).isTrue();
assertThat(url.contains("/api/profileragent/v4/settings")).isTrue();
assertThat(settings).isEqualTo("some-settings");
}
use of com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2 in project ApplicationInsights-Java by microsoft.
the class JfrProfilerServiceFactory method initialize.
@Override
public synchronized Future<ProfilerService> initialize(Supplier<String> appIdSupplier, UploadCompleteHandler uploadCompleteObserver, ProfilerConfigurationHandler profilerConfigurationHandler, String processId, ServiceProfilerServiceConfig config, String machineName, String instrumentationKey, HttpPipeline httpPipeline, ScheduledExecutorService serviceProfilerExecutorService, String userAgent, String roleName) {
if (instance == null) {
ServiceProfilerClientV2 serviceProfilerClient = new ProfilerFrontendClientV2(config.getServiceProfilerFrontEndPoint(), instrumentationKey, httpPipeline, userAgent);
ServiceProfilerUploader uploader = new ServiceProfilerUploader(serviceProfilerClient, machineName, processId, appIdSupplier, roleName);
instance = new JfrProfilerService(appIdSupplier, config, new JfrProfiler(config), profilerConfigurationHandler, uploadCompleteObserver, serviceProfilerClient, uploader, serviceProfilerExecutorService);
return instance.initialize();
}
return CompletableFuture.completedFuture(instance);
}
use of com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2 in project ApplicationInsights-Java by microsoft.
the class ProfilerFrontendClientV2Test method uploadFinishedHitsCorrectUrl.
@Test
void uploadFinishedHitsCorrectUrl() throws IOException {
AtomicReference<HttpRequest> requestHolder = new AtomicReference<>();
HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> {
requestHolder.set(request);
return Mono.just(mockResponse(request, 201, "{\"acceptedTime\":\"a-time\",\"blobUri\":\"a-blob-uri\",\"correlationId\":\"a-correlation-id\",\"stampId\":\"a-stamp\"}"));
}).build();
ProfilerFrontendClientV2 profilerFrontendClientV2 = new ProfilerFrontendClientV2(new URL("http://a-host"), "a-instrumentation-key", httpPipeline);
UUID id = UUID.randomUUID();
ArtifactAcceptedResponse artifactAcceptedResponse = profilerFrontendClientV2.reportUploadFinish(id, "an-etag").block();
HttpRequest request = requestHolder.get();
String url = request.getUrl().toString();
assertThat(request.getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(url.contains("/api/apps/a-instrumentation-key/artifactkinds/profile/artifacts/" + id)).isTrue();
assertThat(url.contains("action=commit")).isTrue();
assertThat(artifactAcceptedResponse.getAcceptedTime()).isEqualTo("a-time");
assertThat(artifactAcceptedResponse.getBlobUri()).isEqualTo("a-blob-uri");
assertThat(artifactAcceptedResponse.getCorrelationId()).isEqualTo("a-correlation-id");
assertThat(artifactAcceptedResponse.getStampId()).isEqualTo("a-stamp");
}
Aggregations