Documentation
¶
Overview ¶
Package faults provides common headers and client-side fault injection functionality.
Index ¶
Constants ¶
const FaultHeader = "x-bp-fault"
FaultHeader is the sole header used for fault injection configuration. It is formatted as a list of <key=value> pairs delimited by <;>, with support for the following keys:
a = [Required] Server address of outgoing request.
Used to determine whether the current request should have a fault injected.
m = [Optional] Method of outgoing request.
Used to determine whether the current request should have a fault injected.
d = [Optional] Number of milliseconds to delay the outgoing request, if matching.
D = [Optional] Percentage chance to delay outgoing request, if matching.
Only integers within [0-100] allowed.
f = [Optional] Abort current outgoing request and return this response code, if matching.
Only integers within [0-599] allowed.
b = [Optional] Message to return with the aborted request response, if matching.
Only US-ASCII allowed, excluding semicolon <;>, comma <,>, and equal sign <=>.
F = [Optional] Percentage chance to abort outgoing request, if matching.
Only integers within [0-100] allowed.
Example:
x-bp-fault: a=foo.bar;m=MyMethod;f=500;b=Fault injected!;F=50 A request for MyMethod on service foo.bar will fail 50% of the time with a 500 response containing the body message "Fault injected!".
Variables ¶
This section is empty.
Functions ¶
func WithDefaultAbort ¶
WithDefaultAbort is an option to set the default abort function for the Injector.
Types ¶
type Abort ¶
Abort is the function type to inject a protocol-specific fault with the given code and message.
type Headers ¶
type Headers interface {
// LookupValues returns the values of a protocol-specific header with
// the given key.
LookupValues(ctx context.Context, key string) ([]string, error)
}
Headers is an interface to be implemented by the caller to allow protocol-specific header lookup. Using an interface here rather than a function type avoids any potential closure requirements of a function.
type Injector ¶
type Injector[T any] struct { // contains filtered or unexported fields }
Injector contains the data common across all requests needed to inject faults on outgoing requests.
func NewInjector ¶
func NewInjector[T any](clientName, callerName string, abortCodeMin, abortCodeMax int, option ...func(*Injector[T])) *Injector[T]
NewInjector creates a new Injector with the provided parameters.
func (*Injector[T]) Inject ¶
func (i *Injector[T]) Inject(ctx context.Context, address, method string, headers Headers, resume Resume[T]) (T, error)
Inject injects a fault using the Injector default fault function on the outgoing request if it matches the header configuration.
func (*Injector[T]) InjectWithAbortOverride ¶
func (i *Injector[T]) InjectWithAbortOverride(ctx context.Context, address, method string, headers Headers, resume Resume[T], abort Abort[T]) (T, error)
InjectWithAbortOverride injects a fault using the provided fault function on the outgoing request if it matches the header configuration.