Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Watcher] Improved error messages for CronEvalTool #32800

Merged
merged 6 commits into from
Aug 23, 2018

Conversation

lipsill
Copy link
Contributor

@lipsill lipsill commented Aug 12, 2018

CronEvalTool prints an error only for cron expressions that result in
no coming time events.

If a cron expression results in less than the specified -count
(default 10) time events, the CronEvalTool prints all the coming
times and displays no error message.

Fixes #32735

CronEvalTool prints an error only for cron expressions that result in
no coming time events.

If a cron expression results in less than the specified `-count`
(default 10) time events, the CronEvalTool prints all the coming
times and displays no error message.

Fixes elastic#32735
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Contributor

@spinscale spinscale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a bunch for tackling this! I left some comments to simplify the code and make the tests more readable.

Would be awesome if you could take a further look, but I am happy to take over if you do not want to!

}
terminal.println((i == count ? "Here are the next " : "There are ") + i + " times this cron expression will trigger:");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this special handling here (introducing state that requires following by filling up the list). Just adding the additional if-statement plus break should be sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the change as originally the following results were printed by the cli tool:
0 0 0 1-6 * ? resulted in

Valid!
Now is [Wed, 15 Aug 2018 11:28:34]
Here are the next 10 times this cron expression will trigger:
1.	Sat, 1 Sep 2018 02:00:00
2.	Sun, 2 Sep 2018 02:00:00
3.	Mon, 3 Sep 2018 02:00:00
4.	Tue, 4 Sep 2018 02:00:00
5.	Wed, 5 Sep 2018 02:00:00
6.	Thu, 6 Sep 2018 02:00:00
7.	Mon, 1 Oct 2018 02:00:00
8.	Tue, 2 Oct 2018 02:00:00
9.	Wed, 3 Oct 2018 02:00:00
10.	Thu, 4 Oct 2018 02:00:00

And a one time cron, such as 0 3 23 8 9 ? 2019 resulted in

Valid!
Now is [Wed, 15 Aug 2018 11:29:37]
Here are the next 10 times this cron expression will trigger:
1.	Mon, 9 Sep 2019 01:03:00

I found it is a little bit confusing that in this case the message was Here are the next 10 time and only a single one was printed, hence I tried to clarify the message.

I will revert the change.

@@ -20,4 +24,28 @@ public void testParse() throws Exception {
String output = execute(countOption, Integer.toString(count), "0 0 0 1-6 * ?");
assertTrue(output, output.contains("Here are the next " + count + " times this cron expression will trigger"));
}

public void testGetNextValidTimes() throws Exception {
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for readability, just put final int year = ZonedDateTime.now(ZoneOffset.UTC).getYear() + 1; at the top of the test and use that one maybe?

{
String output = execute(
"0 3 23 8 9 ? " + (Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT).get(Calendar.YEAR) + 1));
assertTrue(output, output.contains("There are 1 times this cron expression will trigger:"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you replace assertTrue/assertFalse with

assertThat(output, containsString("FoObar"));
assertThat(output, not(containsString("ERROR")));

This way the assertion will return something helpful instead of just being true or false in order to ease debugging.

@spinscale spinscale self-assigned this Aug 14, 2018
@lipsill
Copy link
Contributor Author

lipsill commented Aug 15, 2018

@spinscale thanks for the feedback! I just pushed the changes. Can you have another look?

@spinscale
Copy link
Contributor

@elasticmachine test this please

Copy link
Contributor

@spinscale spinscale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left two super minor things I'd like to fix, but apart from that it's good. let's see what CI has to say!

import org.elasticsearch.xpack.core.scheduler.Cron;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.Arrays;
import java.util.List;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to keep the diff small, can you keep the imports as is?


public void testGetNextValidTimes() throws Exception {
{
final int nextYear = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT).get(Calendar.YEAR) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for readability, just put final int year = ZonedDateTime.now(ZoneOffset.UTC).getYear() + 1; at the top of the test and use that one maybe?

@lipsill
Copy link
Contributor Author

lipsill commented Aug 16, 2018

@spinscale I hope I addressed your latest comments.
Thanks for kicking a complete CI ;)

@spinscale
Copy link
Contributor

@elasticmachine test this please

@lipsill
Copy link
Contributor Author

lipsill commented Aug 16, 2018

Hm... the second CI run finished with an error that I cannot reproduce locally. I actually doubt that the test failure is caused by the changes in this PR.
@spinscale can you have a look when you have a chance? Thanks!

@spinscale
Copy link
Contributor

@elasticmachine retest this please

@spinscale
Copy link
Contributor

once CI passes, I'll merge this. Thanks a lot for helping!

@spinscale
Copy link
Contributor

@elasticmachine retest this please

@spinscale
Copy link
Contributor

may I ask you to merge the master branch into yours one more time, so we can trigger CI and see if it passes? Thanks a ton!

@lipsill
Copy link
Contributor Author

lipsill commented Aug 22, 2018

@spinscale done! Let's see if this helps ;)

@spinscale
Copy link
Contributor

@elasticmachine retest this please

@spinscale spinscale merged commit f84ed14 into elastic:master Aug 23, 2018
spinscale pushed a commit that referenced this pull request Aug 23, 2018
CronEvalTool prints an error only for cron expressions that result in
no upcoming time events.

If a cron expression results in less than the specified count
(default 10) time events, now all the coming times are printed
without displaying error message.

Closes #32735
@spinscale
Copy link
Contributor

thanks again, I have merged the PR into the master and 6.x branch

martijnvg added a commit that referenced this pull request Aug 24, 2018
* es/master: (62 commits)
  [DOCS] Add docs for Application Privileges (#32635)
  Add versions 5.6.12 and 6.4.1
  Do NOT allow termvectors on nested fields (#32728)
  [Rollup] Return empty response when aggs are missing (#32796)
  [TEST] Add some ACL yaml tests for Rollup (#33035)
  Move non duplicated actions back into xpack core (#32952)
  Test fix - GraphExploreResponseTests should not randomise array elements Closes #33086
  Use `addIfAbsent` instead of checking if an element is contained
  TESTS: Fix Random Fail in MockTcpTransportTests (#33061)
  HLRC: Fix Compile Error From Missing Throws (#33083)
  [DOCS] Remove reload password from docs cf. #32889
  HLRC: Add ML Get Buckets API (#33056)
  Watcher: Improve error messages for CronEvalTool (#32800)
  Search: Support of wildcard on docvalue_fields (#32980)
  Change query field expansion (#33020)
  INGEST: Cleanup Redundant Put Method (#33034)
  SQL: skip uppercasing/lowercasing function tests for AZ locales as well (#32910)
  Fix the default pom file name (#33063)
  Switch ml basic tests to new style Requests (#32483)
  Switch some watcher tests to new style Requests (#33044)
  ...
martijnvg added a commit that referenced this pull request Aug 24, 2018
* es/6.x: (58 commits)
  [DOCS] Add docs for Application Privileges (#32635)
  Add versions 5.6.12 and 6.4.1
  [Rollup] Return empty response when aggs are missing (#32796)
  [TEST] Add some ACL yaml tests for Rollup (#33035)
  Test fix - GraphExploreResponseTests should not randomise array elements Closes #33086
  Use `addIfAbsent` instead of checking if an element is contained
  HLRC: Fix Compile Error From Missing Throws (#33083)
  [DOCS] Remove reload password from docs cf. #32889
  Use a dedicated ConnectionManger for RemoteClusterConnection (#32988)
  Watcher: Improve error messages for CronEvalTool (#32800)
  HLRC: Add ML Get Buckets API (#33056)
  Change query field expansion (#33020)
  Search: Support of wildcard on docvalue_fields (#32980)
  Add beta label to MSI on install Elasticsearch page (#28126)
  SQL: skip uppercasing/lowercasing function tests for AZ locales as well (#32910)
  [DOCS] Drafts Elasticsearch 6.4.0 release notes (#33039)
  Fix the default pom file name (#33063)
  Fix backport of switch ml basic tests to new style Requests (#32483)
  Switch ml basic tests to new style Requests (#32483)
  Switch some watcher tests to new style Requests (#33044)
  ...
@lipsill
Copy link
Contributor Author

lipsill commented Aug 28, 2018

Thanks @spinscale :)

@lipsill lipsill deleted the CronEvalTool_errorMsg branch October 24, 2018 11:41
@jimczi jimczi added v7.0.0-beta1 and removed v7.0.0 labels Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants