This repository was archived by the owner on Aug 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
For Kubernetes watch, add tests of backoff and reconnection on failures. Also, when watch response is >= 300, count that as a failure. #205
Open
davidbtucker
wants to merge
3
commits into
master
Choose a base branch
from
davidbtucker-watch-reconnect-backoff-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,8 +78,14 @@ class KubernetesReader::NonRetriableError | |
|
||
KubernetesReader::KubernetesReader(const Configuration& config, | ||
HealthChecker* health_checker) | ||
: KubernetesReader(config, health_checker, SleeperImpl::New()) {} | ||
|
||
KubernetesReader::KubernetesReader(const Configuration& config, | ||
HealthChecker* health_checker, | ||
std::unique_ptr<Sleeper> sleeper) | ||
: config_(config), environment_(config), health_checker_(health_checker), | ||
service_account_directory_(kServiceAccountDirectory) {} | ||
service_account_directory_(kServiceAccountDirectory), | ||
sleeper_(std::move(sleeper)) {} | ||
|
||
std::string KubernetesReader::SecretPath(const std::string& secret) const { | ||
return service_account_directory_ + "/" + secret; | ||
|
@@ -837,21 +843,29 @@ void KubernetesReader::WatchMaster( | |
if (verbose) { | ||
LOG(INFO) << "WatchMaster(" << name << ") completed " << body(response); | ||
} | ||
if (status(response) >= 300) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an unrelated fix not mentioned in the PR description. Mitigations, in order of preference, would be to pull it (and the associated test changes) out into a separate PR, or at least mention it in the description. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the PR description. The fix is intertwined with the new tests, so it's not really possible to pull out into a separate PR. |
||
throw boost::system::system_error( | ||
boost::system::errc::make_error_code( | ||
boost::system::errc::not_connected), | ||
format::Substitute("Server responded with '{{message}}' ({{code}})", | ||
{{"message", status_message(response)}, | ||
{"code", format::str(status(response))}})); | ||
} | ||
// Connection closed without an error; reset failure count. | ||
failures = 0; | ||
} catch (const boost::system::system_error& e) { | ||
LOG(ERROR) << "Failed to query " << endpoint << ": " << e.what(); | ||
++failures; | ||
if (failures > config_.KubernetesUpdaterWatchMaxConnectionFailures()) { | ||
if (failures >= config_.KubernetesUpdaterWatchMaxConnectionFailures()) { | ||
LOG(ERROR) << "WatchMaster(" << name << "): Exiting after " | ||
<< failures << " failures"; | ||
throw QueryException(endpoint + " -> " + e.what()); | ||
} | ||
++failures; | ||
double backoff = fmin(pow(1.5, failures), 30); | ||
if (verbose) { | ||
LOG(INFO) << "Backing off for " << backoff << " seconds"; | ||
} | ||
std::this_thread::sleep_for(time::seconds(backoff)); | ||
sleeper_->SleepFor(backoff); | ||
} | ||
} | ||
} | ||
|
@@ -1310,10 +1324,17 @@ void KubernetesReader::WatchEndpoints( | |
KubernetesUpdater::KubernetesUpdater(const Configuration& config, | ||
HealthChecker* health_checker, | ||
MetadataStore* store) | ||
: reader_(config, health_checker), PollingMetadataUpdater( | ||
config, store, "KubernetesUpdater", | ||
config.KubernetesUpdaterIntervalSeconds(), | ||
[=]() { return reader_.MetadataQuery(); }) { } | ||
: KubernetesUpdater(config, health_checker, store, SleeperImpl::New()) {} | ||
|
||
KubernetesUpdater::KubernetesUpdater(const Configuration& config, | ||
HealthChecker* health_checker, | ||
MetadataStore* store, | ||
std::unique_ptr<Sleeper> sleeper) | ||
: reader_(config, health_checker, std::move(sleeper)), | ||
PollingMetadataUpdater( | ||
config, store, "KubernetesUpdater", | ||
config.KubernetesUpdaterIntervalSeconds(), | ||
[=]() { return reader_.MetadataQuery(); }) { } | ||
|
||
void KubernetesUpdater::ValidateDynamicConfiguration() const | ||
throw(ConfigurationValidationError) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we rename
sleeper
to be a bit more descriptive? This only seems to be used during retry backoffs.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.
+1. The sleep functionality is to induce the passage of time, so time-related tool names like "Timer", "Stopwatch", "AlarmClock", etc are usually appropriate. Would it make sense to reuse the existing
Timer
class and broaden its interface?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.
Happy to rename. What would you like?