cache

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package cache defines a configuration cache for the server.

Index

Constants

View Source
const (
	EndpointType = typePrefix + "ClusterLoadAssignment"
	ClusterType  = typePrefix + "Cluster"
	RouteType    = typePrefix + "RouteConfiguration"
	ListenerType = typePrefix + "Listener"

	// AnyType is used only by ADS
	AnyType = ""
)

Resource types in xDS v2.

Variables

View Source
var (
	// ResponseTypes are supported response types.
	ResponseTypes = []string{
		EndpointType,
		ClusterType,
		RouteType,
		ListenerType,
	}
)

Functions

func GetResourceName

func GetResourceName(res Resource) string

GetResourceName returns the resource name for a valid xDS response type.

func GetResourceReferences

func GetResourceReferences(resources map[string]Resource) map[string]bool

GetResourceReferences returns the names for dependent resources (EDS cluster names for CDS, RDS routes names for LDS).

func IndexResourcesByName

func IndexResourcesByName(items []Resource) map[string]Resource

IndexResourcesByName creates a map from the resource name to the resource.

Types

type Cache

type Cache interface {
	ConfigWatcher

	// Fetch implements the polling method of the config cache using a non-empty request.
	Fetch(context.Context, Request) (*Response, error)

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

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

Cache is a generic config cache with a watcher.

type ConfigWatcher

type ConfigWatcher interface {
	// CreateWatch returns a new open watch from a non-empty request.
	//
	// Value channel produces requested resources, once they are available.  If
	// the channel is closed prior to cancellation of the watch, an unrecoverable
	// error has occurred in the producer, and the consumer should close the
	// corresponding stream.
	//
	// Cancel is an optional function to release resources in the producer. If
	// provided, the consumer may call this function multiple times.
	CreateWatch(Request) (value chan Response, cancel func())
}

ConfigWatcher requests watches for configuration resources by a node, last applied version identifier, and resource names hint. The watch should send the responses when they are ready. The watch can be cancelled by the consumer, in effect terminating the watch for the request. ConfigWatcher implementation must be thread-safe.

type NodeHash

type NodeHash interface {
	// ID function defines a unique string identifier for the remote Envoy node.
	ID(node *core.Node) string
}

NodeHash computes string identifiers for Envoy nodes.

type Request

type Request = v2.DiscoveryRequest

Request is an alias for the discovery request type.

type Resource

type Resource interface {
	proto.Message
	Equal(interface{}) bool
}

Resource is the base interface for the xDS payload.

type Resources

type Resources struct {
	// Version information.
	Version string

	// Items in the group.
	Items map[string]Resource
}

Resources is a versioned group of resources.

func NewResources

func NewResources(version string, items []Resource) Resources

NewResources creates a new resource group.

type Response

type Response struct {
	// Request is the original request.
	Request v2.DiscoveryRequest

	// Version of the resources as tracked by the cache for the given type.
	// Proxy responds with this version as an acknowledgement.
	Version string

	// Resources to be included in the response.
	Resources []Resource
}

Response is a pre-serialized xDS response.

type ResponseWatch

type ResponseWatch struct {
	// Request is the original request for the watch.
	Request Request

	// Response is the channel to push response to.
	Response chan Response
}

ResponseWatch is a watch record keeping both the request and an open channel for the response.

type Snapshot

type Snapshot struct {
	// Endpoints are items in the EDS response payload.
	Endpoints Resources

	// Clusters are items in the CDS response payload.
	Clusters Resources

	// Routes are items in the RDS response payload.
	Routes Resources

	// Listeners are items in the LDS response payload.
	Listeners Resources
}

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

func NewSnapshot

func NewSnapshot(version string,
	endpoints []Resource,
	clusters []Resource,
	routes []Resource,
	listeners []Resource) Snapshot

NewSnapshot creates a snapshot from response types and a version.

func (*Snapshot) Consistent

func (s *Snapshot) Consistent() error

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.

func (*Snapshot) GetResources

func (s *Snapshot) GetResources(typ string) map[string]Resource

GetResources selects snapshot resources by type.

func (*Snapshot) GetVersion

func (s *Snapshot) GetVersion(typ string) string

GetVersion returns the version for a resource type.

type SnapshotCache

type SnapshotCache interface {
	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

	// ClearSnapshot removes all status and snapshot information associated with a node.
	ClearSnapshot(node 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 NodeHash, logger 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), mutliple partial requests are sent across multiple streams and re-using the snapshot version is OK.

Logger is optional.

type StatusInfo

type StatusInfo interface {
	// GetNode returns the node metadata.
	GetNode() *core.Node

	// GetNumWatches returns the number of open watches.
	GetNumWatches() int

	// GetLastWatchRequestTime returns the timestamp of the last discovery watch request.
	GetLastWatchRequestTime() time.Time
}

StatusInfo tracks the server state for the remote Envoy node. Not all fields are used by all cache implementations.

Jump to

Keyboard shortcuts

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