diderot

package module
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: BSD-2-Clause Imports: 21 Imported by: 0

README

Diderot

(pronounced dee-duh-row)


Diderot is a server implementation of the xDS protocol that makes it extremely easy and efficient to implement a control plane for your Envoy and gRPC services. For the most up-to-date information, please visit the documentation.

Quick Start Guide

The only thing you need to implement to make your resources available via xDS is a diderot.ResourceLocator(link). It is the interface exposed by the ADS server implementation which should contain the business logic of all your resource definitions and how to find them. To facilitate this implementation, Diderot provides an efficient, low-resource cache that supports highly concurrent updates. By leveraging the cache implementation for the heavy lifting, you will be able to focus on the meaningful part of operating your own xDS control plane: your resource definitions.

Once you have implemented your ResourceLocator, you can simply drop in a diderot.ADSServer to your gRPC service, and you're ready to go! Please refer to the examples/quickstart package

Features

Diderot's ADS server implementation is a faithful implementation of the xDS protocol. This means it implements both the State-of-the-World and Delta/Incremental variants. It supports advanced features such as glob collections, unlocking the more efficient alternative to the EDS stage: LEDS (design doc).

Documentation

Overview

Package diderot provides a set of utilities to implement an xDS control plan in go. Namely, it provides two core elements:

  1. The ADSServer, the implementation of both the SotW and Delta ADS stream variants.
  2. The Cache, which is an efficient means to store, retrieve and subscribe to xDS resource definitions.

ADS Server and Resource Locator

The ADSServer is an implementation of the xDS protocol's various features. It implements both the Delta and state-of-the-world variants, but abstracts this away completely by only exposing a single entry point: the ResourceLocator. When the server receives a request (be it Delta or SotW), it will check whether it is an ACK (or a NACK), then invoke the corresponding subscription methods on the ResourceLocator. The locator is simply in charge of invoking Notify on the handler whenever the resource changes, and the server will relay that resource update to the client using the corresponding response type. This makes it very easy to implement an xDS control plane without needing to worry about the finer details of the xDS protocol.

Most ResourceLocator implementations will likely be a series of Cache instances for the corresponding supported types, which implements the semantics of Subscribe and Resubscribe out of the box. However, as long as the semantics are respected, implementations may do as they please. For example, a common pattern is listed in the xDS spec:

For Listener and Cluster resource types, there is also a “wildcard” subscription, which is triggered
when subscribing to the special name *. In this case, the server should use site-specific business
logic to determine the full set of resources that the client is interested in, typically based on
the client’s node identification.

Instead of invoking subscribing to a backing Cache with the wildcard subscription, the said "business logic" can be implemented in the ResourceLocator and wildcard subscriptions can be transformed into an explicit set of resources.

Cache

This type is the core building block provided by this package. It is effectively a map from resource name to ads.Resource definitions. It provides a way to subscribe to them in order to be notified whenever they change. For example, the ads.Endpoint type (aka "envoy.config.endpoint.v3.ClusterLoadAssignment") contains the set of IPs that back a specific ads.Cluster ("envoy.config.cluster.v3.Cluster") and is the final step in the standard LDS -> RDS -> CDS -> EDS Envoy flow. The Cache will store the Endpoint instances that back each cluster, and Envoy will be able to subscribe to the ads.Endpoint resource by providing the correct name when subscribing. See diderot.Cache.Subscribe for additional details on the subscription model.

It is safe for concurrent use as its concurrency model is per-resource. This means different goroutines can modify different resources concurrently, and goroutines attempting to modify the same resource will be synchronized.

Cache Priority

The cache supports a notion of "priority". Concretely, this feature is intended to be used when a resource definition can come from multiple sources. For example, if resource definitions are being migrated from one source to another, it would be sane to always use the new source if it is present, otherwise fall back to the old source. This would be as opposed to simply picking whichever source defined the resource most recently, as it would mean the resource definition cannot be relied upon to be stable. NewPrioritizedCache returns a slice of instances of their respective types. The instances all point to the same underlying cache, but at different priorities, where instances that appear earlier in the slice have a higher priority than those that appear later. If a resource is defined at priorities p1 and p2 where p1 is a higher priority than p2, subscribers will see the version that was defined at p1. If the resource is cleared at p1, the cache will fall back to the definition at p2. This means that a resource is only ever considered fully deleted if it is cleared at all priority levels. The reason a slice of instances is returned rather than adding a priority parameter to each function on Cache is to avoid complicated configuration or simple bugs where a resource is being set at an unintended or invalid priority. Instead, the code path where a source is populating the cache simply receives a reference to the cache and starts writing to it. If the priority of a source changes in subsequent versions, it can be handled at initialization/startup instead of requiring any actual code changes to the source itself.

xDS TP1 Support

The notion of glob collections defined in the TP1 proposal is supported natively in the Cache. This means that if resource names are xdstp:// URNs, they will be automatically added to the corresponding glob collection, if applicable. These resources are still available for subscription by their full URN, but will also be available for subscription by subscribing to the parent glob collection. More details available at diderot.Cache.Subscribe, ads.ParseGlobCollectionURL and ads.ParseGlobCollectionURN.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSubscribedTo

func IsSubscribedTo(c RawCache, name string, handler ads.RawSubscriptionHandler) bool

IsSubscribedTo checks whether the given handler is subscribed to the given named resource by invoking the underlying generic API diderot.Cache.IsSubscribedTo.

func NodeFromContext

func NodeFromContext(streamCtx context.Context) (*ads.Node, bool)

NodeFromContext returns the ads.Node in the given context, if it exists. Note that the ADSServer will always provide the Node in the context when invoking methods on the ResourceLocator.

func Subscribe

func Subscribe(c RawCache, name string, handler ads.RawSubscriptionHandler)

Subscribe registers the handler as a subscriber of the given named resource by invoking the underlying generic API diderot.Cache.Subscribe.

func Unsubscribe

func Unsubscribe(c RawCache, name string, handler ads.RawSubscriptionHandler)

Unsubscribe unregisters the handler as a subscriber of the given named resource by invoking the underlying generic API diderot.Cache.Unsubscribe.

func Watch added in v0.2.0

func Watch[T proto.Message](c *ADSClient, name string, watcher Watcher[T])

Watch registers the given watcher in the given client, triggering a subscription (if necessary) for the given resource name such that the Watcher will be notified whenever the resource is updated. If a resource is already known (for example from a previous existing subscription), the watcher will be immediately notified. Glob or wildcard subscriptions are supported, and [Watcher.Notify] will be invoked with a sequence that iterates over all the updated resources.

Types

type ADSClient added in v0.2.0

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

An ADSClient is a client that implements the xDS protocol, and can therefore be used to talk to any xDS backend. Use the Watch, [WatchGlob] and [WatchWildcard] to subscribe to resources.

func NewADSClient added in v0.2.0

func NewADSClient(conn grpc.ClientConnInterface, node *ads.Node, opts ...ADSClientOption) *ADSClient

NewADSClient creates a new *ADSClient with the given options. To stop the client, close the backing grpc.ClientConn.

type ADSClientOption added in v0.2.0

type ADSClientOption func(*options)

func WithReconnectBackoff added in v0.2.0

func WithReconnectBackoff(initialBackoff, maxBackoff time.Duration) ADSClientOption

WithReconnectBackoff provides backoff configuration when reconnecting to the xDS backend after a connection failure. The default settings are 100ms and 2m for the initial and max backoff respectively.

func WithResponseChunkingSupported added in v0.2.0

func WithResponseChunkingSupported(supported bool) ADSClientOption

WithResponseChunkingSupported changes whether response chunking should be supported (see ads.ParseRemainingChunksFromNonce for additional details). This feature is only provided by the ADSServer implemented in this package. This enabled by default.

type ADSServer

type ADSServer struct {
	discovery.UnimplementedAggregatedDiscoveryServiceServer
	// contains filtered or unexported fields
}

An ADSServer is an implementation of the xDS protocol. It implements the tricky parts of an xDS control plane such as managing subscriptions, parsing the incoming ads.SotWDiscoveryRequest and ads.DeltaDiscoveryRequest, etc. The actual business logic of locating the resources is injected via the given ResourceLocator.

func NewADSServer

func NewADSServer(locator ResourceLocator, options ...ADSServerOption) *ADSServer

NewADSServer creates a new *ADSServer with the given options.

func (*ADSServer) DeltaAggregatedResources

func (s *ADSServer) DeltaAggregatedResources(stream ads.DeltaStream) (err error)

DeltaAggregatedResources is the implementation of the delta/incremental variant of the ADS protocol.

func (*ADSServer) GetGlobalResponseRateLimit

func (s *ADSServer) GetGlobalResponseRateLimit() rate.Limit

GetGlobalResponseRateLimit returns the current global response rate limit.

func (*ADSServer) GetGranularResponseRateLimit

func (s *ADSServer) GetGranularResponseRateLimit() rate.Limit

GetGranularResponseRateLimit returns the current granular response rate limit.

func (*ADSServer) GetRequestRateLimit

func (s *ADSServer) GetRequestRateLimit() rate.Limit

GetRequestRateLimit returns the current incoming request rate limit.

func (*ADSServer) SetGlobalResponseRateLimit

func (s *ADSServer) SetGlobalResponseRateLimit(newLimit rate.Limit)

SetGlobalResponseRateLimit updates the global response rate limit. If the given limit is 0, negative or rate.Inf, it disables the rate limiting.

func (*ADSServer) SetGranularResponseRateLimit

func (s *ADSServer) SetGranularResponseRateLimit(newLimit rate.Limit)

SetGranularResponseRateLimit updates the granular response rate limit. If the given limit is 0, negative or rate.Inf, it disables the rate limiting.

func (*ADSServer) SetRequestRateLimit

func (s *ADSServer) SetRequestRateLimit(newLimit rate.Limit)

SetRequestRateLimit updates the incoming request rate limit. If the given limit is 0, negative or rate.Inf, it disables the rate limiting.

func (*ADSServer) StreamAggregatedResources

func (s *ADSServer) StreamAggregatedResources(stream ads.SotWStream) (err error)

StreamAggregatedResources is the implementation of the state-of-the-world variant of the ADS protocol.

type ADSServerOption

type ADSServerOption interface {
	// contains filtered or unexported methods
}

ADSServerOption configures how the ADS Server is initialized.

func WithControlPlane

func WithControlPlane(controlPlane *corev3.ControlPlane) ADSServerOption

WithControlPlane causes the server to include the given corev3.ControlPlane instance in each response.

func WithGlobalResponseRateLimit

func WithGlobalResponseRateLimit(globalLimit rate.Limit) ADSServerOption

WithGlobalResponseRateLimit enforces a maximum rate at which the server will respond to clients. This prevents clients from being overloaded with responses and throttles the resource consumption on the server. If not specified, 0 or rate.Inf is provided, this feature is disabled.

func WithGranularResponseRateLimit

func WithGranularResponseRateLimit(granularLimit rate.Limit) ADSServerOption

WithGranularResponseRateLimit is an additional layer of rate limiting to the one provided by WithGlobalResponseRateLimit. If specified, it will be applied to each resource type requested by each client. For example, a client can receive updates to its LDS, RDS, CDS and EDS subscriptions at a rate of 10 responses per second per type, for a potential maximum rate of 40 responses per second since it is subscribed to 4 individual types. When determining how long a response should be stalled however, the server computes the wait time required to satisfy both limits and picks the largest one. This means this granular limit cannot override the global limit. If not specified, this feature is disabled.

func WithMaxDeltaResponseSize

func WithMaxDeltaResponseSize(maxResponseSize int) ADSServerOption

WithMaxDeltaResponseSize limits the size of responses sent by the server when the Delta variant of the xDS protocol is being used. As it builds the response from the set of resource updates it wants to send, the server will check how large the serialized message will be, stopping before it reaches the threshold. It then sends the chunk it has built up until this point before restarting the process over until the desired set of updates is sent. Note that this cannot be implemented for SotW protocols due to the nature of the protocol itself. The configuration is ignored if 0 and is disabled by default.

func WithRequestRateLimit

func WithRequestRateLimit(limit rate.Limit) ADSServerOption

WithRequestRateLimit sets the rate limiting parameters for client requests. When a client's request is being limited, it will block all other requests for that client until the rate limiting expires. If not specified, 0 or rate.Inf is provided, this feature is disabled.

func WithSendBufferSizeEstimator added in v0.2.9

func WithSendBufferSizeEstimator(sizeEstimator SendBufferSizeEstimator) ADSServerOption

WithSendBufferSizeEstimator provides a SendBufferSizeEstimator that will be invoked when the ADSServer responds to subscription requests.

func WithServerStatsHandler

func WithServerStatsHandler(statsHandler serverstats.Handler) ADSServerOption

WithServerStatsHandler registers a stats handler for the server. The given handler will be invoked whenever a corresponding event happens. See the [stats] package for more details.

type Cache

type Cache[T proto.Message] interface {
	RawCache
	// Set stores the given resource in the cache. If the resource name corresponds to a resource URN, it
	// will also be stored in the corresponding glob collection (see [TP1 proposal] for additional
	// details on the format). See Subscribe for more details on how the resources added by this method
	// can be subscribed to. Invoking Set whenever possible is preferred to RawCache.SetRaw, since it can
	// return an error if the given resource's type does not match the expected type while Set validates
	// at compile time that the given value matches the desired type. A zero [time.Time] can be used to
	// represent that the time at which the resource was created or modified is unknown (or ignored).
	//
	// WARNING: It is imperative that the Resource and the underlying [proto.Message] not be modified
	// after insertion! This resource will be read by subscribers to the cache and callers of Get, and
	// modifying the resource may at best result in incorrect reads for consumers and at worst panics if
	// the consumer is reading a map as it's being modified. When in doubt, callers should pass in a deep
	// copy of the resource. Note that the cache takes no responsibility in enforcing this since cloning
	// every resource as it is inserted in the cache may incur unexpected and avoidable costs.
	//
	// [TP1 proposal]: https://github.com/cncf/xds/blob/main/proposals/TP1-xds-transport-next.md#uri-based-xds-resource-names
	Set(name, version string, t T, modifiedAt time.Time) *ads.Resource[T]
	// SetResource is the more verbose equivalent of Set which supports the additional fields in [ads.Resource].
	SetResource(r *ads.Resource[T], modifiedAt time.Time)
	// Get fetches the entry, or nil if it's not present and/or has been deleted.
	Get(name string) *ads.Resource[T]
	// IsSubscribedTo checks whether the given handler is subscribed to the given named entry.
	IsSubscribedTo(name string, handler ads.SubscriptionHandler[T]) bool
	// Subscribe registers the handler as a subscriber of the given named resource. The handler is always
	// immediately called with the current values of the entries selected by this call, even if it was
	// already subscribed.
	//
	// If the name is ads.WildcardSubscription, the handler is registered as a wildcard subscriber. This
	// means the handler will be subscribed to all existing entries, and be automatically subscribed to
	// any new entries until a corresponding call to Unsubscribe is made.
	//
	// If the name is a glob collection URL, the handler will be subscribed to all entries in the
	// collection, along with being automatically subscribed to any new entries. If the collection is
	// empty, the handler will receive a deletion notification for the entire collection. This behavior
	// is defined in the [TP1 proposal]:
	//	If no resources are present in the glob collection, the server should reply with a
	//	DeltaDiscoveryResponse in which the glob collection URL is specified in removed_resources.
	// The subscription will be preserved even if the glob collection is empty (or becomes empty) until a
	// corresponding call to Unsubscribe is made.
	//
	// Otherwise, the handler will be subscribed to the resource specified by the given name and receive
	// notifications any time the resource changes. If a resource by that name does not exist, the
	// handler will immediately receive a deletion notification, but will not be unsubscribed until a
	// corresponding call to Unsubscribe is made. See the [spec on deletions] for more details.
	//
	// Note that there are therefore three ways to subscribe to a given resource:
	//  1. The simplest way is to explicitly subscribe to a resource, via its name. Such a subscription is
	//     it can only be cancelled with a corresponding call to Unsubscribe. It will not, for example, be
	//     cancelled by unsubscribing from the wildcard. This is by design, as it allows clients to discover
	//     resources by emitting a wildcard subscription, finding which resources they are interested in,
	//     explicitly subscribing to those then removing the implicit subscriptions to other resources by
	//     unsubscribing from the wildcard. This is outlined in the [sample xDS flows].
	//  2. If the resource's name is a URN, a subscription to the matching glob collection URL will
	//     subscribe the given handler to the resource. Similar to the explicit subscription listed in 1.,
	//     unsubscribing from the wildcard will not cancel a glob collection to a resource, only a
	//     corresponding unsubscription to the collection will cancel it.
	//  3. A wildcard subscription will also implicitly create a subscription to the resource.
	//     subscribe
	//
	// Note that while the xDS docs are clear on what the behavior should be when a subscription is
	// "upgraded" from a wildcard subscription to an explicit subscription, they are not clear as to what
	// happens when a subscription is "downgraded". For example, if a client subscribes to a resource "A"
	// then subscribes to the wildcard, should an unsubscription from the wildcard cancel the
	// subscription to "A"? Similarly, the docs are unclear as to what should happen if a client
	// subscribes to the wildcard, then subscribes to resource "A", then unsubscribes from "A". Should
	// the original implicit subscription to "A" via the wildcard be honored? To address both of these,
	// the cache will preserve all subscriptions that target a specific resource. This means a client that
	// subscribed to a resource both via a wildcard and an explicit subscription (regardless of order) will
	// only be unsubscribed from that resource once it has both explicitly unsubscribed from the resource and
	// unsubscribed from the wildcard (regardless of order).
	//
	// It is unsafe for multiple goroutines to invoke Subscribe and/or Unsubscribe with the same
	// SubscriptionHandler, and will result undefined behavior.
	//
	// [TP1 proposal]: https://github.com/cncf/xds/blob/main/proposals/TP1-xds-transport-next.md#glob
	// [sample xDS flows]: https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol#how-the-client-specifies-what-resources-to-return
	// [spec on deletions]: https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol#id2
	Subscribe(name string, handler ads.SubscriptionHandler[T])
	// Unsubscribe removes the given handler from the named entry's list of subscribers.
	//
	// If the given name is ads.WildcardSubscription, the handler is unsubscribed from all entries it did
	// not explicitly subscribe to (see definition of explicit subscription in Subscribe).
	//
	// If the given name is a glob collection URL, it is unsubscribed from the collection, unsubscribing
	// it from all matching entries.
	//
	// Noop if the resource does not exist or the handler was not subscribed to it.
	Unsubscribe(name string, handler ads.SubscriptionHandler[T])
}

Cache is the primary type provided by this package. It provides an efficient storage mechanism for ads.RawResource objects, and the means to subscribe to them via the SubscriptionHandler interface. For example, it can be used to store the set of "envoy.config.listener.v3.Listener" available to clients.

func NewCache

func NewCache[T proto.Message]() Cache[T]

NewCache returns a simple Cache with only 1 priority (see NewPrioritizedCache).

func NewPrioritizedCache

func NewPrioritizedCache[T proto.Message](prioritySlots int) []Cache[T]

NewPrioritizedCache creates a series of Cache accessors that all point to the same underlying cache, but have different "priorities". The Cache object that appears first in the returned slice has the highest priority, with every subsequent Cache having correspondingly lower priority. If the same resource is provided by two Caches, the resource defined by the Cache with the highest priority will be provided to subscribers and returned by Cache.GetResource. Conversely, if a Cache with a high priority clears a resource, the underlying cache will fall back to lower priority definitions if present. A resource is only fully cleared if it is cleared at all priority levels.

Concretely, this feature is intended to be used when a resource definition can come from multiple sources. For example, if resource definitions are being migrated from one source to another, it would be sane to always use the new source if it is present, otherwise fall back to the old source. This would be as opposed to simply picking whichever source defined the resource most recently, as it would mean the resource definition is nondeterministic.

type RawCache

type RawCache interface {
	// Type returns the corresponding [Type] for this cache.
	Type() Type
	// EntryNames returns an [iter.Seq] that will iterate over all the current entry names in the cache.
	EntryNames() iter.Seq[string]
	// GetRaw is the untyped equivalent of Cache.Get. There are uses for this method, but the preferred
	// way is to use Cache.Get because this function incurs the cost of marshaling the resource. Returns
	// an error if the resource cannot be marshaled.
	GetRaw(name string) (*ads.RawResource, error)
	// SetRaw is the untyped equivalent of Cache.Set. There are uses for this method, but the preferred
	// way is to use Cache.Set since it offers a typed API instead of the untyped ads.RawResource parameter.
	// Subscribers will be notified of the new version of this resource. See Cache.Set for additional
	// details on how the resources are stored. Returns an error if the given resource's type URL does
	// not match the expected type URL, or the resource cannot be unmarshaled.
	SetRaw(r *ads.RawResource, modifiedAt time.Time) error
	// Clear clears the entry (if present) and notifies all subscribers that the entry has been deleted.
	// A zero [time.Time] can be used to represent that the time at which the resource was cleared is
	// unknown (or ignored). For example, when watching a directory, the filesystem does not keep track
	// of when the file was deleted.
	Clear(name string, clearedAt time.Time)
	// EstimateSubscriptionSize estimates the number of resources targeted by the given list of
	// subscriptions. This is only an estimation since the resource count is dynamic, and repeated
	// invocations of this function with the same parameters may not yield the same results.
	EstimateSubscriptionSize(resourceNamesSubscribe []string) int
}

RawCache is a subset of the Cache interface and provides a number of methods to interact with the Cache without needing to know the underlying resource type at compile time. All RawCache implementations *must* also implement Cache for the underlying resource type.

type ResourceLocator

type ResourceLocator interface {
	// Subscribe subscribes the given handler to the desired resource. The returned function should
	// execute the unsubscription to the resource. The desired behavior when a client resubscribes to a
	// resource is for the resource to be re-sent. To achieve this, the returned unsubscription function
	// will be called, then [Subscribe] will be called again with the same parameters. Additionally, this
	// function should only return when the given subscription handler has received the notification(s)
	// for the corresponding subscription(s). It allows the server implementation to correctly batch
	// resources for more efficient responses, as well as skip the granular limiter (if enabled). This is
	// especially important during the initial bulk subscriptions a client will emit at startup.
	//
	// Note: There is no clear provision in the protocol for what to do if a client sends a request for a
	// type that is unsupported by this server. Therefore, this is not explicitly handled by the Server.
	// Instead, the implementation of this function may choose to either do nothing, or send back a
	// deletion notification for the requested resources whose types are not supported.
	Subscribe(
		streamCtx context.Context,
		typeURL, resourceName string,
		handler ads.RawSubscriptionHandler,
	) (unsubscribe func())
}

The ResourceLocator abstracts away the business logic used to locate resources and subscribe to them. For example, while Subscribe is trivially implemented with a Cache which only serves static predetermined resources, it could be implemented to instead generate a resource definition on the fly, based on the client's attributes. Alternatively, for example, some attribute in the client's ads.Node may show that the client does not support IPv6 and should instead be shown IPv4 addresses in the ads.Endpoint response.

Many users of this library may also choose to implement a google.golang.org/grpc.StreamServerInterceptor to populate additional values in the stream's context, which can be used to better identify the client. However, for convenience, the ads.Node provided in the request will always be provided in the stream context, and can be accessed with NodeFromContext.

type SendBufferSizeEstimator added in v0.2.9

type SendBufferSizeEstimator interface {
	// EstimateSubscriptionSize returns the expected number of resources that will be sent back as a
	// result of the given resource names.
	EstimateSubscriptionSize(streamCtx context.Context, typeURL string, resourceNamesSubscribe []string) int
}

A SendBufferSizeEstimator is used to estimate a size to pre-allocate the send buffer used by the ADSServer. More specifically, when the server responds to a subscription request, it will use a map to buffer the resources that correspond to the newly added subscriptions until all subscriptions are processed. This helps limit the number of responses sent.

Depending on the size of the subscription (e.g. a wildcard subscription will target many resources), adding each resource to the map will grow the map, resulting in repeated copies and lots of memory movement. As such, the estimator, if provided, will be invoked by the server to determine the size of the send buffer map to create, in order to hopefully avoid expensive re-allocations.

However, if the client provides initial resource versions along with its subscription request, the estimator will not be invoked, as it may result in pre-allocating a very large map that will likely not be fully utilized.

For convenience, this is trivially implemented by [RawCache.EstimateSubscriptionSize].

type Type

type Type interface {
	// URL returns the type URL for this Type.
	URL() string
	// TrimmedURL returns the type URL for this Type without the leading "types.googleapis.com/" prefix.
	// This string is useful when constructing xdstp URLs.
	TrimmedURL() string
	// NewCache is the untyped equivalent of this package's NewCache. The returned RawCache still
	// retains the runtime type information and can be safely cast to the corresponding Cache type.
	NewCache() RawCache
	// NewPrioritizedCache is the untyped equivalent of this package's NewPrioritizedCache. The returned
	// RawCache instances can be safely cast to the corresponding Cache type.
	NewPrioritizedCache(prioritySlots int) []RawCache
	// contains filtered or unexported methods
}

Type is a type reference for a type that can be cached. Only accessible through TypeOf.

type TypeReference

type TypeReference[T proto.Message] interface {
	Type
}

TypeReference is a superset of the Type interface which captures the actual runtime type.

func TypeOf

func TypeOf[T proto.Message]() TypeReference[T]

TypeOf returns a TypeReference that corresponds to the type parameter.

type Watcher added in v0.2.0

type Watcher[T proto.Message] interface {
	// Notify is invoked whenever a response is processed. The given sequence will iterate over all the
	// resources in the response, with a nil resource indicating a deletion. Implementations should
	// return an error if any resource is invalid, and this error will be propagated as a NACK to the xDS
	// backend.
	Notify(resources iter.Seq2[string, *ads.Resource[T]]) error
}

A Watcher is used to receive updates from the xDS backend using an ADSClient. It is passed into the various Watch methods in this package. Note that it is imperative that implementations be hashable as it will be stored as the key to a map (unhashable types include slices and functions).

Directories

Path Synopsis
Package ads provides a set of utilities and definitions around the Aggregated Discovery Service xDS protocol (ADS), such as convenient type aliases, constants and core definitions.
Package ads provides a set of utilities and definitions around the Aggregated Discovery Service xDS protocol (ADS), such as convenient type aliases, constants and core definitions.
internal
stats

Jump to

Keyboard shortcuts

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