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 InjectParameters ¶ added in v0.10.1
type InjectParameters[T any] struct { Address string Method string MethodLabel string Headers Headers Resume Resume[T] Abort Abort[T] }
InjectParameters contains the parameters needed to match and inject a fault into the outgoing request.
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.