Fix DateTime issues

We were using DateTime without a timezone to pick the history index to write the alert runs to.
This caused tests to fail because we use UTC internally (as we should)

Original commit: elastic/x-pack-elasticsearch@6d6f57fb9e
This commit is contained in:
Brian Murphy 2015-02-13 17:07:46 -08:00
parent ba15a197ea
commit 8b83d74994
2 changed files with 12 additions and 7 deletions

View File

@ -23,6 +23,8 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
*/
@ -66,9 +68,13 @@ public class IndexAction extends Action<IndexAction.Result> {
try {
IndexResponse response = client.index(indexRequest).actionGet();
//@TODO this doesn't seem to work for index response
//return new Result(new Payload.Simple(responseToData(response)), null, true);
return new Result(new Payload.Simple(), null, response.isCreated());
Map<String,Object> data = new HashMap<>();
data.put("created", response.isCreated());
data.put("id", response.getId());
data.put("version", response.getVersion());
data.put("type", response.getType());
data.put("index", response.getIndex());
return new Result(new Payload.Simple(data), null, response.isCreated());
} catch (ElasticsearchException e) {
logger.error("failed to index result for alert [{}]", e, ctx.alert().name());
return new Result(null, "failed to build index request. " + e.getMessage(), false);

View File

@ -22,11 +22,11 @@ import org.elasticsearch.alerts.transport.actions.stats.AlertsStatsResponse;
import org.elasticsearch.alerts.trigger.search.ScriptSearchTrigger;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.joda.time.DateTime;
import org.elasticsearch.common.joda.time.DateTimeZone;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.test.junit.annotations.TestLogging;
@ -87,7 +87,7 @@ public class BootStrapTest extends AbstractAlertingTests {
new Alert.Status()
);
DateTime scheduledFireTime = new DateTime();
DateTime scheduledFireTime = new DateTime(DateTimeZone.UTC);
FiredAlert entry = new FiredAlert(alert, scheduledFireTime, scheduledFireTime, FiredAlert.State.AWAITS_RUN);
String actionHistoryIndex = HistoryStore.getAlertHistoryIndexNameForTime(scheduledFireTime);
@ -114,7 +114,7 @@ public class BootStrapTest extends AbstractAlertingTests {
@Test
@TestLogging("alerts.actions:DEBUG")
public void testBootStrapManyHistoryIndices() throws Exception {
DateTime now = new DateTime();
DateTime now = new DateTime(DateTimeZone.UTC);
long numberOfAlertHistoryIndices = randomIntBetween(2,8);
long numberOfAlertHistoryEntriesPerIndex = randomIntBetween(5,10);
SearchRequest searchRequest = createTriggerSearchRequest("my-index").source(searchSource().query(termQuery("field", "value")));
@ -149,7 +149,6 @@ public class BootStrapTest extends AbstractAlertingTests {
IndexResponse indexResponse = client().prepareIndex(actionHistoryIndex, HistoryStore.ALERT_HISTORY_TYPE, entry.id())
.setConsistencyLevel(WriteConsistencyLevel.ALL)
.setSource(XContentFactory.jsonBuilder().value(entry))
.setVersionType(VersionType.INTERNAL)
.get();
assertTrue(indexResponse.isCreated());
}