-
Notifications
You must be signed in to change notification settings - Fork 11
Change ValidateConfiguration to throw ConfigurationValidationError on invalid configs. #134
Conversation
…igs. Return false to stop or true to proceed.
bmoyles0117
left a comment
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.
General takeaway is that we should split this into two separate PRs. One to handle the transient errors in config validation, and a subsequent PR to change the signature for config validation, while adding a new method that determines whether or not the user intends to use a specific updater.
src/docker.cc
Outdated
| } catch (const QueryException& e) { | ||
| // Already logged. | ||
| return false; | ||
| bool DockerReader::ValidateConfiguration() const |
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 discussed to create a new contract where we return void, and throw an exception in the event of an invalid configuration.
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.
Done.
| format::Substitute("Polling period {{period}}s cannot be negative", | ||
| {{"period", format::str(period_.count())}})); | ||
| } | ||
| return period_ > time::seconds::zero(); |
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.
Let's change this to >= again, as we will have a new abstraction for ShouldStartUpdater that will focus strictly on > 0.
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.
Actually, just moved this code to ShouldStartUpdater — ValidateConfiguration no longer needs a return value.
src/updater.h
Outdated
| }; | ||
|
|
||
| // A representation of all validation errors. | ||
| class ValidationError { |
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.
ConfigValidationError to be more specific?
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.
Done.
src/updater.h
Outdated
| friend class UpdaterTest; | ||
|
|
||
| bool ValidateConfiguration() const; | ||
| bool ValidateConfiguration() const throw(ValidationError); |
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.
Let's add a new method for ShouldStartUpdater or some equivalent name, that returns true or false. If for whatever reason the ShouldStartUpdater "fails" to validate, by not being able to QueryMaster, we should set unhealthy, but then return true so that we make a best effort attempt to poll / watch, as we had already validated that the configuration was valid. This will help keep us safe from transient errors preventing the updaters from firing off. Arguably, this hints at supporting a SetHealthy, in the event that something is able to recover properly. Let's save that for another PR though.
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.
Right, I'll leave this whole discussion in the PR comments for now, as we don't really need any of this functionality yet.
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.
Will keep this in one PR due to lack of time, but I did do what you asked in multiple commits. PTAL.
src/docker.cc
Outdated
| } catch (const QueryException& e) { | ||
| // Already logged. | ||
| return false; | ||
| bool DockerReader::ValidateConfiguration() const |
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.
Done.
| format::Substitute("Polling period {{period}}s cannot be negative", | ||
| {{"period", format::str(period_.count())}})); | ||
| } | ||
| return period_ > time::seconds::zero(); |
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.
Actually, just moved this code to ShouldStartUpdater — ValidateConfiguration no longer needs a return value.
src/updater.h
Outdated
| }; | ||
|
|
||
| // A representation of all validation errors. | ||
| class ValidationError { |
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.
Done.
src/updater.h
Outdated
| friend class UpdaterTest; | ||
|
|
||
| bool ValidateConfiguration() const; | ||
| bool ValidateConfiguration() const throw(ValidationError); |
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.
Right, I'll leave this whole discussion in the PR comments for now, as we don't really need any of this functionality yet.
90dbab8 to
ce23529
Compare
ce23529 to
dc64b1d
Compare
src/docker.cc
Outdated
| // Already logged. | ||
| return false; | ||
| throw MetadataUpdater::ConfigurationValidationError( | ||
| "Docker query retry limit reached: " + e.what()); |
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.
WDYT about adding "validation" here as well. Same elsewhere.
"Docker query validation retry limit reached"
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.
Done.
bmoyles0117
left a comment
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.
LGTM
… invalid configs. (#134) * Split the bool part of ValidateConfiguration out into ShouldStartUpdater.
Return false to stop or true to proceed.