Documentation
¶
Overview ¶
Package protocol pairs the reference and candidate traffic that protocol servers report, compares ingress responses, and replays egress responses.
Index ¶
- type Acceptor
- type Config
- type Content
- type Decision
- type DecisionForward
- type DecisionIntercept
- type Declaration
- type DeclarationIgnore
- type DeclarationRequest
- type DeclarationResponse
- type Engine
- func (e *Engine) EgressCandidate(protocol model.Protocol) Acceptor
- func (e *Engine) EgressReference(protocol model.Protocol) Acceptor
- func (e *Engine) IngressCandidate(protocol model.Protocol) Acceptor
- func (e *Engine) IngressReference(protocol model.Protocol) Acceptor
- func (e *Engine) Schema() *schema.Schema
- func (e *Engine) Shutdown(ctx context.Context) error
- type Exchange
- type Matcher
- type Message
- type Quarantiner
- type Raw
- type RequestID
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Acceptor ¶
type Acceptor interface {
// ProcessRequest decides what a server does with a request. ignored explains why
// ingress never compares its responses. An error means the request must not be sent.
ProcessRequest(ctx context.Context, requestID Option[RequestID], route model.Route, ignored Option[string],
request func(ctx context.Context) (Message, error)) (Decision, error)
// ProcessResponse reports the response to a forwarded request. The engine owns
// response.Raw from here on.
ProcessResponse(ctx context.Context, exchange Exchange, response Response)
// Unable ends a forwarded request whose response cannot be compared or replayed.
// A cancelled ctx explains the failure, so it never quarantines the candidate.
Unable(ctx context.Context, exchange Exchange, reason error)
}
Acceptor receives the requests and responses at one ingress or egress point, so servers never know whether they carry reference or candidate traffic.
type Config ¶
type Config struct {
// Comparison configures the scripts that normalise, compare, and hash payloads.
Comparison comparison.Config `embed:""`
// MatchWindow bounds how long an unused reference stays available, and how
// long a candidate waits for one.
MatchWindow time.Duration `default:"5s" help:"How long reference and candidate requests wait to be paired."`
}
Config contains the command-line configuration for pairing and comparison.
type Content ¶
type Content struct {
// Status is absent only when Failure explains why.
Status Option[string]
Message Option[Message]
Failure Option[error]
}
Content is a response's comparable content. Comparison checks Status when both sides know it, then Failure, then Message.
type Decision ¶
type Decision interface {
// contains filtered or unexported methods
}
Decision tells a server what to do with a request.
type DecisionForward ¶
DecisionForward sends the request on. The server reports the response under Exchange, and passes RequestID to a candidate when one is assigned.
type DecisionIntercept ¶
type DecisionIntercept struct{ Raw Raw }
DecisionIntercept answers the request with Raw instead of sending it. The server releases Raw once replay finishes.
type Declaration ¶
type Declaration interface {
// contains filtered or unexported methods
}
Declaration is what a script declares for a protocol pattern.
type DeclarationIgnore ¶
type DeclarationIgnore struct{ Reason string }
DeclarationIgnore skips comparison of ingress responses.
type DeclarationRequest ¶
DeclarationRequest types the requests that egress forwards to a dependency.
type DeclarationResponse ¶
DeclarationResponse types the responses that ingress compares.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine owns the in-flight state that every Acceptor shares.
func NewEngine ¶
func NewEngine( ctx context.Context, config Config, matchers map[model.Protocol]Matcher, quarantine Quarantiner, ) (*Engine, error)
NewEngine loads the scripts and passes each declaration to the matcher for its protocol. A script naming an unregistered protocol fails startup.
func (*Engine) EgressCandidate ¶
EgressCandidate returns the acceptor for the candidate's dependency requests.
func (*Engine) EgressReference ¶
EgressReference returns the acceptor for the reference's dependency requests.
func (*Engine) IngressCandidate ¶
IngressCandidate returns the acceptor for mirrored requests to the candidate service.
func (*Engine) IngressReference ¶
IngressReference returns the acceptor for requests to the reference service.
type Exchange ¶
Exchange links a forwarded request to its response. It is unique within one engine, so it never leaves the process that forwarded the request.
type Matcher ¶
type Matcher interface {
Declare(pattern string, declaration Declaration) error
}
Matcher owns a protocol's pattern table. The engine passes it every script declaration for its protocol at startup, so invalid patterns fail startup.
type Quarantiner ¶
type Quarantiner interface {
Quarantine(ctx context.Context, reason model.QuarantineReason)
}
Quarantiner stops all candidate traffic.
type Raw ¶
type Raw interface {
Release()
}
Raw is a server's own record of a response, which an intercept replays. Release frees it, and must be safe to call more than once.
type Response ¶
type Response struct {
Raw Raw
// Latency is the time to the first response byte, or zero if unmeasured.
Latency time.Duration
// Decode is called only to compare, on the candidate's time rather than the
// reference's, and while the engine still holds Raw.
Decode func() Content
}
Response is what a server received for a forwarded request.