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