-
Notifications
You must be signed in to change notification settings - Fork 4.6k
internal/xds: move the LDS and RDS watchers to dependency manager #8651
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
Open
eshitachandwani
wants to merge
10
commits into
grpc:master
Choose a base branch
from
eshitachandwani:A74_LDS_RDS
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,206
−5
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fbfb4b1
LDS/RDS to deps manager
eshitachandwani 66270ee
remove const
eshitachandwani d28cb9e
Merge branch 'grpc:master' into A74_LDS_RDS
eshitachandwani d80ee7a
Change log
eshitachandwani 3502dbf
resolve conflicts
eshitachandwani b696279
remove test
eshitachandwani ed60964
change test
eshitachandwani fff6013
review comments
eshitachandwani 58478e6
cancelled watcher updates
eshitachandwani c279455
fine changes
eshitachandwani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * | ||
| * Copyright 2025 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package xdsresource | ||
|
|
||
| import "google.golang.org/grpc/resolver" | ||
|
|
||
| // XDSConfig holds the complete gRPC client-side xDS configuration containing | ||
| // all necessary resources. | ||
| type XDSConfig struct { | ||
| // Listener holds the listener configuration. | ||
| Listener *ListenerUpdate | ||
|
|
||
| // RouteConfig is the route configuration. It will be populated even if | ||
| // RouteConfig is inlined into the Listener resource. | ||
| RouteConfig RouteConfigUpdate | ||
|
|
||
| // VirtualHost selected from the route configuration whose domain field | ||
| // offers the best match against the provided dataplane authority. | ||
| VirtualHost *VirtualHost | ||
|
|
||
| // Clusters is a map from cluster name to its configuration. | ||
| Clusters map[string]*ClusterResult | ||
| } | ||
|
|
||
| // ClusterResult contains a cluster's configuration when we receive a | ||
| // valid resource from the management server. It contains an error when: | ||
| // - we receive an invalid resource from the management server and | ||
| // we did not already have a valid resource or | ||
| // - the cluster resource does not exist on the management server | ||
| type ClusterResult struct { | ||
| Config ClusterConfig | ||
| Err error | ||
| } | ||
|
|
||
| // ClusterConfig contains configuration for a single cluster. | ||
| type ClusterConfig struct { | ||
| Cluster ClusterUpdate // Cluster configuration. Always present. | ||
| EndpointConfig EndpointConfig // Endpoint configuration for leaf clusters. | ||
| AggregateConfig AggregateConfig // List of children for aggregate clusters. | ||
| } | ||
|
|
||
| // AggregateConfig contains a list of leaf cluster names for . | ||
| type AggregateConfig struct { | ||
| LeafClusters []string | ||
| } | ||
|
|
||
| // EndpointConfig contains configuration corresponding to the endpoints in a | ||
| // cluster. Only one of EDSUpdate or DNSEndpoints will be populated based on the | ||
| // cluster type. | ||
| type EndpointConfig struct { | ||
| EDSUpdate EndpointsUpdate // Configuration for EDS clusters. | ||
| DNSEndpoints DNSUpdate // Configuration for LOGICAL_DNS clusters. | ||
| ResolutionNote error // Error obtaining endpoints data. | ||
| } | ||
|
|
||
| // DNSUpdate contains the update from DNS resolver. | ||
| type DNSUpdate struct { | ||
| Endpoints []resolver.Endpoint | ||
| } | ||
|
|
||
| // xdsConfigkey is the type used as the key to store XDSConfig in | ||
| // the Attributes field of resolver.states. | ||
| type xdsConfigkey struct{} | ||
|
|
||
| // SetXDSConfig returns a copy of state in which the Attributes field | ||
| // is updated with the XDSConfig. | ||
| func SetXDSConfig(state resolver.State, config *XDSConfig) resolver.State { | ||
| state.Attributes = state.Attributes.WithValue(xdsConfigkey{}, config) | ||
| return state | ||
| } | ||
|
|
||
| // XDSConfigFromResolverState returns XDSConfig stored in attribute in resolver | ||
| // state. | ||
| func XDSConfigFromResolverState(state resolver.State) *XDSConfig { | ||
| state.Attributes.Value(xdsConfigkey{}) | ||
| if v := state.Attributes.Value(xdsConfigkey{}); v != nil { | ||
| return v.(*XDSConfig) | ||
| } | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * | ||
| * Copyright 2025 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package xdsdepmgr | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "google.golang.org/grpc/grpclog" | ||
| internalgrpclog "google.golang.org/grpc/internal/grpclog" | ||
| ) | ||
|
|
||
| const prefix = "[xds-dependency-manager %p] " | ||
|
|
||
| var logger = grpclog.Component("xds") | ||
|
|
||
| func prefixLogger(p *DependencyManager) *internalgrpclog.PrefixLogger { | ||
| return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| * | ||
| * Copyright 2020 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package xdsdepmgr | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "google.golang.org/grpc/internal/xds/xdsclient/xdsresource" | ||
| ) | ||
|
|
||
| type listenerWatcher struct { | ||
| resourceName string | ||
| cancel func() | ||
| isCancelled bool | ||
| parent *DependencyManager | ||
| } | ||
|
|
||
| func newListenerWatcher(resourceName string, parent *DependencyManager) *listenerWatcher { | ||
| lw := &listenerWatcher{resourceName: resourceName, parent: parent} | ||
| lw.cancel = xdsresource.WatchListener(parent.xdsClient, resourceName, lw) | ||
| return lw | ||
| } | ||
|
|
||
| func (l *listenerWatcher) ResourceChanged(update *xdsresource.ListenerUpdate, onDone func()) { | ||
| if l.isCancelled { | ||
| return | ||
| } | ||
| handleUpdate := func(context.Context) { | ||
| l.parent.onListenerResourceUpdate(update) | ||
| onDone() | ||
| } | ||
| l.parent.serializer.ScheduleOr(handleUpdate, onDone) | ||
| } | ||
|
|
||
| func (l *listenerWatcher) ResourceError(err error, onDone func()) { | ||
| if l.isCancelled { | ||
| return | ||
| } | ||
| handleError := func(context.Context) { | ||
| l.parent.onListenerResourceError(err) | ||
| onDone() | ||
| } | ||
|
|
||
| l.parent.serializer.ScheduleOr(handleError, onDone) | ||
| } | ||
|
|
||
| func (l *listenerWatcher) AmbientError(err error, onDone func()) { | ||
| if l.isCancelled { | ||
| return | ||
| } | ||
| handleError := func(context.Context) { | ||
| l.parent.onListenerResourceAmbientError(err) | ||
| onDone() | ||
| } | ||
| l.parent.serializer.ScheduleOr(handleError, onDone) | ||
| } | ||
|
|
||
| func (l *listenerWatcher) stop() { | ||
| l.isCancelled = true | ||
| l.cancel() | ||
| if logger.V(2) { | ||
| l.parent.logger.Infof("Canceling watch on Listener resource %q", l.resourceName) | ||
| } | ||
| } | ||
|
|
||
| type routeConfigWatcher struct { | ||
| resourceName string | ||
| cancel func() | ||
| parent *DependencyManager | ||
| isCancelled bool | ||
| } | ||
|
|
||
| func newRouteConfigWatcher(resourceName string, parent *DependencyManager) *routeConfigWatcher { | ||
| rw := &routeConfigWatcher{resourceName: resourceName, parent: parent} | ||
| rw.cancel = xdsresource.WatchRouteConfig(parent.xdsClient, resourceName, rw) | ||
| return rw | ||
| } | ||
|
|
||
| func (r *routeConfigWatcher) ResourceChanged(u *xdsresource.RouteConfigResourceData, onDone func()) { | ||
| if r.isCancelled { | ||
| return | ||
| } | ||
| handleUpdate := func(context.Context) { | ||
| r.parent.onRouteConfigResourceUpdate(r.resourceName, u.Resource) | ||
| onDone() | ||
| } | ||
| r.parent.serializer.ScheduleOr(handleUpdate, onDone) | ||
| } | ||
|
|
||
| func (r *routeConfigWatcher) ResourceError(err error, onDone func()) { | ||
| if r.isCancelled { | ||
| return | ||
| } | ||
| handleError := func(context.Context) { | ||
| r.parent.onRouteConfigResourceError(r.resourceName, err) | ||
| onDone() | ||
| } | ||
| r.parent.serializer.ScheduleOr(handleError, onDone) | ||
| } | ||
|
|
||
| func (r *routeConfigWatcher) AmbientError(err error, onDone func()) { | ||
| if r.isCancelled { | ||
| return | ||
| } | ||
| handleError := func(context.Context) { | ||
| r.parent.onRouteConfigResourceAmbientError(r.resourceName, err) | ||
| onDone() | ||
| } | ||
| r.parent.serializer.ScheduleOr(handleError, onDone) | ||
| } | ||
|
|
||
| func (r *routeConfigWatcher) stop() { | ||
| r.isCancelled = true | ||
| r.cancel() | ||
| if logger.V(2) { | ||
| r.parent.logger.Infof("Canceling watch on RouteConfiguration resource %q", r.resourceName) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Will change other resources to pointer after #8652 is merged