From e0a56520dc960b52078d9049be89e7548b4c6946 Mon Sep 17 00:00:00 2001 From: Purnesh Dixit Date: Tue, 11 Feb 2025 18:11:25 +0700 Subject: [PATCH] changed to decoder struct --- xds/internal/clients/config.go | 2 +- xds/internal/clients/lrsclient/client.go | 2 +- xds/internal/clients/transport_builder.go | 12 ++++++------ xds/internal/clients/xdsclient/config.go | 2 +- .../clients/xdsclient/resource_type.go | 18 +++++++++++++----- .../clients/xdsclient/resource_watcher.go | 5 +++-- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/xds/internal/clients/config.go b/xds/internal/clients/config.go index dc1d30e5fdc2..a48a6b8ed7d8 100644 --- a/xds/internal/clients/config.go +++ b/xds/internal/clients/config.go @@ -105,7 +105,7 @@ func (sc *ServerConfig) equal(other *ServerConfig) bool { // Authority contains configuration for an xDS control plane authority. // -// See https://github.com/grpc/grpc/blob/master/doc/grpc_xds_bootstrap_format.md +// See: https://github.com/grpc/grpc/blob/master/doc/grpc_xds_bootstrap_format.md type Authority struct { // XDSServers contains the list of server configurations for this authority. // The order of the servers in this list reflects the order of preference diff --git a/xds/internal/clients/lrsclient/client.go b/xds/internal/clients/lrsclient/client.go index 37f7042f8a09..0c8c4a5aaed6 100644 --- a/xds/internal/clients/lrsclient/client.go +++ b/xds/internal/clients/lrsclient/client.go @@ -20,7 +20,7 @@ // Package lrsclient provides an LRS (Load Reporting Service) client. // -// [LRS]: https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/load_stats/v3/lrs.proto +// See: https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/load_stats/v3/lrs.proto package lrsclient import ( diff --git a/xds/internal/clients/transport_builder.go b/xds/internal/clients/transport_builder.go index e07606e8fc39..a80eebdae970 100644 --- a/xds/internal/clients/transport_builder.go +++ b/xds/internal/clients/transport_builder.go @@ -23,19 +23,19 @@ import ( ) // TransportBuilder provides the functionality to create a communication -// channel to an xDS management server. +// channel to an xDS or LRS server. type TransportBuilder interface { - // Build creates a new Transport instance to the xDS server based on the + // Build creates a new Transport instance to the server based on the // provided ServerConfig. Build(ServerConfig ServerConfig) (Transport, error) } -// Transport provides the functionality to communicate with an xDS management +// Transport provides the functionality to communicate with an xDS or LRS // server using streaming calls. type Transport interface { - // NewStream creates a new streaming call to the xDS server for the - // specified RPC method name. The returned Stream interface can be used - // to send and receive messages on the stream. + // NewStream creates a new streaming call to the server for the specific + // RPC method name. The returned Stream interface can be used to send and + // receive messages on the stream. NewStream(context.Context, string) (Stream, error) // Close closes the Transport. diff --git a/xds/internal/clients/xdsclient/config.go b/xds/internal/clients/xdsclient/config.go index 973af0afcf9b..44d3d1b2f9ad 100644 --- a/xds/internal/clients/xdsclient/config.go +++ b/xds/internal/clients/xdsclient/config.go @@ -45,7 +45,7 @@ type Config struct { // management server. Node clients.Node - // TransportBuilder is used to connect to the management server. + // TransportBuilder is used to connect to the xDS management server. TransportBuilder clients.TransportBuilder // ResourceTypes is a map from resource type URLs to resource type diff --git a/xds/internal/clients/xdsclient/resource_type.go b/xds/internal/clients/xdsclient/resource_type.go index 58b80805beb8..aa49ae80734e 100644 --- a/xds/internal/clients/xdsclient/resource_type.go +++ b/xds/internal/clients/xdsclient/resource_type.go @@ -25,32 +25,40 @@ import ( // ResourceType wraps all resource-type specific functionality. Each supported // resource type needs to provide an implementation of this interface. -type ResourceType interface { +type ResourceType struct { // TypeURL is the xDS type URL of this resource type for the v3 xDS // protocol. This URL is used as the key to look up the corresponding // ResourceType implementation in the ResourceTypes map provided in the // Config. - TypeURL() string + TypeURL string // TypeName identifies resources in a transport protocol agnostic way. This // can be used for logging/debugging purposes, as well as in cases where // the resource type name is to be uniquely identified but the actual // functionality provided by the resource type is not required. - TypeName() string + TypeName string // AllResourcesRequiredInSotW indicates whether this resource type requires // that all resources be present in every SotW response from the server. If // true, a response that does not include a previously seen resource will // be interpreted as a deletion of that resource. - AllResourcesRequiredInSotW() bool + AllResourcesRequiredInSotW bool + // Decoder is used to deserialize and validate an xDS resource received + // from the xDS management server. + Decoder Decoder +} + +// Decoder wraps the resource-type specific functionality for validation +// and deserialization. +type Decoder interface { // Decode deserializes and validates an xDS resource serialized inside the // provided `Any` proto, as received from the xDS management server. // // If protobuf deserialization fails or resource validation fails, // returns a non-nil error. Otherwise, returns a fully populated // DecodeResult. - Decode(DecodeOptions, any) (*DecodeResult, error) + Decode(resource any, options DecodeOptions) (*DecodeResult, error) } // DecodeOptions wraps the options required by ResourceType implementation for diff --git a/xds/internal/clients/xdsclient/resource_watcher.go b/xds/internal/clients/xdsclient/resource_watcher.go index 8d3a7d663385..0eead5c892d9 100644 --- a/xds/internal/clients/xdsclient/resource_watcher.go +++ b/xds/internal/clients/xdsclient/resource_watcher.go @@ -37,7 +37,8 @@ type ResourceWatcher interface { // AmbientError indicates an error occurred after a resource has been // received that should not modify the use of that resource but may be - // useful information about the ambient state of the XdsClient. The - // previous version of the resource should still be considered valid. + // provide useful information about the ambient state of the XdsClient for + // debugging purposes. The previous version of the resource should still be + // considered valid. AmbientError(err error, onCallbackProcessed func()) }