-
Notifications
You must be signed in to change notification settings - Fork 4.6k
xds/internal:remove Generic resource Decoder and added concrete functions #8381 #8582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1593b7f
6bdcc58
6176249
ceee228
ae544d4
e77e356
15b88ff
f8ee66d
4f4f99d
10f4504
7bb5a2b
c17c44c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ import ( | |
"sync" | ||
|
||
"google.golang.org/grpc/internal/xds/clients" | ||
"google.golang.org/grpc/internal/xds/clients/lrsclient" | ||
"google.golang.org/grpc/internal/xds/xdsclient" | ||
) | ||
|
||
// NewWrapper creates a Wrapper. | ||
|
@@ -54,8 +54,8 @@ type Wrapper struct { | |
// store and perCluster are initialized as nil. They are only set by the | ||
// balancer when LRS is enabled. Before that, all functions to record loads | ||
// are no-op. | ||
store *lrsclient.LoadStore | ||
perCluster *lrsclient.PerClusterReporter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we change it to use the grpc xdsclient interfaces that we created? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, our balancer directly referenced lrsclient types like LoadStore and PerClusterReporter. |
||
store xdsclient.LoadStore | ||
perCluster xdsclient.PerClusterReporter | ||
} | ||
|
||
// UpdateClusterAndService updates the cluster name and eds service for this | ||
|
@@ -77,7 +77,7 @@ func (lsw *Wrapper) UpdateClusterAndService(cluster, edsService string) { | |
|
||
// UpdateLoadStore updates the load store for this wrapper. If it is changed | ||
// from before, the perCluster store in this wrapper will also be updated. | ||
func (lsw *Wrapper) UpdateLoadStore(store *lrsclient.LoadStore) { | ||
func (lsw *Wrapper) UpdateLoadStore(store xdsclient.LoadStore) { | ||
lsw.mu.Lock() | ||
defer lsw.mu.Unlock() | ||
if store == lsw.store { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ package resolver | |
import ( | ||
"context" | ||
|
||
"google.golang.org/grpc/internal/xds/clients/xdsclient" | ||
"google.golang.org/grpc/internal/xds/xdsclient/xdsresource" | ||
) | ||
|
||
|
@@ -36,8 +37,9 @@ func newListenerWatcher(resourceName string, parent *xdsResolver) *listenerWatch | |
return lw | ||
} | ||
|
||
func (l *listenerWatcher) ResourceChanged(update *xdsresource.ListenerResourceData, onDone func()) { | ||
handleUpdate := func(context.Context) { l.parent.onListenerResourceUpdate(update.Resource); onDone() } | ||
func (l *listenerWatcher) ResourceChanged(rd xdsclient.ResourceData, onDone func()) { | ||
listenerData := rd.(*xdsresource.ListenerResourceData) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making every watcher go through these type assertions is not going to scale. |
||
handleUpdate := func(context.Context) { l.parent.onListenerResourceUpdate(listenerData.Resource); onDone() } | ||
l.parent.serializer.ScheduleOr(handleUpdate, onDone) | ||
} | ||
|
||
|
@@ -68,9 +70,10 @@ func newRouteConfigWatcher(resourceName string, parent *xdsResolver) *routeConfi | |
return rw | ||
} | ||
|
||
func (r *routeConfigWatcher) ResourceChanged(u *xdsresource.RouteConfigResourceData, onDone func()) { | ||
func (r *routeConfigWatcher) ResourceChanged(rd xdsclient.ResourceData, onDone func()) { | ||
rcData := rd.(*xdsresource.RouteConfigResourceData) | ||
handleUpdate := func(context.Context) { | ||
r.parent.onRouteConfigResourceUpdate(r.resourceName, u.Resource) | ||
r.parent.onRouteConfigResourceUpdate(r.resourceName, rcData.Resource) | ||
onDone() | ||
} | ||
r.parent.serializer.ScheduleOr(handleUpdate, onDone) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ import ( | |
internalgrpclog "google.golang.org/grpc/internal/grpclog" | ||
"google.golang.org/grpc/internal/grpcsync" | ||
"google.golang.org/grpc/internal/xds/bootstrap" | ||
"google.golang.org/grpc/internal/xds/clients/xdsclient" | ||
"google.golang.org/grpc/internal/xds/xdsclient/xdsresource" | ||
) | ||
|
||
|
@@ -58,7 +59,7 @@ type ServingModeCallback func(addr net.Addr, mode connectivity.ServingMode, err | |
// XDSClient wraps the methods on the XDSClient which are required by | ||
// the listenerWrapper. | ||
type XDSClient interface { | ||
WatchResource(rType xdsresource.Type, resourceName string, watcher xdsresource.ResourceWatcher) (cancel func()) | ||
WatchResource(rType xdsclient.ResourceType, resourceName string, watcher xdsclient.ResourceWatcher) (cancel func()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, the watch API in this interface should exactly match the one in the external XDSClient. |
||
BootstrapConfig() *bootstrap.Config | ||
} | ||
|
||
|
@@ -386,17 +387,18 @@ type ldsWatcher struct { | |
name string | ||
} | ||
|
||
func (lw *ldsWatcher) ResourceChanged(update *xdsresource.ListenerResourceData, onDone func()) { | ||
func (lw *ldsWatcher) ResourceChanged(rd xdsclient.ResourceData, onDone func()) { | ||
defer onDone() | ||
if lw.parent.closed.HasFired() { | ||
lw.logger.Warningf("Resource %q received update: %#v after listener was closed", lw.name, update) | ||
lw.logger.Warningf("Resource %q received update after listener was closed", lw.name) | ||
return | ||
} | ||
listenerData := rd.(*xdsresource.ListenerResourceData) | ||
if lw.logger.V(2) { | ||
lw.logger.Infof("LDS watch for resource %q received update: %#v", lw.name, update.Resource) | ||
lw.logger.Infof("LDS watch for resource %q received update: %#v", lw.name, listenerData.Resource) | ||
} | ||
l := lw.parent | ||
ilc := update.Resource.InboundListenerCfg | ||
ilc := listenerData.Resource.InboundListenerCfg | ||
// Make sure that the socket address on the received Listener resource | ||
// matches the address of the net.Listener passed to us by the user. This | ||
// check is done here instead of at the XDSClient layer because of the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,9 @@ import ( | |
|
||
v3statuspb "github.com/envoyproxy/go-control-plane/envoy/service/status/v3" | ||
"google.golang.org/grpc/internal/xds/bootstrap" | ||
"google.golang.org/grpc/internal/xds/clients" | ||
"google.golang.org/grpc/internal/xds/clients/lrsclient" | ||
"google.golang.org/grpc/internal/xds/xdsclient/xdsresource" | ||
"google.golang.org/grpc/internal/xds/clients/xdsclient" | ||
) | ||
|
||
// XDSClient is a full fledged gRPC client which queries a set of discovery APIs | ||
|
@@ -47,13 +48,39 @@ type XDSClient interface { | |
// 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()) | ||
WatchResource(rType xdsclient.ResourceType, resourceName string, watcher xdsclient.ResourceWatcher) (cancel func()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This API should match the one in the external XDSClient. |
||
|
||
ReportLoad(*bootstrap.ServerConfig) (*lrsclient.LoadStore, func(context.Context)) | ||
ReportLoad(*bootstrap.ServerConfig) (LoadStore, func(context.Context)) | ||
|
||
BootstrapConfig() *bootstrap.Config | ||
} | ||
|
||
// PerClusterReporter is the minimal interface callers use to record per-cluster | ||
// load and drops. It mirrors the PerClusterReporter methods from the concrete | ||
// lrsclient.PerClusterReporter but is intentionally tiny. | ||
type PerClusterReporter interface { | ||
// CallStarted records that a call has started for the given locality. | ||
CallStarted(locality clients.Locality) | ||
|
||
// CallFinished records that a call has finished for the given locality. | ||
// Pass the error (nil if success) so implementations can update success/failure counters. | ||
CallFinished(locality clients.Locality, err error) | ||
|
||
// CallServerLoad reports a numeric load metric for the given locality and cluster. | ||
// (If your code uses a different name/parameters for this, match the concrete type.) | ||
CallServerLoad(locality clients.Locality, clusterName string, value float64) | ||
|
||
// CallDropped records a dropped request of the given category. | ||
CallDropped(category string) | ||
} | ||
|
||
// LoadStore is the minimal interface returned by ReportLoad. It provides a | ||
// way to get per-cluster reporters and to stop the store. | ||
type LoadStore interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we add this interface? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As part of task #8381, I added the LoadStore interface to replace the previous wrapper and embedded logic used for load reporting. Earlier, the balancers and xDS components used a concrete wrapper (load_store_wrapper.go) to talk to the LRS client. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's please the scope of this PR to only take care of the APIs involving resource type implementations and watchers etc. Smaller PRs ensure that they can be reviewed in time and reviewed more thoroughly. So, let's please get rid of all load reporting changes and have them be made as a follow-up PR. Thanks. |
||
ReporterForCluster(clusterName, serviceName string) *lrsclient.PerClusterReporter | ||
Stop(ctx context.Context) | ||
} | ||
|
||
// DumpResources returns the status and contents of all xDS resources. It uses | ||
// xDS clients from the default pool. | ||
func DumpResources() *v3statuspb.ClientStatusResponse { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ var ( | |
// interface with ref counting so that it can be shared by the xds resolver and | ||
// balancer implementations, across multiple ClientConns and Servers. | ||
type clientImpl struct { | ||
*xdsclient.XDSClient // TODO: #8313 - get rid of embedding, if possible. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we make this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We embedded xdsclient.XDSClient here as a temporary delegation layer to the generic client while we migrate call sites for #8381. |
||
xdsClient *xdsclient.XDSClient | ||
|
||
// The following fields are initialized at creation time and are read-only | ||
// after that. | ||
|
@@ -137,7 +137,7 @@ func newClientImpl(config *bootstrap.Config, metricsRecorder estats.MetricsRecor | |
return nil, err | ||
} | ||
c := &clientImpl{ | ||
XDSClient: client, | ||
xdsClient: client, | ||
xdsClientConfig: gConfig, | ||
bootstrapConfig: config, | ||
target: target, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this import renaming here and elsewhere?
Please see: https://google.github.io/styleguide/go/decisions#import-renaming