xdsclient

package
v1.56.0-dev Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package xdsclient implements a full fledged gRPC client for the xDS API used by the xds resolver and balancer implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearAllCountersForTesting added in v1.40.0

func ClearAllCountersForTesting()

ClearAllCountersForTesting clears all the counters. Should be only used in tests.

func ClearCounterForTesting

func ClearCounterForTesting(clusterName, edsServiceName string)

ClearCounterForTesting clears the counter for the service. Should be only used in tests.

func SetClient

func SetClient(state resolver.State, c XDSClient) resolver.State

SetClient sets c in state and returns the new state.

Types

type ClusterRequestsCounter added in v1.40.0

type ClusterRequestsCounter struct {
	ClusterName    string
	EDSServiceName string
	// contains filtered or unexported fields
}

ClusterRequestsCounter is used to track the total inflight requests for a service with the provided name.

func GetClusterRequestsCounter added in v1.40.0

func GetClusterRequestsCounter(clusterName, edsServiceName string) *ClusterRequestsCounter

GetClusterRequestsCounter returns the ClusterRequestsCounter with the provided serviceName. If one does not exist, it creates it.

func (*ClusterRequestsCounter) EndRequest added in v1.40.0

func (c *ClusterRequestsCounter) EndRequest()

EndRequest ends a request for a service, decrementing its number of requests by 1.

func (*ClusterRequestsCounter) StartRequest added in v1.40.0

func (c *ClusterRequestsCounter) StartRequest(max uint32) error

StartRequest starts a request for a cluster, incrementing its number of requests by 1. Returns an error if the max number of requests is exceeded.

type XDSClient

type XDSClient interface {
	WatchListener(string, func(xdsresource.ListenerUpdate, error)) func()
	WatchRouteConfig(string, func(xdsresource.RouteConfigUpdate, error)) func()
	WatchCluster(string, func(xdsresource.ClusterUpdate, error)) func()
	WatchEndpoints(string, func(xdsresource.EndpointsUpdate, error)) func()

	// WatchResource uses xDS to discover the resource associated with the
	// provided resource name. The resource type implementation determines how
	// xDS requests are sent out and how responses are deserialized and
	// validated. Upon receipt of a response from the management server, an
	// appropriate callback on the watcher is invoked.
	//
	// Most callers will not have a need to use this API directly. They will
	// instead use a resource-type-specific wrapper API provided by the relevant
	// resource type implementation.
	//
	//
	// During a race (e.g. an xDS response is received while the user is calling
	// cancel()), there's a small window where the callback can be called after
	// the watcher is canceled. Callers need to handle this case.
	//
	// TODO: Once this generic client API is fully implemented and integrated,
	// delete the resource type specific watch APIs on this interface.
	WatchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) (cancel func())

	// DumpResources returns the status of the xDS resources. Returns a map of
	// resource type URLs to a map of resource names to resource state.
	DumpResources() map[string]map[string]xdsresource.UpdateWithMD

	ReportLoad(*bootstrap.ServerConfig) (*load.Store, func())

	BootstrapConfig() *bootstrap.Config
}

XDSClient is a full fledged gRPC client which queries a set of discovery APIs (collectively termed as xDS) on a remote management server, to discover various dynamic resources.

func FromResolverState

func FromResolverState(state resolver.State) XDSClient

FromResolverState returns the Client from state, or nil if not present.

func New

func New() (XDSClient, func(), error)

New returns a new xDS client configured by the bootstrap file specified in env variable GRPC_XDS_BOOTSTRAP or GRPC_XDS_BOOTSTRAP_CONFIG.

The returned client is a reference counted singleton instance. This function creates a new client only when one doesn't already exist.

The second return value represents a close function which releases the caller's reference on the returned client. The caller is expected to invoke it once they are done using the client. The underlying client will be closed only when all references are released, and it is safe for the caller to invoke this close function multiple times.

func NewWithBootstrapContentsForTesting added in v1.45.0

func NewWithBootstrapContentsForTesting(contents []byte) (XDSClient, func(), error)

NewWithBootstrapContentsForTesting returns an xDS client for this config, separate from the global singleton.

The second return value represents a close function which the caller is expected to invoke once they are done using the client. It is safe for the caller to invoke this close function multiple times.

Testing Only

This function should ONLY be used for testing purposes.

func NewWithConfig

func NewWithConfig(config *bootstrap.Config) (XDSClient, func(), error)

NewWithConfig returns a new xDS client configured by the given config.

The second return value represents a close function which releases the caller's reference on the returned client. The caller is expected to invoke it once they are done using the client. The underlying client will be closed only when all references are released, and it is safe for the caller to invoke this close function multiple times.

Internal/Testing Only

This function should ONLY be used for internal (c2p resolver) and/or testing purposese. DO NOT use this elsewhere. Use New() instead.

func NewWithConfigForTesting

func NewWithConfigForTesting(config *bootstrap.Config, watchExpiryTimeout, authorityIdleTimeout time.Duration) (XDSClient, func(), error)

NewWithConfigForTesting returns an xDS client for the specified bootstrap config, separate from the global singleton.

The second return value represents a close function which the caller is expected to invoke once they are done using the client. It is safe for the caller to invoke this close function multiple times.

Testing Only

This function should ONLY be used for testing purposes. TODO(easwars): Document the new close func.

Directories

Path Synopsis
Package bootstrap provides the functionality to initialize certain aspects of an xDS client by reading a bootstrap file.
Package bootstrap provides the functionality to initialize certain aspects of an xDS client by reading a bootstrap file.
Package load provides functionality to record and maintain load data.
Package load provides functionality to record and maintain load data.
Package transport implements the xDS transport protocol functionality required by the xdsclient.
Package transport implements the xDS transport protocol functionality required by the xdsclient.
Package xdsresource implements the xDS data model layer.
Package xdsresource implements the xDS data model layer.
version
Package version defines constants to distinguish between supported xDS API versions.
Package version defines constants to distinguish between supported xDS API versions.

Jump to

Keyboard shortcuts

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