* Implement missing pieces for connection backoff.
Spec can be found here:
https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md
Summary of changes:
* Added a new type (marked experimental), ConnectParams, which contains
the knobs defined in the spec (except for minConnectTimeout).
* Added a new API (marked experimental), WithConnectParams() to return a
DialOption to dial with the provided parameters.
* Added new fields to the implementation of the exponential backoff in
internal/backoff which mirror the ones in ConnectParams.
* Marked existing APIs WithBackoffMaxDelay() and WithBackoffConfig() as
deprecated.
* Added a default exponential backoff implementation, for easy use of
internal callers.
Added a new backoff package which defines the backoff configuration
options, and is used by both the grpc package and the internal/backoff
package. This allows us to have all backoff related options in a
separate package.
According to http://www.grpc.io/faq/, the project is called gRPC. It's
already referred by that name in most places, except a few instances
where it's still "GRPC". Fix those to have consistency.
To enforce immutability of the `DefaultBackoffConfig`, we've made it a
concrete value. While fields can still be set directly on the value,
taking a copy will not incidentally pull a reference to the variable.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
Because most of the fields on `BackoffConfig` are unexported, correctly
using the config requires copying from the default. This sets the
defaults appropriately and falls back to a default if MaxDelay is
negative or zero.
Tests are added to ensure that the backoff is set correctly in common
use cases.
Signedroff-by: Stephen J Day <stephen.day@docker.com>
Signed-off-by: Stephen J Day <stephen.day@docker.com>
The backoff function and parameters have been pulled up into an
interface `backoffStrategy`. The default parameters are now part of a
package variable `DefaultBackoffConfig`. The strategy is then plumbed
through `dialOptions`. As a result of this PR, the
maximum backoff delay can now be set using the `WithBackoffConfig` dial
option.
While the addition of strategy may seem premature, this allows one to
simply export `BackoffStrategy` and `WithBackoff` to allow arbirarily
configurable backoff strategies.
Signed-off-by: Stephen J Day <stephen.day@docker.com>