Search in sources :

Example 1 with ProfilerFrontendClientV2

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");
}
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 ProfilerFrontendClientV2

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");
}
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) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProfilerFrontendClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2) URL(java.net.URL) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with ProfilerFrontendClientV2

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);
}
Also used : ServiceProfilerClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2) ProfilerFrontendClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2) ServiceProfilerUploader(com.microsoft.applicationinsights.serviceprofilerapi.upload.ServiceProfilerUploader) JfrProfiler(com.microsoft.applicationinsights.serviceprofilerapi.profiler.JfrProfiler)

Example 4 with ProfilerFrontendClientV2

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");
}
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) ArtifactAcceptedResponse(com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) 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)

Aggregations

ProfilerFrontendClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2)4 HttpHeaders (com.azure.core.http.HttpHeaders)3 HttpMethod (com.azure.core.http.HttpMethod)3 HttpPipeline (com.azure.core.http.HttpPipeline)3 HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)3 HttpRequest (com.azure.core.http.HttpRequest)3 ArtifactAcceptedResponse (com.microsoft.applicationinsights.serviceprofilerapi.client.contract.ArtifactAcceptedResponse)3 BlobAccessPass (com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass)3 IOException (java.io.IOException)3 URL (java.net.URL)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Instant (java.time.Instant)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Test (org.junit.jupiter.api.Test)3 Mono (reactor.core.publisher.Mono)3 ServiceProfilerClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2)1