Elasticsearch Version
7.17.5 (since 6.6.0 but 8.x is not affected)
Installed Plugins
n/a
Java Version
bundled
OS Version
doesn't matter
Problem Description
The following example from documentation results in "met": true on 8.x but doesn't on 7.x
{
"condition" : {
"compare" : {
"ctx.execution_time" : {
"gte" : "<{now-5m}>"
}
}
}
}
Getting to the bottom, the following test case succeeds in master branch but fails in 7.17. branch.
https://github.com/sakurai-youhei/elasticsearch/blob/58d57bed48d31b1c9d842d70889003106477b9a4/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionTests.java#L191-L200
public void testExecuteDateMathExecutionContext() throws Exception {
ClockMock clock = ClockMock.frozen();
boolean met = true;
Op op = CompareCondition.Op.GTE;
String value = "<{now-5m}>";
CompareCondition condition = new CompareCondition("ctx.execution_time", op, value, clock);
WatchExecutionContext ctx = mockExecutionContext("_name", null);
assertThat(condition.execute(ctx).met(), is(met));
}
That's because LenientCompare.java doesn't expect org.elasticsearch.script.JodaCompatibleZonedDateTime of which ctx.execution_time is an instance in 7.x.
Steps to Reproduce
- Spin up a new Elasticsearch cluster.
- Start a trial by
curl -XPOST "http://localhost:9200/_license/start_trial?acknowledge=true" if needed.
- Run the following two commands with
watch.json file.
curl -XPUT "http://localhost:9200/_watcher/watch/test" -H "Content-Type: application/json" -d@watch.json
curl -XPOST "http://localhost:9200/_watcher/watch/test/_execute" | jq .watch_record.result.condition
watch.json
{
"trigger": {
"schedule": {
"interval": "10s"
}
},
"input": {
"simple": {}
},
"condition": {
"compare": {
"ctx.execution_time": {
"gte": "<{now-5m}>"
}
}
},
"actions": {}
}
Expected result:
"met": true because ctx.execution_time is almost the same as now.
Actual result:
"met": false like the below output.
{
"type": "compare",
"status": "success",
"met": false,
"compare": {
"resolved_values": {
"ctx.execution_time": "2022-07-07T10:10:01.869294555Z",
"now-5m": "2022-07-07T10:05:01.872Z"
}
}
}
Logs (if relevant)
No response
Elasticsearch Version
7.17.5 (since 6.6.0 but 8.x is not affected)
Installed Plugins
n/a
Java Version
bundled
OS Version
doesn't matter
Problem Description
The following example from documentation results in
"met": trueon 8.x but doesn't on 7.x{ "condition" : { "compare" : { "ctx.execution_time" : { "gte" : "<{now-5m}>" } } } }Getting to the bottom, the following test case succeeds in master branch but fails in 7.17. branch.
https://github.com/sakurai-youhei/elasticsearch/blob/58d57bed48d31b1c9d842d70889003106477b9a4/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionTests.java#L191-L200
That's because LenientCompare.java doesn't expect
org.elasticsearch.script.JodaCompatibleZonedDateTimeof whichctx.execution_timeis an instance in 7.x.Steps to Reproduce
curl -XPOST "http://localhost:9200/_license/start_trial?acknowledge=true"if needed.watch.jsonfile.watch.json
{ "trigger": { "schedule": { "interval": "10s" } }, "input": { "simple": {} }, "condition": { "compare": { "ctx.execution_time": { "gte": "<{now-5m}>" } } }, "actions": {} }Expected result:
"met": truebecausectx.execution_timeis almost the same asnow.Actual result:
"met": falselike the below output.{ "type": "compare", "status": "success", "met": false, "compare": { "resolved_values": { "ctx.execution_time": "2022-07-07T10:10:01.869294555Z", "now-5m": "2022-07-07T10:05:01.872Z" } } }Logs (if relevant)
No response