Fix alert history entry parsing
This commit fixes the alert history parsing that was causing the tests to fail. It now just warns on null fields and sets the search request on alert history entry creation. Original commit: elastic/x-pack-elasticsearch@09d2b09b79
This commit is contained in:
parent
71d9feb9d0
commit
2954f5f9c2
|
@ -134,7 +134,6 @@ public class AlertManager extends AbstractComponent {
|
|||
throw new ElasticsearchException("Alert is not available");
|
||||
}
|
||||
TriggerResult triggerResult = triggerManager.isTriggered(alert, entry.getScheduledTime(), entry.getFireTime());
|
||||
entry.setSearchRequest(triggerResult.getRequest());
|
||||
entry.setSearchResponse(triggerResult.getResponse());
|
||||
if (triggerResult.isTriggered()) {
|
||||
entry.setTriggered(true);
|
||||
|
|
|
@ -31,9 +31,9 @@ public class AlertActionEntry implements ToXContent {
|
|||
private AlertTrigger trigger;
|
||||
private List<AlertAction> actions;
|
||||
private AlertActionState entryState;
|
||||
private SearchRequest searchRequest;
|
||||
|
||||
/*Optional*/
|
||||
private SearchRequest searchRequest;
|
||||
private Map<String, Object> searchResponse;
|
||||
private boolean triggered;
|
||||
private String errorMsg;
|
||||
|
@ -50,6 +50,7 @@ public class AlertActionEntry implements ToXContent {
|
|||
this.trigger = alert.trigger();
|
||||
this.actions = alert.actions();
|
||||
this.entryState = state;
|
||||
this.searchRequest = alert.getSearchRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,7 +189,10 @@ public class AlertActionEntry implements ToXContent {
|
|||
historyEntry.field("triggered", triggered);
|
||||
historyEntry.field("fire_time", fireTime.toDateTimeISO());
|
||||
historyEntry.field(AlertActionManager.SCHEDULED_FIRE_TIME_FIELD, scheduledTime.toDateTimeISO());
|
||||
historyEntry.field("trigger", trigger, params);
|
||||
historyEntry.field("trigger");
|
||||
historyEntry.startObject();
|
||||
historyEntry.field(trigger.getTriggerName(), trigger, params);
|
||||
historyEntry.endObject();
|
||||
historyEntry.field("request");
|
||||
AlertUtils.writeSearchRequest(searchRequest, historyEntry, params);
|
||||
historyEntry.field("response", searchResponse);
|
||||
|
|
|
@ -196,6 +196,7 @@ public class AlertActionManager extends AbstractComponent {
|
|||
String currentFieldName = null;
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
assert token == XContentParser.Token.START_OBJECT;
|
||||
logger.error("source [{}]",source.toUtf8());
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
|
@ -240,7 +241,11 @@ public class AlertActionManager extends AbstractComponent {
|
|||
throw new ElasticsearchIllegalArgumentException("Unexpected field [" + currentFieldName + "]");
|
||||
}
|
||||
} else {
|
||||
throw new ElasticsearchIllegalArgumentException("Unexpected token [" + token + "]");
|
||||
if (token == XContentParser.Token.VALUE_NULL) {
|
||||
logger.warn("Got null value for [{}]", currentFieldName);
|
||||
} else {
|
||||
throw new ElasticsearchIllegalArgumentException("Unexpected token [" + token + "] for [" + currentFieldName + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Reference in New Issue