upstream

package
v0.0.0-...-0611383 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorClientStreamInterceptor

func ErrorClientStreamInterceptor(logger log.Logger, scope tally.Scope) grpc.StreamClientInterceptor

Types

type CallOptions

type CallOptions struct {
	// Timeout is the time to wait on a blocking grpc SendMsg.
	SendTimeout time.Duration

	// StreamTimeout is the time to wait before closing and reopening the gRPC stream.
	// If this is set to the Time.IsZero() value (ex: 0s), no stream timeout will be set unless
	// gRPC is blocked on Send/Recv message. If blocked, the maximum of StreamBlockedTimeout or
	// StreamTimeout is used.
	StreamTimeout time.Duration
	// StreamTimeoutJitter is an upper variance added to StreamTimeout to prevent a thundering
	// herd of streams being reopened.
	StreamTimeoutJitter time.Duration

	// ConnKeepaliveTimeout is the gRPC connection keep-alive timeout.
	// Based on https://github.com/grpc/grpc-go/blob/v1.32.x/keepalive/keepalive.go#L27-L45
	// If unset this defaults to 5 minutes.
	ConnKeepaliveTimeout time.Duration

	// NodeMetadata is an optional node metadata string field. This can be used to send
	// extra information to the management server, possibly on xds-relay specific metadata.
	NodeMetadata string
}

CallOptions contains grpc client call options

type Client

type Client interface {
	// OpenStream creates a stream with the origin server
	//
	// OpenStream should be called once per aggregated key.
	// OpenStream uses one representative node identifier for the entire lifetime of the stream.
	// Therefore, it is not necessary to pass node identifiers on subsequent requests from sidecars.
	// It follows xds protocol https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol
	// to handle the version_info, nonce and error_details and applies the response to the cache.
	//
	// All responses from the origin server are sent back through the callback function.
	//
	// OpenStream uses the retry and timeout configurations to make best effort to get the responses from origin server.
	// If the timeouts are exhausted, receive fails or a irrecoverable error occurs, the response channel is closed.
	// It is the caller's responsibility to send a new request from the last known DiscoveryRequest.
	// The shutdown function should be invoked to signal stream closure.
	// The shutdown function represents the intent that a stream is supposed to be closed.
	// All goroutines that depend on the ctx object should consider ctx.Done to be related to shutdown.
	// All such scenarios need to exit cleanly and are not considered an erroneous situation.
	OpenStream(transport.Request, string) (<-chan transport.Response, func())
}

Client handles the requests and responses from the origin server. The xds client handles each xds request on a separate stream, e.g. 2 different cds requests happen on 2 separate streams. It is the caller's responsibility to make sure there is one instance of Client overall.

func New

func New(
	ctx context.Context,
	url string,
	callOptions CallOptions,
	logger log.Logger,
	scope tally.Scope,
) (Client, error)

New creates a grpc connection with an upstream origin server. Each xds relay server should create a single such upstream connection. grpc will handle the actual number of underlying tcp connections.

The method does not block until the underlying connection is up. Returns immediately and connecting the server happens in background

func NewMock

func NewMock(
	ctx context.Context,
	callOptions CallOptions,
	errorOnCreate []error,
	ldsReceiveChan chan *v2.DiscoveryResponse,
	rdsReceiveChan chan *v2.DiscoveryResponse,
	edsReceiveChan chan *v2.DiscoveryResponse,
	cdsReceiveChan chan *v2.DiscoveryResponse,
	sendCb func(m interface{}) error,
	scope tally.Scope) Client

NewMock creates a mock client implementation for testing

func NewMockClient

NewMockClient creates a mock implementation for testing

func NewMockClientEDS

func NewMockClientEDS(
	ctx context.Context,
	edsClientV3 endpointservice.EndpointDiscoveryServiceClient,
	edsClientV2 v2.EndpointDiscoveryServiceClient,
	callOptions CallOptions,
	scope tally.Scope) Client

NewMockClientEDS creates a mock implementation for testing both v2 and v3 eds together

func NewMockClientV3

NewMockClientV3 creates a mock implementation for testing

func NewMockEDS

func NewMockEDS(
	ctx context.Context,
	callOptions CallOptions,
	errorOnCreate []error,
	edsReceiveChanV3 chan *discoveryv3.DiscoveryResponse,
	edsReceiveChanV2 chan *v2.DiscoveryResponse,
	sendCb func(m interface{}) error,
	scope tally.Scope) Client

NewMockEDS creates a mock client implementation for testing v2 and v3 eds together

func NewMockV3

func NewMockV3(
	ctx context.Context,
	callOptions CallOptions,
	errorOnCreate []error,
	ldsReceiveChan chan *discoveryv3.DiscoveryResponse,
	rdsReceiveChan chan *discoveryv3.DiscoveryResponse,
	edsReceiveChan chan *discoveryv3.DiscoveryResponse,
	cdsReceiveChan chan *discoveryv3.DiscoveryResponse,
	sendCb func(m interface{}) error,
	scope tally.Scope) Client

NewMockV3 creates a mock client implementation for testing

type UnsupportedResourceError

type UnsupportedResourceError struct {
	TypeURL string
}

UnsupportedResourceError is a custom error for unsupported typeURL

func (*UnsupportedResourceError) Error

func (e *UnsupportedResourceError) Error() string

Jump to

Keyboard shortcuts

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