Skip to content

Commit

Permalink
changed to decoder struct
Browse files Browse the repository at this point in the history
  • Loading branch information
purnesh42H committed Feb 11, 2025
1 parent 9463fbb commit e0a5652
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion xds/internal/clients/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/clients/lrsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
12 changes: 6 additions & 6 deletions xds/internal/clients/transport_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/clients/xdsclient/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions xds/internal/clients/xdsclient/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions xds/internal/clients/xdsclient/resource_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit e0a5652

Please sign in to comment.