Search in sources :

Example 1 with UploadContext

use of com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext in project ApplicationInsights-Java by microsoft.

the class ServiceProfilerUploader method uploadJfrFile.

/**
 * Upload a given JFR file and return associated metadata of the uploaded profile.
 */
public Mono<UploadResult> uploadJfrFile(String triggerName, long timestamp, File file, double cpuUsage, double memoryUsage) {
    String appId = appIdSupplier.get();
    if (appId == null || appId.isEmpty()) {
        LOGGER.error("Failed to upload due to lack of appId");
        return Mono.error(new UploadFailedException("Failed to upload due to lack of appId"));
    }
    UUID profileId = UUID.randomUUID();
    UploadContext uploadContext = new UploadContext(machineName, UUID.fromString(appId), timestamp, file, profileId);
    // upload trace to service profiler
    return uploadTrace(uploadContext).map(done -> {
        // return associated profile metadata
        String fileId = createId(9);
        String formattedTimestamp = TimestampContract.padNanos(done.getTimeStamp());
        return new UploadResult(new ServiceProfilerIndex(triggerName, fileId, done.getStampId(), UUID.fromString(appId), formattedTimestamp, uploadContext.getMachineName(), OsPlatformProvider.getOsPlatformDescription(), processId, "Profile", profileId.toString(), "jfr", cpuUsage, memoryUsage));
    });
}
Also used : ServiceProfilerIndex(com.microsoft.applicationinsights.profiler.uploader.ServiceProfilerIndex) UploadResult(com.microsoft.applicationinsights.profiler.uploader.UploadResult) UUID(java.util.UUID) UploadContext(com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext)

Example 2 with UploadContext

use of com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext 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 UploadContext

use of com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext in project ApplicationInsights-Java by microsoft.

the class ServiceProfilerUploaderTest method roleNameIsCorrectlyAddedToMetaData.

@Test
void roleNameIsCorrectlyAddedToMetaData() throws IOException {
    ServiceProfilerClientV2 serviceProfilerClient = stubServiceProfilerClient();
    File tmpFile = createFakeJfrFile();
    UUID appId = UUID.randomUUID();
    BlobUploadFromFileOptions blobOptions = new ServiceProfilerUploader(serviceProfilerClient, "a-machine-name", "a-process-id", appId::toString, "a-role-name").createBlockBlobOptions(tmpFile, new UploadContext("a-machine-name", UUID.randomUUID(), 1, tmpFile, UUID.randomUUID()));
    // Role name is set correctly
    assertThat(blobOptions.getMetadata().get(BlobMetadataConstants.ROLE_NAME_META_NAME)).isEqualTo("a-role-name");
    blobOptions = new ServiceProfilerUploader(serviceProfilerClient, "a-machine-name", "a-process-id", appId::toString, null).createBlockBlobOptions(tmpFile, new UploadContext("a-machine-name", UUID.randomUUID(), 1, tmpFile, UUID.randomUUID()));
    // Null role name tag is not added
    assertThat(blobOptions.getMetadata().get(BlobMetadataConstants.ROLE_NAME_META_NAME)).isNull();
}
Also used : ServiceProfilerClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2) BlobUploadFromFileOptions(com.azure.storage.blob.options.BlobUploadFromFileOptions) UUID(java.util.UUID) File(java.io.File) UploadContext(com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext) Test(org.junit.jupiter.api.Test)

Aggregations

UploadContext (com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext)3 UUID (java.util.UUID)3 ServiceProfilerClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2)2 File (java.io.File)2 Test (org.junit.jupiter.api.Test)2 BlobUploadFromFileOptions (com.azure.storage.blob.options.BlobUploadFromFileOptions)1 ServiceProfilerIndex (com.microsoft.applicationinsights.profiler.uploader.ServiceProfilerIndex)1 UploadResult (com.microsoft.applicationinsights.profiler.uploader.UploadResult)1 BlobAccessPass (com.microsoft.applicationinsights.serviceprofilerapi.client.contract.BlobAccessPass)1 UploadFinishArgs (com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadFinishArgs)1