proxy

package
v0.0.0-...-2c38ada Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProbUniform = iota
	ProbExponential
	ProbNormal
)

Variables

View Source
var NopRule = Rule{Enabled: false}

NopRule is a rule that does nothing. Useful default return value

Functions

func DistributionString

func DistributionString(p ProbabilityDistribution) string

func ReqString

func ReqString(r MessageType) string

ReqString returns the string represtation of MessageType: either "request" or "reply"

Types

type ActionMethod

type ActionMethod uint

ActionMethod with respect to an action. In case of abort it's hang, reset,...

type LoadBalancer

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

LoadBalancer is in charge of switching up which host the request goes to

func NewLoadBalancer

func NewLoadBalancer(c config.LoadBalancerConfig) *LoadBalancer

NewLoadBalancer creates a new load balancer

func (*LoadBalancer) GetHost

func (l *LoadBalancer) GetHost() string

GetHost returns a single host that the client should connect based on the loadbalance mode

func (*LoadBalancer) GetInstances

func (l *LoadBalancer) GetInstances() []string

GetInstances retrieves the available instances for the service

func (*LoadBalancer) SetInstances

func (l *LoadBalancer) SetInstances(hosts []string)

SetInstances updates internally stored available instances for the service

type MessageType

type MessageType uint

MessageType is just that a type: request or reply

const (
	MTypeUnknown MessageType = iota
	Request
	Response
	Publish
	Subscribe
)

message channel type between client and server, via the proxy

type ProbabilityDistribution

type ProbabilityDistribution uint

ProbabilityDistribution is a type for probability distribution functions for rules

type Proxy

type Proxy struct {
	Protocol string
	// contains filtered or unexported fields
}

Proxy implements the proxying logic between a pair of services. A single router can have multiple proxies, one for each service that the local service needs to talk to

func NewProxy

func NewProxy(serviceName string, conf config.ProxyConfig,
	lbconf config.LoadBalancerConfig) *Proxy

NewProxy returns a new proxy instance.

func (*Proxy) AddRule

func (p *Proxy) AddRule(r Rule)

AddRule adds a new rule to the proxy. All requests/replies carrying the trackingheader will be checked against all rules, if something matches, the first matched rule will be executed

func (*Proxy) GetInstances

func (p *Proxy) GetInstances() []string

GetInstances returns the service instances available in the loadbalancer for a given service

func (*Proxy) GetRules

func (p *Proxy) GetRules() []Rule

GetRules returns all rules currently active at this proxy

func (*Proxy) RemoveRule

func (p *Proxy) RemoveRule(r Rule) bool

RemoveRule removes a rule from this proxy

func (*Proxy) Reset

func (p *Proxy) Reset()

Reset clears proxy state. Removes all stored rules and expects. However loadbalancer hosts remain.

func (*Proxy) Run

func (p *Proxy) Run()

Run starts up a proxy in the desired mode: tcp or http. This is a blocking call

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, req *http.Request)
FIXME: BUG This method reads requests/replies into memory.

* DO NOT use this on very large size requests.

func (*Proxy) SetInstances

func (p *Proxy) SetInstances(hosts []string)

SetInstances sets the service instances available in the loadbalancer for a given service

func (*Proxy) SetTestID

func (p *Proxy) SetTestID(testID string)

func (*Proxy) StopTest

func (p *Proxy) StopTest(testID string) bool

type Rule

type Rule struct {
	Source string
	Dest   string
	MType  MessageType

	//Select only messages that match pattens specified in these fields
	BodyPattern   string
	HeaderPattern string

	// First delay, then mangle and then abort
	// One could set the probabilities of these variables to 0/1 to toggle them on or off
	// We effectively get 8 combinations but only few make sense.
	DelayProbability   float64
	DelayDistribution  ProbabilityDistribution
	MangleProbability  float64
	MangleDistribution ProbabilityDistribution
	AbortProbability   float64
	AbortDistribution  ProbabilityDistribution

	//TestID       string
	DelayTime     time.Duration
	ErrorCode     int
	SearchString  string
	ReplaceString string
	Enabled       bool
}

Rule is a universal type for all rules.

func NewRule

func NewRule(c config.RuleConfig) (Rule, error)

NewRule return a new rule based on the config.

func (*Rule) ToConfig

func (r *Rule) ToConfig() config.RuleConfig

ToConfig converts the rule into a human-readable string config.

Jump to

Keyboard shortcuts

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