package xdsclient

import "google.golang.org/grpc/xds/internal/xdsclient"

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

Index

Functions

func ClearAllCountersForTesting

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

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

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

func (c *ClusterRequestsCounter) EndRequest()

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

func (*ClusterRequestsCounter) StartRequest

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()
	ReportLoad(*bootstrap.ServerConfig) (*load.Store, 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.
	//
	// 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())

	DumpLDS() map[string]xdsresource.UpdateWithMD
	DumpRDS() map[string]xdsresource.UpdateWithMD
	DumpCDS() map[string]xdsresource.UpdateWithMD
	DumpEDS() map[string]xdsresource.UpdateWithMD

	BootstrapConfig() *bootstrap.Config
	Close()
}

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

Note that the first invocation of New() or NewWithConfig() sets the client singleton. The following calls will return the singleton client without checking or using the config.

func NewWithBootstrapContentsForTesting

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

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

Testing Only

This function should ONLY be used for testing purposes.

func NewWithConfig

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

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

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, error)

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

Testing Only

This function should ONLY be used for testing purposes.

Source Files

attributes.go authority.go callback_serializer.go client.go client_new.go clientimpl.go clientimpl_authority.go clientimpl_dump.go clientimpl_loadreport.go clientimpl_validator.go clientimpl_watchers.go logging.go requests_counter.go singleton.go

Directories

PathSynopsis
xds/internal/xdsclient/bootstrapPackage bootstrap provides the functionality to initialize certain aspects of an xDS client by reading a bootstrap file.
xds/internal/xdsclient/controllerPackage controller contains implementation to connect to the control plane.
xds/internal/xdsclient/controller/versionPackage version defines APIs to deal with different versions of xDS.
xds/internal/xdsclient/controller/version/v2Package v2 provides xDS v2 transport protocol specific functionality.
xds/internal/xdsclient/controller/version/v3Package v3 provides xDS v3 transport protocol specific functionality.
xds/internal/xdsclient/e2e_test
xds/internal/xdsclient/loadPackage load provides functionality to record and maintain load data.
xds/internal/xdsclient/pubsubPackage pubsub implements a utility type to maintain resource watchers and the updates.
xds/internal/xdsclient/transportPackage transport implements the xDS transport protocol functionality required by the xdsclient.
xds/internal/xdsclient/xdsresourcePackage xdsresource contains functions to proto xds updates (unmarshal from proto), and types for the resource updates.
xds/internal/xdsclient/xdsresource/versionPackage version defines constants to distinguish between supported xDS API versions.
Version
v1.52.3
Published
Jan 25, 2023
Platform
linux/amd64
Imports
21 packages
Last checked
6 minutes ago

Tools for package owners.