Documentation ¶
Index ¶
- Constants
- Variables
- func WithRetryPolicy(ctx context.Context, retryPolicy RetryPolicy) context.Context
- type CircuitBreakerSettings
- type Client
- type ExponentialRetryPolicy
- type HystrixSSEEvent
- type NoRetryPolicy
- type RetryPolicy
- type SingleRetryPolicy
- type WagClient
- func (c *WagClient) GetDistricts(ctx context.Context, i *models.GetDistrictsInput) error
- func (c *WagClient) SetCircuitBreakerDebug(b bool)
- func (c *WagClient) SetCircuitBreakerSettings(settings CircuitBreakerSettings)
- func (c *WagClient) SetLogger(l wcl.WagClientLogger)
- func (c *WagClient) SetRetryPolicy(retryPolicy RetryPolicy)
- func (c *WagClient) SetTimeout(timeout time.Duration)
Constants ¶
const Version = "9.0.0"
Version of the client.
const VersionHeader = "X-Client-Version"
VersionHeader is sent with every request.
Variables ¶
var DefaultCircuitBreakerSettings = CircuitBreakerSettings{
MaxConcurrentRequests: 100,
RequestVolumeThreshold: 20,
SleepWindow: 5000,
ErrorPercentThreshold: 90,
}
DefaultCircuitBreakerSettings describes the default circuit parameters.
Functions ¶
func WithRetryPolicy ¶
func WithRetryPolicy(ctx context.Context, retryPolicy RetryPolicy) context.Context
WithRetryPolicy returns a new context that overrides the client object's retry policy.
Types ¶
type CircuitBreakerSettings ¶
type CircuitBreakerSettings struct { // MaxConcurrentRequests is the maximum number of concurrent requests // the client can make at the same time. Default: 100. MaxConcurrentRequests int // RequestVolumeThreshold is the minimum number of requests needed // before a circuit can be tripped due to health. Default: 20. RequestVolumeThreshold int // SleepWindow how long, in milliseconds, to wait after a circuit opens // before testing for recovery. Default: 5000. SleepWindow int // ErrorPercentThreshold is the threshold to place on the rolling error // rate. Once the error rate exceeds this percentage, the circuit opens. // Default: 90. ErrorPercentThreshold int }
CircuitBreakerSettings are the parameters that govern the client's circuit breaker.
type Client ¶
type Client interface { // GetDistricts makes a POST request to /check // // 200: nil // 400: *models.BadRequest // 500: *models.InternalError // default: client side HTTP errors, for example: context.DeadlineExceeded. GetDistricts(ctx context.Context, i *models.GetDistrictsInput) error }
Client defines the methods available to clients of the nil-test service.
type ExponentialRetryPolicy ¶
type ExponentialRetryPolicy struct{}
ExponentialRetryPolicy defines an exponential retry policy
func (ExponentialRetryPolicy) Backoffs ¶
func (ExponentialRetryPolicy) Backoffs() []time.Duration
Backoffs returns five backoffs with exponentially increasing wait times between requests: 100, 200, 400, 800, and 1600 milliseconds +/- up to 5% jitter.
type HystrixSSEEvent ¶
type HystrixSSEEvent struct { Type string `json:"type"` Name string `json:"name"` RequestCount int `json:"requestCount"` ErrorCount int `json:"errorCount"` ErrorPercentage int `json:"errorPercentage"` IsCircuitBreakerOpen bool `json:"isCircuitBreakerOpen"` RollingCountFailure int `json:"rollingCountFailure"` RollingCountFallbackFailure int `json:"rollingCountFallbackFailure"` RollingCountFallbackSuccess int `json:"rollingCountFallbackSuccess"` RollingCountShortCircuited int `json:"rollingCountShortCircuited"` RollingCountSuccess int `json:"rollingCountSuccess"` RollingCountThreadPoolRejected int `json:"rollingCountThreadPoolRejected"` RollingCountTimeout int `json:"rollingCountTimeout"` CurrentConcurrentExecutionCount int `json:"currentConcurrentExecutionCount"` LatencyTotalMean int `json:"latencyTotal_mean"` }
HystrixSSEEvent is emitted by hystrix-go via server-sent events. It describes the state of a circuit.
type NoRetryPolicy ¶
type NoRetryPolicy struct{}
NoRetryPolicy defines a policy of never retrying a request.
func (NoRetryPolicy) Backoffs ¶
func (NoRetryPolicy) Backoffs() []time.Duration
Backoffs returns an empty slice.
type RetryPolicy ¶
type RetryPolicy interface { // Backoffs returns the number and timing of retry attempts. Backoffs() []time.Duration // Retry receives the http request, as well as the result of // net/http.Client's `Do` method. Retry(*http.Request, *http.Response, error) bool }
RetryPolicy defines a retry policy.
type SingleRetryPolicy ¶
type SingleRetryPolicy struct{}
SingleRetryPolicy defines a retry that retries a request once
func (SingleRetryPolicy) Backoffs ¶
func (SingleRetryPolicy) Backoffs() []time.Duration
Backoffs returns that you should retry the request 1second after it fails.
type WagClient ¶
type WagClient struct {
// contains filtered or unexported fields
}
WagClient is used to make requests to the nil-test service.
func New ¶
func New(basePath string, logger wcl.WagClientLogger, transport *http.RoundTripper) *WagClient
New creates a new client. The base path, logger, and http transport are configurable. The logger provided should be specifically created for this wag client. If tracing is required, provide an instrumented transport using the wag clientconfig module. If no tracing is required, pass nil to use the default transport.
func NewFromDiscovery ¶
func NewFromDiscovery(logger wcl.WagClientLogger, transport *http.RoundTripper) (*WagClient, error)
NewFromDiscovery creates a client from the discovery environment variables. This method requires the three env vars: SERVICE_NIL_TEST_HTTP_(HOST/PORT/PROTO) to be set. Otherwise it returns an error. The logger provided should be specifically created for this wag client. If tracing is required, provide an instrumented transport using the wag clientconfig module. If no tracing is required, pass nil to use the default transport.
func (*WagClient) GetDistricts ¶
GetDistricts makes a POST request to /check
200: nil 400: *models.BadRequest 500: *models.InternalError default: client side HTTP errors, for example: context.DeadlineExceeded.
func (*WagClient) SetCircuitBreakerDebug ¶
SetCircuitBreakerDebug puts the circuit
func (*WagClient) SetCircuitBreakerSettings ¶
func (c *WagClient) SetCircuitBreakerSettings(settings CircuitBreakerSettings)
SetCircuitBreakerSettings sets parameters on the circuit breaker. It must be called on application startup.
func (*WagClient) SetLogger ¶
func (c *WagClient) SetLogger(l wcl.WagClientLogger)
SetLogger allows for setting a custom logger
func (*WagClient) SetRetryPolicy ¶
func (c *WagClient) SetRetryPolicy(retryPolicy RetryPolicy)
SetRetryPolicy sets a the given retry policy for all requests.
func (*WagClient) SetTimeout ¶
SetTimeout sets a timeout on all operations for the client. To make a single request with a shorter timeout than the default on the client, use context.WithTimeout as described here: https://godoc.org/golang.org/x/net/context#WithTimeout.