fault

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fault implements fault injection rules (FR-CORE-060): inject an error code, latency or a dropped connection by service, method, resource pattern and probability or count.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Latency time.Duration
	Err     *apierr.Error
	Drop    bool
}

Action is what to do for a matched request.

type Duration

type Duration time.Duration

Duration is a time.Duration that (un)marshals as a Go duration string.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

type Rule

type Rule struct {
	ID string `json:"id" yaml:"id"`
	// Service is the emulator service name ("gcs", "pubsub", ...).
	Service string `json:"service,omitempty" yaml:"service"`
	// Method is a regexp matched against the method: "GET /storage/v1/b"
	// for HTTP, "/google.pubsub.v1.Publisher/Publish" for gRPC.
	Method string `json:"method,omitempty" yaml:"method"`
	// Resource is a regexp matched against the request path/resource.
	Resource string `json:"resource,omitempty" yaml:"resource"`
	// Code is the canonical error name to return (e.g. "UNAVAILABLE").
	Code string `json:"code,omitempty" yaml:"code"`
	// HTTPStatus overrides the HTTP status for Code.
	HTTPStatus int `json:"httpStatus,omitempty" yaml:"httpStatus"`
	// Latency is added before the request is handled (or the error returned).
	Latency Duration `json:"latency,omitempty" yaml:"latency"`
	// Drop closes the connection without a response.
	Drop bool `json:"drop,omitempty" yaml:"drop"`
	// Probability in (0,1]; 0 means always.
	Probability float64 `json:"probability,omitempty" yaml:"probability"`
	// Count limits how many times the rule fires; 0 means unlimited.
	Count int `json:"count,omitempty" yaml:"count"`
	// Fired is how many times the rule has fired.
	Fired int `json:"fired" yaml:"-"`
	// contains filtered or unexported fields
}

Rule is one fault-injection rule. Empty matchers match everything.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is a concurrency-safe ordered rule list.

func (*Set) Add

func (s *Set) Add(r Rule) (Rule, error)

Add validates and appends r, assigning an ID if empty.

func (*Set) List

func (s *Set) List() []Rule

List returns a copy of all rules.

func (*Set) Match

func (s *Set) Match(service, method, resource string) *Action

Match returns the action of the first rule that fires, or nil.

func (*Set) Remove

func (s *Set) Remove(id string) bool

Remove deletes a rule by ID; empty id clears all.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL