Search in sources :

Example 1 with AlertConfiguration

use of com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertTriggerTest method doesNotReTriggerAfterCooldown.

@Test
void doesNotReTriggerAfterCooldown() throws InterruptedException {
    AlertConfiguration config = new AlertConfiguration(AlertMetricType.CPU, true, 0.5f, 1, 1);
    AtomicBoolean called = new AtomicBoolean(false);
    AlertPipelineTrigger trigger = getAlertTrigger(config, called);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isTrue();
    called.set(false);
    Thread.sleep(2000);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.1);
    }
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AlertPipelineTrigger(com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with AlertConfiguration

use of com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertTriggerTest method overThresholdDataDoesTrigger.

@Test
void overThresholdDataDoesTrigger() {
    AlertConfiguration config = new AlertConfiguration(AlertMetricType.CPU, true, 0.5f, 1, 1);
    AtomicBoolean called = new AtomicBoolean(false);
    AlertPipelineTrigger trigger = getAlertTrigger(config, called);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AlertPipelineTrigger(com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with AlertConfiguration

use of com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertingSubsystemTest method manualAlertDoesNotTriggerAfterExpired.

@Test
void manualAlertDoesNotTriggerAfterExpired() {
    AtomicReference<AlertBreach> called = new AtomicReference<>();
    Consumer<AlertBreach> consumer = called::set;
    AlertingSubsystem service = AlertingSubsystem.create(consumer, Executors.newSingleThreadExecutor());
    service.updateConfiguration(new AlertingConfiguration(new AlertConfiguration(AlertMetricType.CPU, true, 80, 30, 14400), new AlertConfiguration(AlertMetricType.MEMORY, true, 20, 120, 14400), new DefaultConfiguration(true, 5, 120), new CollectionPlanConfiguration(true, EngineMode.immediate, ZonedDateTime.now().minus(100, ChronoUnit.SECONDS), 120, "a-settings-moniker")));
    assertThat(called.get()).isNull();
}
Also used : AlertBreach(com.microsoft.applicationinsights.alerting.alert.AlertBreach) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultConfiguration(com.microsoft.applicationinsights.alerting.config.DefaultConfiguration) CollectionPlanConfiguration(com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) AlertingConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with AlertConfiguration

use of com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertingSubsystemTest method getAlertMonitor.

private static AlertingSubsystem getAlertMonitor(Consumer<AlertBreach> consumer) {
    AlertingSubsystem monitor = AlertingSubsystem.create(consumer, Executors.newSingleThreadExecutor());
    monitor.updateConfiguration(new AlertingConfiguration(new AlertConfiguration(AlertMetricType.CPU, true, 80, 30, 14400), new AlertConfiguration(AlertMetricType.MEMORY, true, 20, 120, 14400), new DefaultConfiguration(true, 5, 120), new CollectionPlanConfiguration(true, EngineMode.immediate, ZonedDateTime.now(), 120, "a-settings-moniker")));
    return monitor;
}
Also used : DefaultConfiguration(com.microsoft.applicationinsights.alerting.config.DefaultConfiguration) CollectionPlanConfiguration(com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) AlertingConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration)

Example 5 with AlertConfiguration

use of com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertingSubsystem method updateConfiguration.

/**
 * Apply given configuration to the alerting pipelines.
 */
public void updateConfiguration(AlertingConfiguration alertingConfig) {
    if (this.alertConfig == null || !this.alertConfig.equals(alertingConfig)) {
        AlertConfiguration oldCpuConfig = this.alertConfig == null ? null : this.alertConfig.getCpuAlert();
        updatePipelineConfig(alertingConfig.getCpuAlert(), oldCpuConfig);
        AlertConfiguration oldMemoryConfig = this.alertConfig == null ? null : this.alertConfig.getMemoryAlert();
        updatePipelineConfig(alertingConfig.getMemoryAlert(), oldMemoryConfig);
        evaluateManualTrigger(alertingConfig);
        this.alertConfig = alertingConfig;
    }
}
Also used : AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration)

Aggregations

AlertConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration)11 Test (org.junit.jupiter.api.Test)7 AlertingConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration)6 CollectionPlanConfiguration (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration)6 DefaultConfiguration (com.microsoft.applicationinsights.alerting.config.DefaultConfiguration)6 AlertPipelineTrigger (com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AlertBreach (com.microsoft.applicationinsights.alerting.alert.AlertBreach)2 AlertMetricType (com.microsoft.applicationinsights.alerting.config.AlertMetricType)2 AlertConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder)2 EngineMode (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration.EngineMode)2 CollectionPlanConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfigurationBuilder)2 DefaultConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.DefaultConfigurationBuilder)2 ProfilerConfiguration (com.microsoft.applicationinsights.profiler.ProfilerConfiguration)2 Instant (java.time.Instant)2 ZoneOffset (java.time.ZoneOffset)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2