Search in sources :

Example 1 with ServiceProfilerUploader

use of com.microsoft.applicationinsights.serviceprofilerapi.upload.ServiceProfilerUploader in project ApplicationInsights-Java by microsoft.

the class ProfilerServiceTest method endToEndAlertTriggerCycle.

void endToEndAlertTriggerCycle(boolean triggerNow, TelemetryItem metricTelemetry, Consumer<TelemetryEventData> assertTelemetry) throws Exception {
    AtomicBoolean profileInvoked = new AtomicBoolean(false);
    AtomicReference<TelemetryEventData> serviceProfilerIndex = new AtomicReference<>();
    String appId = UUID.randomUUID().toString();
    ServiceProfilerClientV2 clientV2 = stubClient(triggerNow);
    Supplier<String> appIdSupplier = () -> appId;
    ServiceProfilerUploader serviceProfilerUploader = getServiceProfilerJfrUpload(clientV2, appIdSupplier);
    JfrProfiler jfrProfiler = getJfrDaemon(profileInvoked);
    Object monitor = new Object();
    TelemetryClient client = spy(TelemetryClient.builder().setCustomDimensions(new HashMap<>()).build());
    doAnswer(invocation -> {
        TelemetryItem telemetry = invocation.getArgument(0);
        MonitorDomain data = telemetry.getData().getBaseData();
        if (data instanceof TelemetryEventData) {
            if ("ServiceProfilerIndex".equals(((TelemetryEventData) data).getName())) {
                serviceProfilerIndex.set((TelemetryEventData) data);
            }
            synchronized (monitor) {
                monitor.notifyAll();
            }
        }
        return null;
    }).when(client).trackAsync(any(TelemetryItem.class));
    ScheduledExecutorService serviceProfilerExecutorService = Executors.newScheduledThreadPool(2, ThreadPoolUtils.createDaemonThreadFactory(ProfilerServiceFactory.class, "ServiceProfilerService"));
    ScheduledExecutorService alertServiceExecutorService = Executors.newSingleThreadScheduledExecutor(ThreadPoolUtils.createDaemonThreadFactory(ProfilerServiceFactory.class, "ServiceProfilerAlertingService"));
    AtomicReference<ProfilerService> service = new AtomicReference<>();
    AlertingSubsystem alertService = AlertingServiceFactory.create(alert -> awaitReferenceSet(service).getProfiler().accept(alert), TelemetryObservers.INSTANCE, client, alertServiceExecutorService, new GcEventMonitor.GcEventMonitorConfiguration(GcReportingLevel.ALL));
    service.set(new JfrProfilerService(() -> appId, new ServiceProfilerServiceConfig(1, 2, 3, new URL("http://localhost"), null, null, LocalFileSystemUtils.getTempDir()), jfrProfiler, ProfilerServiceInitializer.updateAlertingConfig(alertService), ProfilerServiceInitializer.sendServiceProfilerIndex(client), clientV2, serviceProfilerUploader, serviceProfilerExecutorService).initialize().get());
    // Wait up to 10 seconds
    for (int i = 0; i < 100; i++) {
        TelemetryObservers.INSTANCE.getObservers().forEach(telemetryObserver -> telemetryObserver.accept(metricTelemetry));
        synchronized (monitor) {
            if (serviceProfilerIndex.get() != null) {
                break;
            }
            monitor.wait(100);
        }
    }
    assertThat(profileInvoked.get()).isTrue();
    assertThat(serviceProfilerIndex.get()).isNotNull();
    assertThat(serviceProfilerIndex.get().getProperties().get("ArtifactKind")).isEqualTo("Profile");
    assertThat(serviceProfilerIndex.get().getProperties().get("EtlFileSessionId")).isEqualTo(timeStamp);
    assertThat(serviceProfilerIndex.get().getProperties().get("DataCube")).isEqualTo(appId);
    assertThat(serviceProfilerIndex.get().getProperties().get("Extension")).isEqualTo(jfrExtension);
    assertThat(serviceProfilerIndex.get().getProperties().get("MachineName")).isEqualTo(machineName);
    assertThat(serviceProfilerIndex.get().getProperties().get("ProcessId")).isEqualTo(processId);
    assertThat(serviceProfilerIndex.get().getProperties().get("StampId")).isEqualTo(stampId);
    assertTelemetry.accept(serviceProfilerIndex.get());
}
Also used : MonitorDomain(com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain) ServiceProfilerUploader(com.microsoft.applicationinsights.serviceprofilerapi.upload.ServiceProfilerUploader) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) AlertingSubsystem(com.microsoft.applicationinsights.alerting.AlertingSubsystem) URL(java.net.URL) JfrProfilerService(com.microsoft.applicationinsights.serviceprofilerapi.JfrProfilerService) ProfilerServiceFactory(com.microsoft.applicationinsights.profiler.ProfilerServiceFactory) ProfilerService(com.microsoft.applicationinsights.profiler.ProfilerService) JfrProfilerService(com.microsoft.applicationinsights.serviceprofilerapi.JfrProfilerService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) AtomicReference(java.util.concurrent.atomic.AtomicReference) JfrProfiler(com.microsoft.applicationinsights.serviceprofilerapi.profiler.JfrProfiler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ServiceProfilerServiceConfig(com.microsoft.applicationinsights.profiler.config.ServiceProfilerServiceConfig) ServiceProfilerClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2) TelemetryEventData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData)

Example 2 with ServiceProfilerUploader

use of com.microsoft.applicationinsights.serviceprofilerapi.upload.ServiceProfilerUploader 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)

Aggregations

ServiceProfilerClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2)2 JfrProfiler (com.microsoft.applicationinsights.serviceprofilerapi.profiler.JfrProfiler)2 ServiceProfilerUploader (com.microsoft.applicationinsights.serviceprofilerapi.upload.ServiceProfilerUploader)2 MonitorDomain (com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain)1 TelemetryEventData (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData)1 TelemetryItem (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)1 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)1 AlertingSubsystem (com.microsoft.applicationinsights.alerting.AlertingSubsystem)1 ProfilerService (com.microsoft.applicationinsights.profiler.ProfilerService)1 ProfilerServiceFactory (com.microsoft.applicationinsights.profiler.ProfilerServiceFactory)1 ServiceProfilerServiceConfig (com.microsoft.applicationinsights.profiler.config.ServiceProfilerServiceConfig)1 JfrProfilerService (com.microsoft.applicationinsights.serviceprofilerapi.JfrProfilerService)1 ProfilerFrontendClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ProfilerFrontendClientV2)1 URL (java.net.URL)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1