use of com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass 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.contract.BlobAccessPass in project ApplicationInsights-Java by microsoft.
the class ServiceProfilerUploaderTest method uploadFileGoodPathReturnsExpectedResponse.
@Test
void uploadFileGoodPathReturnsExpectedResponse() throws IOException {
ServiceProfilerClientV2 serviceProfilerClient = stubServiceProfilerClient();
File tmpFile = createFakeJfrFile();
UUID appId = UUID.randomUUID();
ServiceProfilerUploader serviceProfilerUploader = new ServiceProfilerUploader(serviceProfilerClient, "a-machine-name", "a-process-id", appId::toString, "a-role-name") {
@Override
protected Mono<UploadFinishArgs> performUpload(UploadContext uploadContext, BlobAccessPass uploadPass, File file) {
return Mono.just(new UploadFinishArgs("a-stamp-id", "a-timestamp"));
}
};
serviceProfilerUploader.uploadJfrFile("a-trigger", 321, tmpFile, 0.0, 0.0).subscribe(result -> {
assertThat(result.getServiceProfilerIndex().getProperties().get(ServiceProfilerIndex.SERVICE_PROFILER_STAMPID_PROPERTY_NAME)).isEqualTo("a-stamp-id");
assertThat(result.getServiceProfilerIndex().getProperties().get(ServiceProfilerIndex.SERVICE_PROFILER_MACHINENAME_PROPERTY_NAME)).isEqualTo("a-machine-name");
assertThat(result.getServiceProfilerIndex().getProperties().get(ServiceProfilerIndex.SERVICE_PROFILER_ETLFILESESSIONID_PROPERTY_NAME)).isEqualTo("a-timestamp");
assertThat(result.getServiceProfilerIndex().getProperties().get(ServiceProfilerIndex.SERVICE_PROFILER_DATACUBE_PROPERTY_NAME)).isEqualTo(appId.toString());
});
}
use of com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass in project ApplicationInsights-Java by microsoft.
the class ProfilerFrontendClientV2 method getUploadAccess.
/**
* Obtain permission to upload a profile to service profiler.
*/
@Override
public Mono<BlobAccessPass> getUploadAccess(UUID profileId) {
URL requestUrl = uploadRequestUri(profileId);
LOGGER.debug("Etl upload access request: {}", requestUrl);
return executePostWithRedirect(requestUrl).map(response -> {
if (response == null) {
// this shouldn't happen, the mono should complete with a response or a failure
throw new AssertionError("http response mono returned empty");
}
// response body is not consumed below
consumeResponseBody(response);
if (response.getStatusCode() >= 300) {
throw new HttpResponseException(response);
}
String location = response.getHeaderValue("Location");
if (location == null || location.isEmpty()) {
throw new AssertionError("response did not have a location");
}
return new BlobAccessPass(null, location, null);
});
}
Aggregations