-
Notifications
You must be signed in to change notification settings - Fork 295
Fixes #1113: removes fixed max-failure value from task creation #1120
Conversation
Not sure why the default for a setting in Scheduler for a task is being defined in the REST server. |
@geauxvirtual; I really don't care where we define it, as long as we define it once (rather than having it defined three times in three separate packages with two distinctly different values); do you have a preference as to which should be the package it's defined in and which should pull their values from that package? |
0ffcdbe
to
6a356ab
Compare
Honestly, Scheduler should be the only package that needs to know that value and set that value for a task if no value is passed. If a value needs to be passed to create a task, then the REST server or any other package that creates a task should either pass a value for a task or pass something like (-1) to signal the scheduler to use the default value if no value was passed to the API, for example. |
@geauxvirtual; after looking at the test failures I was seeing under TravisCI, I decided there was more than one reason to move the definition of that parameter out of the |
Neither REST or snapctl should need to import the scheduler package for a single constant. They shouldn't have to worry about passing the default constant to scheduler that already knows what the default value is. These packages should either pass a value that a user passed in, or pass a value that signals scheduler to use the default. |
6a356ab
to
d8f8d66
Compare
Yep; had just hit "submit" on my previous comment as yours was appearing in my browser window, @geauxvirtual; this PR is now setup so that the default can be selected by passing a value of |
@@ -129,7 +125,7 @@ var ( | |||
flTaskMaxFailures = cli.IntFlag{ | |||
Name: "max-failures", | |||
Usage: "The number of consecutive failures before snap disable the task (Default 10 consective failures)", | |||
Value: DefaultMaxFailures, | |||
Value: -1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to pass -1, then the usage text could become incorrect if the default changes from 10 consecutive failures to something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably document this somewhere, @IRCody, but from what I understand using a value of -1
is quite common if you want the default value for something to be used. In this case, the default value is 10
, and the default value (-1
) in snapctl
will ensure that the underlying default value from the scheduler package is used (which happens to be 10
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing -1 isn't an issue. Passing -1, while telling the user that the default value is going to be 10 but then not guaranteeing that seems off. Since snapctl does not control the default value I feel like giving a specific value here without enforcing it could potentially mislead the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point...I'll remove the reference to the default value from the CLI usage...Cheers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR has been updated, @IRCody; here's the new help output for creating tasks:
$ snapctl task create --help
NAME:
snapctl task create - There are two ways to create a task.
1) Use a task manifest with [--task-manifest]
2) Provide a workflow manifest and schedule details.
* Note: Start and stop date/time are optional.
USAGE:
snapctl task create [command options] [arguments...]
DESCRIPTION:
Creates a new task in the snap scheduler
OPTIONS:
--task-manifest value, -t value File path for task manifest to use for task creation.
--workflow-manifest value, -w value File path for workflow manifest to use for task creation
--interval value, -i value Interval for the task schedule [ex (simple schedule): 250ms, 1s, 30m (cron schedule): "0 * * * * *"]
--start-date value Start date for the task schedule [defaults to today]
--start-time value Start time for the task schedule [defaults to now]
--stop-date value Stop date for the task schedule [defaults to today]
--stop-time value Start time for the task schedule [defaults to now]
--name value, -n value Optional requirement for giving task names
--duration value, -d value The amount of time to run the task [appends to start or creates a start time before a stop]
--no-start Do not start task on creation [normally started on creation]
--deadline value The deadline for the task to be killed after started if the task runs too long (All tasks default to 5s)
--max-failures value The number of consecutive failures before snap disable the task (default: -1)
$
Note that the reference to that default value has been removed. Hopefully that addresses your concern here.
d8f8d66
to
0c33039
Compare
LGTM |
fd49f24
to
79814ab
Compare
This PR is now doing more than resolving issue #1113. Any enhancements to snapctl should be added via another PR. |
PR #1127 replaces this PR; closing this PR now. |
Fixes #1113
Summary of changes:
core/task.go
file that used to set themax-failure
value to10
for all tasks; now it sets the value to whatever was received in the task creation request insteadcmd/snapctl/flags.go
andscheduler/task.go
files so that they used a single parameter (theDefaultMaxFailures
constant from themgmt/rest
package) to set the default value they use for the number of times a task can fail before it is disabled; previously this parameter was set with separate fixed values in these two files and those fixed values did not match (the default was set to3
in thescheduler/task.go
file and to10
in thecmd/snapctl/flags.go
file)Testing done:
snapd
eg-file.yaml
task configuration from the Snap distribution; in the copy being used for this part of the test, themax-failures
value in the task configuration was set to3
snapd
max-failures
value unspecified in the task configuration file that was used and verified that the task was disabled after 10 consecutive failures (the default value for this parameter once this PR has been applied)max-failures
value set to-1
and verified that the task was once again disabled after 10 consecutive failures (the default value for this parameter)see the command-line output, below, for details; here's the head of the three YAML files used in the testing (to show the differences in the
max-failure
parameter value defined in each):next, we started up
snapd
in a separate window:once
snapd
was up and running, created a task that should be disabled after three concurrent failures, then unloaded the two versions of the collector plugin that the task depends on (so that the task would fail); once the task had been disabled, went back and counted the number of times it failed beforesnapd
disabled that task by grep'ing for the line denoting the task failure in the log output of thesnapd
instance (thet.t
file):next, restarted
snapd
(using the samesnapd
command shown above) and once it was up and running again re-ran the test, this time using the task configuration file that doesn't specify a value for themax-failures
parameter:and finally, restarted
snapd
and once it was up and running again ran the test for the task configuration file that specifies a value of-1
for themax-failures
parameter:As you can see, in the first case we saw three lines in the log output indicating that the task had failed before the task was disabled, while for the last two tests we saw ten lines in the log output, showing that the default value is used for the latter two and for any value greater than zero (
3
in this case) the number of consecutive failures before the task is disabled is set using the specifiedmax-failure
value.@intelsdi-x/snap-maintainers