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

Constants

const NameForServer = "#server"

NameForServer represents the value to be passed as name when creating an xDS client from xDS-enabled gRPC servers. This is a well-known dedicated key value, and is defined in gRFC A71.

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 DumpResources

func DumpResources() *v3statuspb.ClientStatusResponse

DumpResources returns the status and contents of all xDS resources.

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 OptionsForTesting

type OptionsForTesting struct {
	// Name is a unique name for this xDS client.
	Name string
	// Contents contain a JSON representation of the bootstrap configuration to
	// be used when creating the xDS client.
	Contents []byte

	// WatchExpiryTimeout is the timeout for xDS resource watch expiry. If
	// unspecified, uses the default value used in non-test code.
	WatchExpiryTimeout time.Duration

	// AuthorityIdleTimeout is the timeout before idle authorities are deleted.
	// If unspecified, uses the default value used in non-test code.
	AuthorityIdleTimeout time.Duration
}

OptionsForTesting contains options to configure xDS client creation for testing purposes only.

type XDSClient

type XDSClient interface {
	// 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.
	WatchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) (cancel func())

	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 GetForTesting

func GetForTesting(name string) (XDSClient, func(), error)

GetForTesting returns an xDS client created earlier using the given name.

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 New

func New(name string) (XDSClient, func(), error)

New returns an xDS client configured with bootstrap configuration specified by the ordered list: - file name containing the configuration specified by GRPC_XDS_BOOTSTRAP - actual configuration specified by GRPC_XDS_BOOTSTRAP_CONFIG - fallback configuration set using bootstrap.SetFallbackBootstrapConfig

gRPC client implementations are expected to pass the channel's target URI for the name field, while server implementations are expected to pass a dedicated well-known value "#server", as specified in gRFC A71. The returned client is a reference counted implementation shared among callers using the same name.

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 NewForTesting

func NewForTesting(opts OptionsForTesting) (XDSClient, func(), error)

NewForTesting returns an xDS client configured with the provided options.

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.

Source Files

attributes.go authority.go client.go client_new.go client_refcounted.go clientimpl.go clientimpl_authority.go clientimpl_dump.go clientimpl_loadreport.go clientimpl_watchers.go logging.go requests_counter.go

Directories

PathSynopsis
xds/internal/xdsclient/internalPackage internal contains functionality internal to the xdsclient package.
xds/internal/xdsclient/loadPackage load provides functionality to record and maintain load data.
xds/internal/xdsclient/tests
xds/internal/xdsclient/transportPackage transport implements the xDS transport protocol functionality required by the xdsclient.
xds/internal/xdsclient/transport/internalPackage internal contains functionality internal to the transport package.
xds/internal/xdsclient/xdslbregistryPackage xdslbregistry provides a registry of converters that convert proto from load balancing configuration, defined by the xDS API spec, to JSON load balancing configuration.
xds/internal/xdsclient/xdslbregistry/converterPackage converter provides converters to convert proto load balancing configuration, defined by the xDS API spec, to JSON load balancing configuration.
xds/internal/xdsclient/xdsresourcePackage xdsresource implements the xDS data model layer.
xds/internal/xdsclient/xdsresource/tests
xds/internal/xdsclient/xdsresource/versionPackage version defines constants to distinguish between supported xDS API versions.
Version
v1.67.0
Published
Sep 20, 2024
Platform
linux/amd64
Imports
21 packages
Last checked
3 minutes ago

Tools for package owners.