Search in sources :

Example 1 with BlobAccessPass

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");
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) ArtifactAcceptedResponse(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse) BlobAccessPass(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass) URL(java.net.URL) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpPipeline(com.azure.core.http.HttpPipeline) IOException(java.io.IOException) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) HttpHeaders(com.azure.core.http.HttpHeaders) UUID(java.util.UUID) Instant(java.time.Instant) AtomicReference(java.util.concurrent.atomic.AtomicReference) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) HttpRequest(com.azure.core.http.HttpRequest) HttpMethod(com.azure.core.http.HttpMethod) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) ProfilerFrontendClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) BlobAccessPass(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProfilerFrontendClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2) UUID(java.util.UUID) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 2 with BlobAccessPass

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());
    });
}
Also used : ServiceProfilerClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2) BlobAccessPass(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass) UUID(java.util.UUID) File(java.io.File) UploadContext(com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext) UploadFinishArgs(com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadFinishArgs) Test(org.junit.jupiter.api.Test)

Example 3 with BlobAccessPass

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);
    });
}
Also used : BlobAccessPass(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass) HttpResponseException(com.azure.core.exception.HttpResponseException) URL(java.net.URL)

Aggregations

BlobAccessPass (com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass)3 URL (java.net.URL)2 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)2 HttpResponseException (com.azure.core.exception.HttpResponseException)1 HttpHeaders (com.azure.core.http.HttpHeaders)1 HttpMethod (com.azure.core.http.HttpMethod)1 HttpPipeline (com.azure.core.http.HttpPipeline)1 HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)1 HttpRequest (com.azure.core.http.HttpRequest)1 ProfilerFrontendClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2)1 ServiceProfilerClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2)1 ArtifactAcceptedResponse (com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse)1 UploadContext (com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext)1 UploadFinishArgs (com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadFinishArgs)1 File (java.io.File)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Instant (java.time.Instant)1 Date (java.util.Date)1