Skip to content

Commit

Permalink
change from godoc review
Browse files Browse the repository at this point in the history
  • Loading branch information
purnesh42H committed Feb 4, 2025
1 parent 56adca3 commit 20e26f8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 52 deletions.
25 changes: 6 additions & 19 deletions xds/internal/clients/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// enabling applications to communicate with xDS management servers and report
// load.
//
// xDS Client
// # xDS Client
//
// The xDS client allows applications to:
// - Create client instances with in-memory configurations.
Expand All @@ -41,14 +41,10 @@
//
// NOTICE: This package is EXPERIMENTAL and may be changed or removed
// in a later release.
//
// See [README](https://github.com/grpc/grpc-go/tree/master/xds/clients/README.md).
package clients

import (
"fmt"
"slices"
"strings"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/structpb"
Expand All @@ -71,15 +67,15 @@ type ServerConfig struct {
IgnoreResourceDeletion bool

// Extensions can be populated with arbitrary data to be passed to the
// [TransportBuilder] and/or xDS Client's ResourceType implementations.
// TransportBuilder and/or xDS Client's ResourceType implementations.
// This field can be used to provide additional configuration or context
// specific to the user's needs.
//
// The xDS and LRS clients do not interpret the contents of this field.
// It is the responsibility of the user's custom [TransportBuilder] and/or
// It is the responsibility of the user's custom TransportBuilder and/or
// ResourceType implementations to handle and interpret these extensions.
//
// For example, a custom [TransportBuilder] might use this field to
// For example, a custom TransportBuilder might use this field to
// configure a specific security credentials.
//
// Note: For custom types used in Extensions, ensure an Equal(any) bool
Expand Down Expand Up @@ -108,15 +104,6 @@ func (sc *ServerConfig) equal(other *ServerConfig) bool {
return false
}

// String returns a string representation of the [ServerConfig].
//
// WARNING: This method is primarily intended for logging and testing
// purposes. The output returned by this method is not guaranteed to be stable
// and may change at any time. Do not rely on it for production use.
func (sc *ServerConfig) String() string {
return strings.Join([]string{sc.ServerURI, fmt.Sprintf("%v", sc.IgnoreResourceDeletion)}, "-")
}

// Authority contains configuration for an xDS control plane authority.
type Authority struct {
// XDSServers contains the list of server configurations for this authority.
Expand Down Expand Up @@ -150,13 +137,13 @@ type Node struct {
UserAgentName string
// UserAgentVersion is the user agent version of application.
UserAgentVersion string
// ClientFeatures is a list of xDS features supported by this client.
// clientFeatures is a list of xDS features supported by this client.
// These features are set within the xDS client, but may be overridden only
// for testing purposes.
clientFeatures []string
}

// toProto converts an instance of [Node] to its protobuf representation.
// toProto converts an instance of Node to its protobuf representation.
func (n Node) toProto() *v3corepb.Node {
return &v3corepb.Node{
Id: n.ID,
Expand Down
6 changes: 3 additions & 3 deletions xds/internal/clients/lrsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ type LRSClient struct {
}

// ReportLoad starts a load reporting stream to the server in given
// [clients.ServerConfig]. All load reports to the same server share the LRS
// clients.ServerConfig. All load reports to the same server share the LRS
// stream.
//
// It returns a [LoadStore] for the user to report loads and a function to
// It returns a LoadStore for the user to report loads and a function to
// cancel the load reporting stream.
//
// The stats from [LoadStore] are reported periodically until cleanup
// The stats from LoadStore are reported periodically until cleanup
// function is called.
func (c *LRSClient) ReportLoad(serverConfig clients.ServerConfig) (*LoadStore, func()) {
panic("unimplemented")

Check warning on line 47 in xds/internal/clients/lrsclient/client.go

View check run for this annotation

Codecov / codecov/patch

xds/internal/clients/lrsclient/client.go#L46-L47

Added lines #L46 - L47 were not covered by tests
Expand Down
8 changes: 4 additions & 4 deletions xds/internal/clients/transport_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
// TransportBuilder provides the functionality to create a communication
// channel to an xDS management 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 xDS server based on the
// provided ServerConfig.
Build(ServerConfig ServerConfig) (Transport, error)
}

// Transport provides the functionality to communicate with an xDS server using
// streaming calls.
// Transport provides the functionality to communicate with an xDS management
// 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
Expand All @@ -43,7 +43,7 @@ type Transport interface {
}

// Stream provides methods to send and receive messages on a stream. Messages
// are represented as a byte slice ([]byte).
// are represented as a byte slice.
type Stream interface {
// Send sends the provided message on the stream.
Send([]byte) error
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/clients/xdsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func New(config Config) (*XDSClient, error) {
// WatchResource uses xDS to discover the resource associated with the provided
// resource name.
// - resourceTypeURL is used to look up the resource type implementation
// provided in the [ResourceTypes] of the config which determines how
// provided in the ResourceTypes map of the config which determines how
// xDS responses are deserialized and validated after receiving from the xDS
// management server.
// - resourceName is the name of the resource to watch.
Expand Down
14 changes: 0 additions & 14 deletions xds/internal/clients/xdsclient/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,3 @@ func NewConfig(servers []clients.ServerConfig, authorities map[string]clients.Au
c.streamBackOffTimeout = defaultStreamBackoffFunc
return c

Check warning on line 78 in xds/internal/clients/xdsclient/config.go

View check run for this annotation

Codecov / codecov/patch

xds/internal/clients/xdsclient/config.go#L74-L78

Added lines #L74 - L78 were not covered by tests
}

// SetWatchExpiryTimeoutForTesting sets the watch expiry timeout.
//
// For testing purpose only.
func (c *Config) SetWatchExpiryTimeoutForTesting(d time.Duration) {
c.watchExpiryTimeOut = d
}

// SetStreamBackOffTimeoutForTesting sets the stream backoff timeout function
//
// For testing purpose only.
func (c *Config) SetStreamBackOffTimeoutForTesting(d func(int) time.Duration) {
c.streamBackOffTimeout = d
}
12 changes: 6 additions & 6 deletions xds/internal/clients/xdsclient/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ResourceType interface {
// 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].
// Config.
TypeURL() string

// TypeName identifies resources in a transport protocol agnostic way. This
Expand All @@ -50,12 +50,12 @@ type ResourceType interface {
// 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(ResourceDecodeOptions, any) (*ResourceDecodeResult, error)
}

// DecodeOptions wraps the options required by ResourceType implementation for
// ResourceDecodeOptions wraps the options required by ResourceType implementation for
// decoding configuration received from the xDS management server.
type DecodeOptions struct {
type ResourceDecodeOptions struct {
// Config contains the complete configuration passed to the xDS client.
// This contains useful data for resource validation.
Config *Config
Expand All @@ -66,8 +66,8 @@ type DecodeOptions struct {
ServerConfig *clients.ServerConfig
}

// DecodeResult is the result of a decode operation.
type DecodeResult struct {
// ResourceDecodeResult is the result of a decode operation.
type ResourceDecodeResult struct {
// Name is the name of the resource being watched.
Name string

Expand Down
10 changes: 5 additions & 5 deletions xds/internal/clients/xdsclient/resource_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

package xdsclient

// OnUpdateProcessed is a function to be invoked by resource watcher
// OnCallbackProcessed is a function to be invoked by resource watcher
// implementations upon completing the processing of a callback from the xDS
// client. Failure to invoke this callback prevents the xDS client from reading
// further messages from the xDS server.
type OnUpdateProcessed func()
type OnCallbackProcessed func()

// ResourceDataOrError is a struct that contains either [ResourceData] or
// ResourceDataOrError is a struct that contains either ResourceData or
// error. It is used to represent the result of an xDS resource update. Exactly
// one of Data or Err will be non-nil.
type ResourceDataOrError struct {
Expand All @@ -43,12 +43,12 @@ type ResourceWatcher interface {
// Upon receiving this, in case of an error, the watcher should
// stop using any previously seen resource. The xDS client will remove the
// resource from its cache.
OnResourceChanged(ResourceDataOrError, OnUpdateProcessed)
OnResourceChanged(ResourceDataOrError, OnCallbackProcessed)

// OnAmbientError is invoked if resource is already cached under different
// error conditions.
//
// Upon receiving this, the watcher may continue using the previously seen
// resource. The xDS client will not remove the resource from its cache.
OnAmbientError(error, OnUpdateProcessed)
OnAmbientError(error, OnCallbackProcessed)
}

0 comments on commit 20e26f8

Please sign in to comment.