removed compound throttler in favour of an alert throttler
We don't really need a generic compound throttler. Instead we now have an `AlertThrottler` that can be configured with optional `AckThrottler` and `PeriodThrottler`. The logic of what throttler is applied first has therefore moved from the `Alert` to the `AlertThrottler` (back to its natural place) Original commit: elastic/x-pack-elasticsearch@b81e467c97
This commit is contained in:
parent
7d9d0aae05
commit
af7cf03a1c
|
@ -12,7 +12,7 @@ import org.elasticsearch.alerts.payload.PayloadRegistry;
|
||||||
import org.elasticsearch.alerts.scheduler.schedule.Schedule;
|
import org.elasticsearch.alerts.scheduler.schedule.Schedule;
|
||||||
import org.elasticsearch.alerts.scheduler.schedule.ScheduleRegistry;
|
import org.elasticsearch.alerts.scheduler.schedule.ScheduleRegistry;
|
||||||
import org.elasticsearch.alerts.throttle.AckThrottler;
|
import org.elasticsearch.alerts.throttle.AckThrottler;
|
||||||
import org.elasticsearch.alerts.throttle.CompoundThrottler;
|
import org.elasticsearch.alerts.throttle.AlertThrottler;
|
||||||
import org.elasticsearch.alerts.throttle.PeriodThrottler;
|
import org.elasticsearch.alerts.throttle.PeriodThrottler;
|
||||||
import org.elasticsearch.alerts.throttle.Throttler;
|
import org.elasticsearch.alerts.throttle.Throttler;
|
||||||
import org.elasticsearch.alerts.trigger.Trigger;
|
import org.elasticsearch.alerts.trigger.Trigger;
|
||||||
|
@ -65,14 +65,9 @@ public class Alert implements ToXContent {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
this.payload = payload != null ? payload : Payload.NOOP;
|
this.payload = payload != null ? payload : Payload.NOOP;
|
||||||
|
|
||||||
CompoundThrottler.Builder builder = CompoundThrottler.builder();
|
PeriodThrottler periodThrottler = throttlePeriod != null ? new PeriodThrottler(throttlePeriod) : null;
|
||||||
if (ackable) {
|
AckThrottler ackThrottler = ackable ? new AckThrottler() : null;
|
||||||
builder.add(new AckThrottler());
|
throttler = new AlertThrottler(periodThrottler, ackThrottler);
|
||||||
}
|
|
||||||
if (throttlePeriod != null) {
|
|
||||||
builder.add(new PeriodThrottler(throttlePeriod));
|
|
||||||
}
|
|
||||||
throttler = builder.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String name() {
|
public String name() {
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
|
*/
|
||||||
|
package org.elasticsearch.alerts.throttle;
|
||||||
|
|
||||||
|
import org.elasticsearch.alerts.Alert;
|
||||||
|
import org.elasticsearch.alerts.trigger.Trigger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AlertThrottler implements Throttler {
|
||||||
|
|
||||||
|
private final PeriodThrottler periodThrottler;
|
||||||
|
private final AckThrottler ackThrottler;
|
||||||
|
|
||||||
|
public AlertThrottler(PeriodThrottler periodThrottler, AckThrottler ackThrottler) {
|
||||||
|
this.periodThrottler = periodThrottler;
|
||||||
|
this.ackThrottler = ackThrottler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result throttle(Alert alert, Trigger.Result result) {
|
||||||
|
Result throttleResult = Result.NO;
|
||||||
|
if (periodThrottler != null) {
|
||||||
|
throttleResult = periodThrottler.throttle(alert, result);
|
||||||
|
if (throttleResult.throttle()) {
|
||||||
|
return throttleResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ackThrottler != null) {
|
||||||
|
throttleResult = ackThrottler.throttle(alert, result);
|
||||||
|
if (throttleResult.throttle()) {
|
||||||
|
return throttleResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return throttleResult;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,57 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
||||||
* or more contributor license agreements. Licensed under the Elastic License;
|
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
|
||||||
*/
|
|
||||||
package org.elasticsearch.alerts.throttle;
|
|
||||||
|
|
||||||
import org.elasticsearch.alerts.Alert;
|
|
||||||
import org.elasticsearch.alerts.trigger.Trigger;
|
|
||||||
import org.elasticsearch.common.collect.ImmutableList;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class CompoundThrottler implements Throttler {
|
|
||||||
|
|
||||||
private final List<Throttler> throttlers;
|
|
||||||
|
|
||||||
public CompoundThrottler(List<Throttler> throttlers) {
|
|
||||||
this.throttlers = throttlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result throttle(Alert alert, Trigger.Result result) {
|
|
||||||
for (Throttler throttler : throttlers) {
|
|
||||||
Result rslt = throttler.throttle(alert, result);
|
|
||||||
if (rslt.throttle()) {
|
|
||||||
return rslt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Result.NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
private final ImmutableList.Builder<Throttler> throttlers = ImmutableList.builder();
|
|
||||||
|
|
||||||
private Builder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder add(Throttler throttler) {
|
|
||||||
throttlers.add(throttler);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Throttler build() {
|
|
||||||
ImmutableList<Throttler> list = throttlers.build();
|
|
||||||
return list.isEmpty() ? Throttler.NO_THROTTLE : new CompoundThrottler(list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue