Documentation ¶
Overview ¶
Package cache defines a configuration cache for the server.
Index ¶
- func GetResourceName(res types.Resource) string
- func GetResourceReferences(resources map[string]types.ResourceWithTtl) map[string]bool
- func GetResponseType(typeURL string) types.ResponseType
- func IndexResourcesByName(items []types.ResourceWithTtl) map[string]types.ResourceWithTtl
- func MarshalResource(resource types.Resource) (types.MarshaledResource, error)
- type Cache
- type ConfigFetcher
- type ConfigWatcher
- type IDHash
- type LinearCache
- func (cache *LinearCache) CreateWatch(request *Request) (chan Response, func())
- func (cache *LinearCache) DeleteResource(name string) error
- func (cache *LinearCache) Fetch(ctx context.Context, request *Request) (Response, error)
- func (cache *LinearCache) NumWatches(name string) int
- func (cache *LinearCache) UpdateResource(name string, res types.Resource) error
- type LinearCacheOption
- type MuxCache
- type NodeHash
- type PassthroughResponse
- type RawResponse
- type Request
- type ResourceWithTtl
- type Resources
- type Response
- type ResponseWatch
- type Snapshot
- type SnapshotCache
- type SnapshotResources
- type StatusInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetResourceName ¶
GetResourceName returns the resource name for a valid xDS response type.
func GetResourceReferences ¶
func GetResourceReferences(resources map[string]types.ResourceWithTtl) map[string]bool
GetResourceReferences returns the names for dependent resources (EDS cluster names for CDS, RDS routes names for LDS).
func GetResponseType ¶
func GetResponseType(typeURL string) types.ResponseType
GetResponseType returns the enumeration for a valid xDS type URL
func IndexResourcesByName ¶
func IndexResourcesByName(items []types.ResourceWithTtl) map[string]types.ResourceWithTtl
IndexResourcesByName creates a map from the resource name to the resource.
func MarshalResource ¶
func MarshalResource(resource types.Resource) (types.MarshaledResource, error)
MarshalResource converts the Resource to MarshaledResource
Types ¶
type Cache ¶
type Cache interface { ConfigWatcher ConfigFetcher }
Cache is a generic config cache with a watcher.
type ConfigFetcher ¶ added in v2.3.0
type ConfigFetcher interface { // Fetch implements the polling method of the config cache using a non-empty request. Fetch(context.Context, *Request) (Response, error) }
ConfigFetcher fetches configuration resources from cache
type ConfigWatcher ¶
type ConfigWatcher interface { // CreateWatch returns a new open watch from a non-empty request. // An individual consumer normally issues a single open watch by each type URL. // // 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 LinearCache ¶ added in v2.3.0
type LinearCache struct {
// contains filtered or unexported fields
}
LinearCache supports collectons of opaque resources. This cache has a single collection indexed by resource names and manages resource versions internally. It implements the cache interface for a single type URL and should be combined with other caches via type URL muxing. It can be used to supply EDS entries, for example, uniformly across a fleet of proxies.
func NewLinearCache ¶ added in v2.3.0
func NewLinearCache(typeURL string, opts ...LinearCacheOption) *LinearCache
NewLinearCache creates a new cache. See the comments on the struct definition.
func (*LinearCache) CreateWatch ¶ added in v2.3.0
func (cache *LinearCache) CreateWatch(request *Request) (chan Response, func())
func (*LinearCache) DeleteResource ¶ added in v2.3.0
func (cache *LinearCache) DeleteResource(name string) error
DeleteResource removes a resource in the collection.
func (*LinearCache) NumWatches ¶ added in v2.3.0
func (cache *LinearCache) NumWatches(name string) int
Number of active watches for a resource name.
func (*LinearCache) UpdateResource ¶ added in v2.3.0
func (cache *LinearCache) UpdateResource(name string, res types.Resource) error
UpdateResource updates a resource in the collection.
type LinearCacheOption ¶ added in v2.3.0
type LinearCacheOption func(*LinearCache)
Options for modifying the behavior of the linear cache.
func WithInitialResources ¶ added in v2.3.0
func WithInitialResources(resources map[string]types.Resource) LinearCacheOption
WithInitialResources initializes the initial set of resources.
func WithVersionPrefix ¶ added in v2.3.0
func WithVersionPrefix(prefix string) LinearCacheOption
WithVersionPrefix sets a version prefix of the form "prefixN" in the version info. Version prefix can be used to distinguish replicated instances of the cache, in case a client re-connects to another instance.
type MuxCache ¶ added in v2.3.0
type MuxCache struct { // Classification functions. Classify func(Request) string // Muxed caches. Caches map[string]Cache }
MuxCache multiplexes across several caches using a classification function. If there is no matching cache for a classification result, the cache responds with an empty closed channel, which effectively terminates the stream on the server. It might be preferred to respond with a "nil" channel instead which will leave the stream open in case the stream is aggregated by making sure there is always a matching cache.
func (*MuxCache) CreateWatch ¶ added in v2.3.0
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 PassthroughResponse ¶
type PassthroughResponse struct { // Request is the original request. Request *discovery.DiscoveryRequest // The discovery response that needs to be sent as is, without any marshalling transformations. DiscoveryResponse *discovery.DiscoveryResponse }
PassthroughResponse is a pre constructed xDS response that need not go through marshalling transformations.
func (*PassthroughResponse) GetDiscoveryResponse ¶
func (r *PassthroughResponse) GetDiscoveryResponse() (*discovery.DiscoveryResponse, error)
GetDiscoveryResponse returns the final passthrough Discovery Response.
func (*PassthroughResponse) GetRequest ¶
func (r *PassthroughResponse) GetRequest() *discovery.DiscoveryRequest
GetRequest returns the original Discovery Request
func (*PassthroughResponse) GetVersion ¶
func (r *PassthroughResponse) GetVersion() (string, error)
GetVersion returns the response version.
type RawResponse ¶
type RawResponse struct { // Request is the original request. Request *discovery.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 []types.ResourceWithTtl // Whether this is a heartbeat response. For xDS versions that support TTL, this // will be converted into a response that doesn't contain the actual resource protobuf. // This allows for more lightweight updates that server only to update the TTL timer. Heartbeat bool // contains filtered or unexported fields }
RawResponse is a pre-serialized xDS response containing the raw resources to be included in the final Discovery Response.
func (*RawResponse) GetDiscoveryResponse ¶
func (r *RawResponse) GetDiscoveryResponse() (*discovery.DiscoveryResponse, error)
GetDiscoveryResponse performs the marshalling the first time its called and uses the cached response subsequently. This is necessary because the marshalled response does not change across the calls. This caching behavior is important in high throughput scenarios because grpc marshalling has a cost and it drives the cpu utilization under load.
func (*RawResponse) GetRequest ¶
func (r *RawResponse) GetRequest() *discovery.DiscoveryRequest
GetRequest returns the original Discovery Request.
func (*RawResponse) GetVersion ¶
func (r *RawResponse) GetVersion() (string, error)
GetVersion returns the response version.
type Request ¶
type Request = discovery.DiscoveryRequest
Request is an alias for the discovery request type.
type ResourceWithTtl ¶ added in v2.3.0
type Resources ¶
type Resources struct { // Version information. Version string // Items in the group indexed by name. Items map[string]types.ResourceWithTtl }
Resources is a versioned group of resources.
func NewResources ¶
NewResources creates a new resource group.
func NewResourcesWithTtl ¶ added in v2.3.0
func NewResourcesWithTtl(version string, items []types.ResourceWithTtl) Resources
NewResources creates a new resource group.
type Response ¶
type Response interface { // Get the Constructed DiscoveryResponse GetDiscoveryResponse() (*discovery.DiscoveryResponse, error) // Get the original Request for the Response. GetRequest() *discovery.DiscoveryRequest // Get the version in the Response. GetVersion() (string, error) }
Response is a wrapper around Envoy's DiscoveryResponse.
type ResponseWatch ¶
type ResponseWatch struct { // Request is the original request for the watch. Request *Request // Response is the channel to push responses 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 {
Resources [types.UnknownType]Resources
}
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.
func NewSnapshot ¶
func NewSnapshot(version string, endpoints []types.Resource, clusters []types.Resource, routes []types.Resource, listeners []types.Resource, runtimes []types.Resource, secrets []types.Resource) Snapshot
NewSnapshot creates a snapshot from response types and a version.
func NewSnapshotWithResources ¶ added in v2.3.0
func NewSnapshotWithResources(version string, resources SnapshotResources) Snapshot
NewSnapshotWithResources creates a snapshot from response types and a version.
func NewSnapshotWithTtls ¶ added in v2.3.0
func NewSnapshotWithTtls(version string, endpoints []types.ResourceWithTtl, clusters []types.ResourceWithTtl, routes []types.ResourceWithTtl, listeners []types.ResourceWithTtl, runtimes []types.ResourceWithTtl, secrets []types.ResourceWithTtl) Snapshot
func (*Snapshot) Consistent ¶
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 ¶
GetResources selects snapshot resources by type, returning the map of resources.
func (*Snapshot) GetResourcesAndTtl ¶ added in v2.3.0
func (s *Snapshot) GetResourcesAndTtl(typeURL string) map[string]types.ResourceWithTtl
GetResourcesAndTtl selects snapshot resources by type, returning the map of resources and the associated TTL.
func (*Snapshot) GetVersion ¶
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 // 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) 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 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), multiple partial requests are sent across multiple streams and re-using the snapshot version is OK.
Logger is optional.
func NewSnapshotCacheWithHeartbeating ¶ added in v2.3.0
func NewSnapshotCacheWithHeartbeating(ctx context.Context, ads bool, hash NodeHash, logger 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 SnapshotResources ¶ added in v2.3.0
type SnapshotResources struct { Endpoints []types.Resource Clusters []types.Resource Routes []types.Resource Listeners []types.Resource Runtimes []types.Resource Secrets []types.Resource ExtensionConfigs []types.Resource }
SnapshotResources contains the resources to construct a snapshot from.
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.