[throttler] changed the Throttler interface
Removed the passed in `Condition.Result` from the `apply` method Original commit: elastic/x-pack-elasticsearch@23101b028d
This commit is contained in:
parent
b292051a13
commit
6fdd6d49e2
|
@ -256,13 +256,12 @@ public class HistoryService extends AbstractComponent {
|
|||
ctx.onConditionResult(conditionResult);
|
||||
|
||||
if (conditionResult.met()) {
|
||||
Throttler.Result throttleResult = alert.throttler().throttle(ctx, conditionResult);
|
||||
Throttler.Result throttleResult = alert.throttler().throttle(ctx);
|
||||
ctx.onThrottleResult(throttleResult);
|
||||
|
||||
if (!throttleResult.throttle()) {
|
||||
Transform.Result result = alert.transform().apply(ctx, conditionResult.payload());
|
||||
ctx.onTransformResult(result);
|
||||
|
||||
for (Action action : alert.actions()) {
|
||||
Action.Result actionResult = action.execute(ctx, result.payload());
|
||||
ctx.onActionResult(actionResult);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.elasticsearch.alerts.throttle;
|
||||
|
||||
import org.elasticsearch.alerts.ExecutionContext;
|
||||
import org.elasticsearch.alerts.condition.Condition;
|
||||
|
||||
import static org.elasticsearch.alerts.support.AlertsDateUtils.formatDate;
|
||||
|
||||
|
@ -16,7 +15,7 @@ import static org.elasticsearch.alerts.support.AlertsDateUtils.formatDate;
|
|||
public class AckThrottler implements Throttler {
|
||||
|
||||
@Override
|
||||
public Result throttle(ExecutionContext ctx, Condition.Result result) {
|
||||
public Result throttle(ExecutionContext ctx) {
|
||||
if (ctx.alert().acked()) {
|
||||
return Result.throttle("alert [" + ctx.alert().name() + "] was acked at [" + formatDate(ctx.alert().status().ackStatus().timestamp()) + "]");
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.elasticsearch.alerts.throttle;
|
||||
|
||||
import org.elasticsearch.alerts.ExecutionContext;
|
||||
import org.elasticsearch.alerts.condition.Condition;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
||||
|
@ -18,19 +17,25 @@ public class AlertThrottler implements Throttler {
|
|||
private static final AckThrottler ACK_THROTTLER = new AckThrottler();
|
||||
|
||||
private final PeriodThrottler periodThrottler;
|
||||
private final AckThrottler ackThrottler;
|
||||
|
||||
public AlertThrottler(@Nullable TimeValue throttlePeriod) {
|
||||
this.periodThrottler = throttlePeriod != null ? new PeriodThrottler(throttlePeriod) : null;
|
||||
this(throttlePeriod != null ? new PeriodThrottler(throttlePeriod) : null, ACK_THROTTLER);
|
||||
}
|
||||
|
||||
AlertThrottler(PeriodThrottler periodThrottler, AckThrottler ackThrottler) {
|
||||
this.periodThrottler = periodThrottler;
|
||||
this.ackThrottler = ackThrottler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result throttle(ExecutionContext ctx, Condition.Result result) {
|
||||
public Result throttle(ExecutionContext ctx) {
|
||||
if (periodThrottler != null) {
|
||||
Result throttleResult = periodThrottler.throttle(ctx, result);
|
||||
Result throttleResult = periodThrottler.throttle(ctx);
|
||||
if (throttleResult.throttle()) {
|
||||
return throttleResult;
|
||||
}
|
||||
}
|
||||
return ACK_THROTTLER.throttle(ctx, result);
|
||||
return ackThrottler.throttle(ctx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package org.elasticsearch.alerts.throttle;
|
|||
|
||||
import org.elasticsearch.alerts.Alert;
|
||||
import org.elasticsearch.alerts.ExecutionContext;
|
||||
import org.elasticsearch.alerts.condition.Condition;
|
||||
import org.elasticsearch.common.joda.time.PeriodType;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
||||
|
@ -33,7 +32,7 @@ public class PeriodThrottler implements Throttler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result throttle(ExecutionContext ctx, Condition.Result result) {
|
||||
public Result throttle(ExecutionContext ctx) {
|
||||
Alert.Status status = ctx.alert().status();
|
||||
if (status.lastExecuted() != null) {
|
||||
TimeValue timeElapsed = new TimeValue(System.currentTimeMillis() - status.lastExecuted().getMillis());
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
package org.elasticsearch.alerts.throttle;
|
||||
|
||||
import org.elasticsearch.alerts.ExecutionContext;
|
||||
import org.elasticsearch.alerts.condition.Condition;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -16,18 +14,15 @@ public interface Throttler {
|
|||
|
||||
public static final Throttler NO_THROTTLE = new Throttler() {
|
||||
@Override
|
||||
public Result throttle(ExecutionContext ctx, Condition.Result result) {
|
||||
public Result throttle(ExecutionContext ctx) {
|
||||
return Result.NO;
|
||||
}
|
||||
};
|
||||
|
||||
Result throttle(ExecutionContext ctx, Condition.Result result);
|
||||
Result throttle(ExecutionContext ctx);
|
||||
|
||||
static class Result {
|
||||
|
||||
public static ParseField THROTTLE_FIELD = new ParseField("throttle");
|
||||
public static ParseField REASON_FIELD = new ParseField("reason");
|
||||
|
||||
public static final Result NO = new Result(false, null);
|
||||
|
||||
private final boolean throttle;
|
||||
|
|
|
@ -48,7 +48,7 @@ public class FiredAlertTest extends AbstractAlertingTests {
|
|||
ctx.onActionResult(new EmailAction.Result.Failure("failed to send because blah"));
|
||||
ctx.onActionResult(new WebhookAction.Result.Executed(300, "http://localhost:8000/alertfoo", "{'awesome' : 'us'}"));
|
||||
Condition.Result conditionResult = new SimpleCondition.Result(new Payload.Simple());
|
||||
ctx.onThrottleResult(Throttler.NO_THROTTLE.throttle(ctx, conditionResult));
|
||||
ctx.onThrottleResult(Throttler.NO_THROTTLE.throttle(ctx));
|
||||
ctx.onConditionResult(conditionResult);
|
||||
firedAlert.update(new AlertExecution(ctx));
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class FiredAlertTest extends AbstractAlertingTests {
|
|||
ctx.onActionResult(new EmailAction.Result.Failure("failed to send because blah"));
|
||||
ctx.onActionResult(new WebhookAction.Result.Executed(300, "http://localhost:8000/alertfoo", "{'awesome' : 'us'}"));
|
||||
Condition.Result conditionResult = new SearchCondition.Result(ScriptSearchCondition.TYPE, true, createConditionSearchRequest(), new Payload.Simple());
|
||||
ctx.onThrottleResult(Throttler.NO_THROTTLE.throttle(ctx, conditionResult));
|
||||
ctx.onThrottleResult(Throttler.NO_THROTTLE.throttle(ctx));
|
||||
ctx.onConditionResult(conditionResult);
|
||||
firedAlert.update(new AlertExecution(ctx));
|
||||
|
||||
|
|
Loading…
Reference in New Issue