xds

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(log logr.Logger) envoy_log.Logger

func SanitizeMetric

func SanitizeMetric(metric string) string

We need to sanitize metrics in order to not break statsd and prometheus format. StatsD only allow [a-zA-Z_\-0-9.] characters, everything else is removed Extra dots breaks many regexes that converts statsd metric to prometheus one with tags

Types

type Callbacks

type Callbacks interface {
	// OnStreamOpen is called once an xDS stream is opened with a stream ID and the type URL (or "" for ADS).
	// Returning an error will end processing and close the stream. OnStreamClosed will still be called.
	OnStreamOpen(context.Context, int64, string) error
	// OnStreamClosed is called immediately prior to closing an xDS stream with a stream ID.
	OnStreamClosed(int64)
	// OnStreamRequest is called once a request is received on a stream.
	// Returning an error will end processing and close the stream. OnStreamClosed will still be called.
	OnStreamRequest(int64, DiscoveryRequest) error
	// OnStreamResponse is called immediately prior to sending a response on a stream.
	OnStreamResponse(int64, DiscoveryRequest, DiscoveryResponse)
}

Callbacks defines Callbacks for xDS streaming requests. The difference over real go-control-plane Callbacks is that it takes an DiscoveryRequest / DiscoveryResponse interface. It helps us to implement Callbacks once for many different versions of Envoy API.

func NewStatsCallbacks

func NewStatsCallbacks(metrics prometheus.Registerer, dsType string) (Callbacks, error)

type DiscoveryRequest

type DiscoveryRequest interface {
	NodeId() string
	// Node returns either a v2 or v3 Node
	Node() interface{}
	Metadata() *_struct.Struct
	VersionInfo() string
	GetTypeUrl() string
	GetResponseNonce() string
	HasErrors() bool
	ErrorMsg() string
}

DiscoveryRequest defines interface over real Envoy's DiscoveryRequest.

type DiscoveryResponse

type DiscoveryResponse interface {
	GetTypeUrl() string
}

DiscoveryResponse defines interface over real Envoy's DiscoveryResponse.

type LoggingCallbacks

type LoggingCallbacks struct {
	Log logr.Logger
}

func (LoggingCallbacks) OnFetchRequest

func (cb LoggingCallbacks) OnFetchRequest(ctx context.Context, req DiscoveryRequest) error

OnFetchRequest is called for each Fetch request. Returning an error will end processing of the request and respond with an error.

func (LoggingCallbacks) OnFetchResponse

func (cb LoggingCallbacks) OnFetchResponse(req DiscoveryRequest, resp DiscoveryResponse)

OnFetchRequest is called for each Fetch request. Returning an error will end processing of the request and respond with an error. OnFetchResponse is called immediately prior to sending a response.

func (LoggingCallbacks) OnStreamClosed

func (cb LoggingCallbacks) OnStreamClosed(streamID int64)

OnStreamClosed is called immediately prior to closing an xDS stream with a stream ID.

func (LoggingCallbacks) OnStreamOpen

func (cb LoggingCallbacks) OnStreamOpen(ctx context.Context, streamID int64, typ string) error

OnStreamOpen is called once an xDS stream is open with a stream ID and the type URL (or "" for ADS). Returning an error will end processing and close the stream. OnStreamClosed will still be called.

func (LoggingCallbacks) OnStreamRequest

func (cb LoggingCallbacks) OnStreamRequest(streamID int64, req DiscoveryRequest) error

OnStreamRequest is called once a request is received on a stream. Returning an error will end processing and close the stream. OnStreamClosed will still be called.

func (LoggingCallbacks) OnStreamResponse

func (cb LoggingCallbacks) OnStreamResponse(streamID int64, req DiscoveryRequest, resp DiscoveryResponse)

OnStreamResponse is called immediately prior to sending a response on a stream.

type MultiCallbacks

type MultiCallbacks interface {
	Callbacks
	RestCallbacks
}

MultiCallbacks implements callbacks for both rest and streaming xDS requests.

type NoopCallbacks

type NoopCallbacks struct {
}

func (*NoopCallbacks) OnStreamClosed

func (n *NoopCallbacks) OnStreamClosed(int64)

func (*NoopCallbacks) OnStreamOpen

func (n *NoopCallbacks) OnStreamOpen(context.Context, int64, string) error

func (*NoopCallbacks) OnStreamRequest

func (n *NoopCallbacks) OnStreamRequest(int64, DiscoveryRequest) error

func (*NoopCallbacks) OnStreamResponse

func (n *NoopCallbacks) OnStreamResponse(int64, DiscoveryRequest, DiscoveryResponse)

type RestCallbacks

type RestCallbacks interface {
	// OnFetchRequest is called when a new rest request comes in.
	// Returning an error will end processing. OnFetchResponse will not be called.
	OnFetchRequest(ctx context.Context, request DiscoveryRequest) error
	// OnFetchResponse is called immediately prior to sending a rest response.
	OnFetchResponse(request DiscoveryRequest, response DiscoveryResponse)
}

RestCallbacks defines rest.Callbacks for xDS fetch requests. The difference over real go-control-plane Callbacks is that it takes an DiscoveryRequest / DiscoveryResponse interface. It helps us to implement Callbacks once for many different versions of Envoy API.

type Snapshot

type Snapshot interface {

	// GetSupportedTypes returns a list of xDS types supported by this snapshot.
	GetSupportedTypes() []string

	// Consistent check verifies that the dependent resources are exactly listed in the
	// snapshot:
	// - all EDS resources are listed by name in CDS resources
	// - all RDS resources are listed by name in LDS resources
	//
	// Note that clusters and listeners are requested without name references, so
	// Envoy will accept the snapshot list of clusters as-is even if it does not match
	// all references found in xDS.
	Consistent() error

	// GetResources selects snapshot resources by type.
	GetResources(typ string) map[string]envoy_types.Resource

	// GetResourcesAndTtl selects snapshot resources by type, returning the map of resources and the associated TTL.
	GetResourcesAndTtl(typ string) map[string]envoy_types.ResourceWithTtl

	// GetVersion returns the version for a resource type.
	GetVersion(typ string) string

	// WithVersion creates a new snapshot with a different version for a given resource type.
	WithVersion(typ string, version string) Snapshot
}

Snapshot is an internally consistent snapshot of xDS resources. Consistency is important for the convergence as different resource types from the snapshot may be delivered to the proxy in arbitrary order.

Notice that unlike in the original github.com/envoyproxy/go-control-plane library, Snapshot is an interface which will allow to reuse SnapshotCache for arbitrary xDS resources rather than just core Envoy's ones.

type SnapshotAutoVersioner

type SnapshotAutoVersioner struct {
	UUID func() string
}

SnapshotAutoVersioner assigns versions to xDS resources in a new Snapshot by reusing if possible a version from the old snapshot and generating a new version (UUID) otherwise.

func (SnapshotAutoVersioner) Version

func (v SnapshotAutoVersioner) Version(new, old Snapshot) Snapshot

type SnapshotCache

type SnapshotCache interface {
	envoy_cache.Cache

	// SetSnapshot sets a response snapshot for a node. For ADS, the snapshots
	// should have distinct versions and be internally consistent (e.g. all
	// referenced resources must be included in the snapshot).
	//
	// This method will cause the server to respond to all open watches, for which
	// the version differs from the snapshot version.
	SetSnapshot(node string, snapshot Snapshot) error

	// GetSnapshots gets the snapshot for a node.
	GetSnapshot(node string) (Snapshot, error)

	// ClearSnapshot removes all status and snapshot information associated with a node.
	ClearSnapshot(node string)

	// GetStatusInfo retrieves status information for a node ID.
	GetStatusInfo(string) envoy_cache.StatusInfo

	// GetStatusKeys retrieves node IDs for all statuses.
	GetStatusKeys() []string
}

SnapshotCache is a snapshot-based cache that maintains a single versioned snapshot of responses per node. SnapshotCache consistently replies with the latest snapshot. For the protocol to work correctly in ADS mode, EDS/RDS requests are responded only when all resources in the snapshot xDS response are named as part of the request. It is expected that the CDS response names all EDS clusters, and the LDS response names all RDS routes in a snapshot, to ensure that Envoy makes the request for all EDS clusters or RDS routes eventually.

SnapshotCache can operate as a REST or regular xDS backend. The snapshot can be partial, e.g. only include RDS or EDS resources.

func NewSnapshotCache

func NewSnapshotCache(ads bool, hash envoy_cache.NodeHash, logger envoy_log.Logger) SnapshotCache

NewSnapshotCache initializes a simple cache.

ADS flag forces a delay in responding to streaming requests until all resources are explicitly named in the request. This avoids the problem of a partial request over a single stream for a subset of resources which would require generating a fresh version for acknowledgement. ADS flag requires snapshot consistency. For non-ADS case (and fetch), multiple partial requests are sent across multiple streams and re-using the snapshot version is OK.

Logger is optional.

func NewSnapshotCacheWithHeartbeating

func NewSnapshotCacheWithHeartbeating(ctx context.Context, ads bool, hash envoy_cache.NodeHash, logger envoy_log.Logger, heartbeatInterval time.Duration) SnapshotCache

NewSnapshotCacheWithHeartbeating initializes a simple cache that sends periodic heartbeat responses for resources with a TTL.

ADS flag forces a delay in responding to streaming requests until all resources are explicitly named in the request. This avoids the problem of a partial request over a single stream for a subset of resources which would require generating a fresh version for acknowledgement. ADS flag requires snapshot consistency. For non-ADS case (and fetch), multiple partial requests are sent across multiple streams and re-using the snapshot version is OK.

Logger is optional.

The context provides a way to cancel the heartbeating routine, while the heartbeatInterval parameter controls how often heartbeating occurs.

type SnapshotVersioner

type SnapshotVersioner interface {
	Version(new, old Snapshot) Snapshot
}

SnapshotVersioner assigns versions to xDS resources in a new Snapshot.

type StatsCallbacks

type StatsCallbacks struct {
	NoopCallbacks
	ResponsesSentMetric    *prometheus.CounterVec
	RequestsReceivedMetric *prometheus.CounterVec
	StreamsActive          int
	sync.RWMutex
}

func (*StatsCallbacks) OnStreamClosed

func (s *StatsCallbacks) OnStreamClosed(stream int64)

func (*StatsCallbacks) OnStreamOpen

func (s *StatsCallbacks) OnStreamOpen(ctx context.Context, stream int64, typ string) error

func (*StatsCallbacks) OnStreamRequest

func (s *StatsCallbacks) OnStreamRequest(stream int64, request DiscoveryRequest) error

func (*StatsCallbacks) OnStreamResponse

func (s *StatsCallbacks) OnStreamResponse(_ int64, _ DiscoveryRequest, response DiscoveryResponse)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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