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));
});
}
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());
});
}
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();
}
Aggregations