failure_detector

package module
v0.0.0-...-2542f88 Latest Latest
Warning

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

Go to latest
Published: May 17, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EndpointStatusReasonTooManyErrors means the detector experienced too many samples that indicated an error
	EndpointStatusReasonTooManyErrors = "TooManyErrors"
)

Variables

This section is empty.

Functions

func EndpointSampleKeyFunction

func EndpointSampleKeyFunction(obj interface{}) string

EndpointSampleKeyFunction a function used for deriving a key from an EndpointSample that uniquely identifies it

func EndpointSampleToServiceKeyFunction

func EndpointSampleToServiceKeyFunction(obj interface{}) string

EndpointSampleToServiceKeyFunction a function used by the batch queue and the internal store (failureDetector.store) for deriving a key from EndpointSample. The key identifies a Service an endpoints belongs to

func NewDefaultFailureDetector

func NewDefaultFailureDetector() *failureDetector

func SimpleWeightedEndpointStatusEvaluator

func SimpleWeightedEndpointStatusEvaluator(endpoint *WeightedEndpointStatus) bool

SimpleWeightedEndpointStatusEvaluator an external policy evaluator that sets the status and weight of the given endpoint based on the collected samples. It returns true only if status or wight have changed otherwise false

WeightedEndpointStatus.Status: will be set to EndpointStatusReasonTooManyErrors only when it sees 10 errors otherwise it will be set to an empty string

WeightedEndpointStatus.Weight: 10 consecutive will decrease the weight by 0.01 for example:

  • the value of 1 means no errors
  • the value of 0 means it observed 100 errors
  • the value of 0.7 means it observed 30 errors

Types

type BatchQueue

type BatchQueue interface {
	// Get retrieves the next batch of collected items/work along with the unique key
	// A caller must execute the corresponding Done() method once it has finished its work
	Get() (key string, items []interface{})

	// Add adds the given item under the given key to the queue
	Add(key string, item interface{})

	// Done indicates that the caller finished working on items represented by a unique key
	// if it has been added again while it was being processed, it will be re-added to the queue for re-processing
	Done(key string)
}

BatchQueue represents a generic work queue that process items in the order in which they were added, it also supports batching - items are grouped by a key and could be retrieved as a package

For now it is used by newEndPointSampleBatchQueue function and converted to a strongly typed queue (endPointSampleBatchQueue) It will be removed in the future once we move the queue implementation to this package

type EndpointSample

type EndpointSample struct {
	Namespace string
	Service   string
	URL       *url.URL
	Err       error
}

EndpointSample represents a sample collected for an endpoint derived from a proxied request. it holds:

  • Namespace, Service and URL to uniquely identify the request
  • an optional Err returned from the proxy

type EvaluateFunc

type EvaluateFunc func(endpoint *WeightedEndpointStatus) bool

EvaluateFunc a function to an external policy evaluator that sets the status and weight of the given endpoint based on the collected samples.

type KeyFunc

type KeyFunc func(obj interface{}) string

type NewStoreFunc

type NewStoreFunc func(ttl time.Duration) WeightedEndpointStatusStore

NewStoreFunc a func for creating WeightedEndpointStatus store per Service

type Sample

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

Sample represents a single sample collected for an endpoint

type Store

type Store interface {
	// Add adds the given object to the store under the given key
	Add(key string, obj interface{})

	// Get retrieves an object from the store at the given key
	Get(key string) interface{}

	// List returns all objects in the store
	List() []interface{}
}

Store an in-memory store for storing and retrieving arbitrary data

For now it is used by newEndpointStore function and converted to a strongly typed store (WeightedEndpointStatus) It will be removed in the future once we move the store implementation to this package

type WeightedEndpointStatus

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

WeightedEndpointStatus represents the current status of the given endpoint based on the collected samples. The status will be examined and filled by the external policy.

func (*WeightedEndpointStatus) Add

func (ep *WeightedEndpointStatus) Add(sample *Sample)

Add adds the given sample to the internal store it will overwrite the old values when it exceeds the configured capacity

func (*WeightedEndpointStatus) Get

func (ep *WeightedEndpointStatus) Get() []*Sample

Get retrieves the collected samples so far

type WeightedEndpointStatusStore

type WeightedEndpointStatusStore interface {
	// Add adds the given object to the store under the given key
	Add(key string, obj *WeightedEndpointStatus)

	// Get retrieves WeightedEndpointStatus from the store at the given key
	Get(key string) *WeightedEndpointStatus

	// List returns all WeightedEndpointStatus in the store
	List() []*WeightedEndpointStatus
}

WeightedEndpointStatusStore an in-memory store for WeightedEndpointStatus. It automatically removed entries that exceed the configured TTL as that allows for removing unused/removed endpoints

Jump to

Keyboard shortcuts

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