Search in sources :

Example 1 with ProfilerConfiguration

use of com.microsoft.applicationinsights.profiler.ProfilerConfiguration in project ApplicationInsights-Java by microsoft.

the class ServiceProfilerConfigMonitorServiceTest method pullsConfig.

@Test
void pullsConfig() throws IOException, URISyntaxException {
    AtomicReference<Runnable> job = new AtomicReference<>();
    ScheduledExecutorService executorService = mockScheduledExecutorService(job::set);
    ServiceProfilerClientV2 serviceProfilerClient = mockServiceProfilerClient();
    ServiceProfilerConfigMonitorService serviceMonitor = new ServiceProfilerConfigMonitorService(executorService, 100, serviceProfilerClient);
    AtomicReference<ProfilerConfiguration> config = new AtomicReference<>();
    serviceMonitor.initialize(Collections.singletonList(config::set));
    assertThat(job.get()).isNotNull();
    job.get().run();
    Mockito.verify(serviceProfilerClient, times(1)).getSettings(any(Date.class));
    assertThat(config.get()).isNotNull();
    assertThat(config.get().getCollectionPlan()).isEqualTo("--single --mode immediate --immediate-profiling-duration 120  --expiration 5249157885138288517 --settings-moniker a-settings-moniker");
    assertThat(config.get().getCpuTriggerConfiguration()).isEqualTo("--cpu-trigger-enabled true --cpu-threshold 80 --cpu-trigger-profilingDuration 30 --cpu-trigger-cooldown 14400");
    assertThat(config.get().getDefaultConfiguration()).isEqualTo("--sampling-enabled true --sampling-rate 5 --sampling-profiling-duration 120");
    assertThat(config.get().getMemoryTriggerConfiguration()).isEqualTo("--memory-trigger-enabled true --memory-threshold 20 --memory-trigger-profilingDuration 120 --memory-trigger-cooldown 14400");
}
Also used : ServiceProfilerConfigMonitorService(com.microsoft.applicationinsights.serviceprofilerapi.config.ServiceProfilerConfigMonitorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServiceProfilerClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2) ProfilerConfiguration(com.microsoft.applicationinsights.profiler.ProfilerConfiguration) AtomicReference(java.util.concurrent.atomic.AtomicReference) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 2 with ProfilerConfiguration

use of com.microsoft.applicationinsights.profiler.ProfilerConfiguration in project ApplicationInsights-Java by microsoft.

the class ServiceProfilerSettingsClientTest method badServiceResponseDoesNotProvideReturn.

@Test
void badServiceResponseDoesNotProvideReturn() throws IOException, URISyntaxException {
    ServiceProfilerClientV2 serviceProfilerClient = Mockito.mock(ServiceProfilerClientV2.class);
    Mockito.when(serviceProfilerClient.getSettings(Mockito.any())).thenReturn(Mono.just(""));
    ServiceProfilerSettingsClient settingsClient = new ServiceProfilerSettingsClient(serviceProfilerClient);
    Mono<ProfilerConfiguration> result = settingsClient.pullSettings();
    assertThatThrownBy(result::block).isInstanceOf(Exception.class);
}
Also used : ServiceProfilerClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2) ProfilerConfiguration(com.microsoft.applicationinsights.profiler.ProfilerConfiguration) ServiceProfilerSettingsClient(com.microsoft.applicationinsights.serviceprofilerapi.config.ServiceProfilerSettingsClient) Test(org.junit.jupiter.api.Test)

Example 3 with ProfilerConfiguration

use of com.microsoft.applicationinsights.profiler.ProfilerConfiguration in project ApplicationInsights-Java by microsoft.

the class ServiceProfilerSettingsClient method toServiceProfilerConfiguration.

private static ProfilerConfiguration toServiceProfilerConfiguration(String config) throws IOException {
    Moshi moshi = new Moshi.Builder().add(Date.class, new Rfc3339DateJsonAdapter()).build();
    JsonAdapter<ProfilerConfiguration> jsonAdapter = moshi.adapter(ProfilerConfiguration.class);
    return jsonAdapter.fromJson(config);
}
Also used : Moshi(com.squareup.moshi.Moshi) ProfilerConfiguration(com.microsoft.applicationinsights.profiler.ProfilerConfiguration) Rfc3339DateJsonAdapter(com.squareup.moshi.adapters.Rfc3339DateJsonAdapter) Date(java.util.Date)

Aggregations

ProfilerConfiguration (com.microsoft.applicationinsights.profiler.ProfilerConfiguration)3 ServiceProfilerClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2)2 Date (java.util.Date)2 Test (org.junit.jupiter.api.Test)2 ServiceProfilerConfigMonitorService (com.microsoft.applicationinsights.serviceprofilerapi.config.ServiceProfilerConfigMonitorService)1 ServiceProfilerSettingsClient (com.microsoft.applicationinsights.serviceprofilerapi.config.ServiceProfilerSettingsClient)1 Moshi (com.squareup.moshi.Moshi)1 Rfc3339DateJsonAdapter (com.squareup.moshi.adapters.Rfc3339DateJsonAdapter)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1