cache

package
v0.30.8 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: Apache-2.0 Imports: 15 Imported by: 19

Documentation

Overview

Package cache defines a configuration cache for the server.

Index

Constants

This section is empty.

Variables

View Source
var (
	MResponses = stats.Int64("xds/responses", "The responses for envoy", "1")

	KeyType = tag.MustNewKey("type")

	ResponsesView = &view.View{
		Name:        "xds/responses",
		Measure:     MResponses,
		Description: "The times gloo responded to xds request",
		Aggregation: view.Count(),
		TagKeys: []tag.Key{
			KeyType,
		},
	}

	VersionUpToDateError = errors.New("skip fetch: version up to date")
)

priority set for Envoy as listed here in Docs https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol#resource-warming

Functions

func IndexResourcesByName

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

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

func NewStatusInfo added in v0.17.4

func NewStatusInfo(node *envoy_config_core_v3.Node, prioritySet map[int][]string) *statusInfo

NewStatusInfo initializes a status info data structure.

func Superset

func Superset(names map[string]bool, resources map[string]Resource) error

Superset checks that all resources are listed in the names set.

func SupersetWithResource added in v0.25.0

func SupersetWithResource(names map[string]Resource, resources map[string]Resource) error

SupersetWithResource checks that all resources are listed in the names set.

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.

roughly copied from https://github.com/envoyproxy/go-control-plane/blob/dcf5642c8e54496938e0311fe9c48e39b609e583/pkg/cache/v3/cache.go#L72

type CacheSettings added in v0.20.6

type CacheSettings struct {
	// Ads identifies if xDS ADS service is being useds.
	Ads bool
	// Hash is the interface for hashing an Envoy node.
	Hash NodeHash
	// Logger is the logger used to log server information.
	Logger log.Logger
	// PrioritySet priorizes the response watches that the cache creates by their TypeURL.
	PrioritySet map[int][]string
}

CacheSettings are the settings used for a cache.

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.

roughly copied from https://github.com/envoyproxy/go-control-plane/blob/dcf5642c8e54496938e0311fe9c48e39b609e583/pkg/cache/v3/cache.go#L45

type GenericSnapshot

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

func NewEasyGenericSnapshot

func NewEasyGenericSnapshot(version string, resources ...[]Resource) *GenericSnapshot

func NewGenericSnapshot

func NewGenericSnapshot(resources TypedResources) *GenericSnapshot

NewSnapshot creates a snapshot from response types and a version.

func (*GenericSnapshot) Clone

func (s *GenericSnapshot) Clone() Snapshot

func (*GenericSnapshot) Combine

Combine snapshots with distinct types to one.

func (*GenericSnapshot) Consistent

func (s *GenericSnapshot) Consistent() error

func (*GenericSnapshot) GetResources

func (s *GenericSnapshot) GetResources(typ string) Resources

GetResources selects snapshot resources by type.

func (*GenericSnapshot) MakeConsistent added in v0.25.0

func (s *GenericSnapshot) MakeConsistent()

func (*GenericSnapshot) Merge

func (s *GenericSnapshot) Merge(newSnap *GenericSnapshot) (*GenericSnapshot, error)

Combine snapshots with distinct types to one.

type NilSnapshot

type NilSnapshot struct{}

func (NilSnapshot) Clone

func (NilSnapshot) Clone() Snapshot

func (NilSnapshot) Consistent

func (NilSnapshot) Consistent() error

func (NilSnapshot) GetResources

func (NilSnapshot) GetResources(typ string) Resources

func (NilSnapshot) MakeConsistent added in v0.25.0

func (NilSnapshot) MakeConsistent()

type NodeHash

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

NodeHash computes string identifiers for Envoy nodes.

type PriorityIndex added in v0.20.6

type PriorityIndex struct {
	Priority int
	Index    uint64
}

PriorityIndex is the priority and index used to locate items.

type PrioritySortedStruct added in v0.20.6

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

PrioritySortedStruct inserts elements into a map indexed in a list by prioirity. Priority lists are unordered. This allows O(1) inserts, gets, and deletes of these elements as long as the client has the index of the element. Indexes are returned on Add() function, when elements are added to the collection.

Elements interface the PriorityValue interface, this allows the collection to call the element to get it's priority. If a priority does not exist for an added element, it is added to the lowest priority.

The below 1, 2, 4 go first, 10 second, and 17 third. Anything else is processed last

{
	0: {item1, item2, item4}
	1: {item10}
	2: {item17}
}

func NewPrioritySortedStruct added in v0.20.6

func NewPrioritySortedStruct(prioritySets map[int][]string) *PrioritySortedStruct

NewPrioritySortedStruct creates a new Priority Sorted Struct. prioritySets is the set lists for priorities, where P is the type used for priority.

func (*PrioritySortedStruct) Add added in v0.20.6

Add will add the element to the Priority Collection, returns the priority, and element number.

func (*PrioritySortedStruct) Delete added in v0.20.6

func (p *PrioritySortedStruct) Delete(pi PriorityIndex) bool

Delete will delete the element, returns true if it deleted.

func (*PrioritySortedStruct) Get added in v0.20.6

Get returns the element at the index, and if it exists.

func (*PrioritySortedStruct) GetPriorityIndexes added in v0.20.6

func (p *PrioritySortedStruct) GetPriorityIndexes() []PriorityIndex

GetPriorityIndexes returns a list of all the indexes for all elements by priority.

func (*PrioritySortedStruct) GetPriorityList added in v0.20.6

func (p *PrioritySortedStruct) GetPriorityList() []ResponseWatch

GetPriorityList returns an ordered list of the elements by priority.

func (*PrioritySortedStruct) Len added in v0.20.6

func (p *PrioritySortedStruct) Len() int

Len will return the number of elements

func (*PrioritySortedStruct) Process added in v0.20.6

func (p *PrioritySortedStruct) Process(processFunc func(el ResponseWatch, pi PriorityIndex))

Process will call the procesFunc over all the elements by priority.

type PriorityValue added in v0.20.6

type PriorityValue interface {
	GetPriority() string
}

type Request

Request is an alias for the discovery request type.

type Resource

type Resource interface {
	Self() XdsResourceReference
	ResourceProto() ResourceProto
	References() []XdsResourceReference
}

type ResourceProto

type ResourceProto = proto.Message

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 envoy_service_discovery_v3.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.

func (ResponseWatch) GetPriority added in v0.20.6

func (rw ResponseWatch) GetPriority() string

type Snapshot

type Snapshot interface {
	Consistent() error
	// MakeConsistent should never be called on a generic snapshot as it is not used for snapshots with dependent resources.
	MakeConsistent()
	GetResources(typ string) Resources
	// Clone shouldn't be called on a generic snapshot until https://github.com/solo-io/solo-kit/issues/461 is resolved.
	Clone() Snapshot
}

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.
	//
	// based off of https://github.com/envoyproxy/go-control-plane/blob/v0.10.1/pkg/cache/v3/simple.go#L43-L49,
	// but updated to handle errors instead of returning them so Gloo Edge control plane can ensure xds snapshot
	// is always getting updates
	SetSnapshot(node string, snapshot Snapshot)

	// 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)
}

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.

roughly copied from https://github.com/envoyproxy/go-control-plane/blob/v0.10.1/pkg/cache/v3/simple.go#L40

func NewSnapshotCache

func NewSnapshotCache(settings CacheSettings) 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() *envoy_config_core_v3.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.

type TypedResources

type TypedResources map[string]Resources

type XdsResourceReference

type XdsResourceReference struct {
	Type string
	Name string
}

Jump to

Keyboard shortcuts

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