protocol

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package protocol implements the agent that injects disruptors in protocols. The protocol disruptors run as a proxy. The agent redirects the traffic to the proxy using iptables.

Index

Constants

View Source
const (
	// MetricRequests is the total number of requests received by the proxy.
	MetricRequests = "requests_total"
	// MetricRequestsExcluded is the total number of requests passed through due to exclusion rules.
	MetricRequestsExcluded = "requests_excluded"
	// MetricRequestsDisrupted is the total number requests that the proxy altered in any way.
	MetricRequestsDisrupted = "requests_disrupted"
)

Variables

View Source
var ErrNoRequests = errors.New("disruptor did not receive any request")

ErrNoRequests is returned when a proxy supports MetricRequests and returns a value of 0 for it.

Functions

func NewDisruptor

func NewDisruptor(
	executor runtime.Executor,
	proxy Proxy,
	redirector TrafficRedirector,
) (agent.Disruptor, error)

NewDisruptor creates a new instance of a Disruptor that applies a disruptions to a target The configuration controls how the disruptor operates.

Types

type MetricMap added in v0.3.8

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

MetricMap is a simple storage for name-indexed counter metrics.

func NewMetricMap added in v0.3.8

func NewMetricMap(metrics ...string) *MetricMap

NewMetricMap returns a MetricMap with the specified metrics initialized to zero.

func (*MetricMap) Inc added in v0.3.8

func (m *MetricMap) Inc(name string)

Inc increases the value of the specified counter by one. If the metric hasn't been initialized or incremented before, it is set to 1.

func (*MetricMap) Map added in v0.3.8

func (m *MetricMap) Map() map[string]uint

Map returns a map of the counters indexed by name. The returned map is a copy of the internal storage.

type Proxy

type Proxy interface {
	Start() error
	Stop() error
	// Metrics returns a map of counter-type metrics. Implementations may return zero or more of the metrics defined
	// below, as well as any number of implementation-defined metrics. Callers can check if a metric exists in the map
	// returned by Metrics to distinguish a counter with a value of zero from an unsupported metric.
	Metrics() map[string]uint
	Force() error
}

Proxy defines an interface for a proxy

type Redirector added in v0.3.11

type Redirector struct {
	*TrafficRedirectionSpec
	// contains filtered or unexported fields
}

Redirector is an implementation of TrafficRedirector that uses iptables rules.

func NewTrafficRedirector added in v0.3.11

func NewTrafficRedirector(
	tr *TrafficRedirectionSpec,
	iptables iptables.Iptables,
) (*Redirector, error)

NewTrafficRedirector creates instances of an iptables traffic redirector

func (*Redirector) Start added in v0.3.11

func (tr *Redirector) Start() error

Start applies the TrafficRedirect

func (*Redirector) Stop added in v0.3.11

func (tr *Redirector) Stop() error

Stop stops the TrafficRedirect. Stop will continue attempting to remove all the rules it deployed even if removing one fails.

type TrafficRedirectionSpec added in v0.3.11

type TrafficRedirectionSpec struct {
	// DestinationPort is the original destination port where the upstream application listens.
	DestinationPort uint
	// RedirectPort is the port where the traffic should be redirected to.
	// Typically, this would be where a transparent proxy is listening.
	RedirectPort uint
}

TrafficRedirectionSpec specifies the redirection of traffic to a destination

type TrafficRedirector added in v0.3.3

type TrafficRedirector interface {
	// Start initiates the redirection of traffic and resets existing connections
	Start() error
	// Stop restores the traffic to the original target and resets existing connections
	// to the redirection target
	Stop() error
}

TrafficRedirector defines the interface for a traffic redirector

func NoopTrafficRedirector added in v0.3.3

func NoopTrafficRedirector() TrafficRedirector

NoopTrafficRedirector returns a dummy traffic redirector that has no effect

Directories

Path Synopsis
Package grpc implements a proxy that applies disruptions to gRPC requests This package is inspired by and extensively copies code from https://github.com/mwitkow/grpc-proxy
Package grpc implements a proxy that applies disruptions to gRPC requests This package is inspired by and extensively copies code from https://github.com/mwitkow/grpc-proxy
Package http implements a proxy that applies disruptions to HTTP requests
Package http implements a proxy that applies disruptions to HTTP requests

Jump to

Keyboard shortcuts

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