-
Notifications
You must be signed in to change notification settings - Fork 4.6k
xds: Add cluster endpoint watchers to depndency manager #8744
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?
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #8744 +/- ##
==========================================
+ Coverage 83.28% 83.32% +0.04%
==========================================
Files 418 418
Lines 32367 32663 +296
==========================================
+ Hits 26958 27218 +260
- Misses 4034 4061 +27
- Partials 1375 1384 +9
🚀 New features to boost your workflow:
|
| // We want to stop using this cluster as we received a resource error so | ||
| // remove the last update. |
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.
Nit: Only onListenerResourceAmbientError and onRouteConfigResourceAmbientError currently have docstrings. A comment like this makes more sense to be part of the docstring (for all watchers). But as they will be repeated for all watchers, please keep it short and sweet.
| } | ||
| } | ||
|
|
||
| type clusterWatcher struct { |
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 is it that the listener and route watchers store the cancel func inside themselves, while the cluster and endpoints watchers don't?
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.
And a result of this difference the LDS/RDS watchers have a stop method, while the CDS/EDS watchers don't.
| } | ||
|
|
||
| m.clustersFromRouteConfig = newClusters | ||
| } |
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 not create new cluster watchers from here since we know the list of clusters at this point?
| } | ||
| } | ||
|
|
||
| func (m *DependencyManager) populateClusterConfigLocked(name string, depth int, clusterMap map[string]*xdsresource.ClusterResult, edsSeen, dnsSeen, clusterSeen map[string]bool) (bool, []string, error) { |
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.
This method accepts a bunch of arguments, returns a bunch of values, and has complex logic in it. This needs to have a good docstring to help the reader.
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.
Also, can we have better variable names for the arguments.
- s/name/clusterName
- What does
clusterMapreally represent? This needs a more descriptive name. - s/clusterSeen/clustersSeen etc
|
Can you also please check the codecov report here: #8744 (comment) to see if there are any valid lines that are missing test coverage. Thanks. |
| } | ||
| } | ||
|
|
||
| func (m *DependencyManager) populateClusterConfigLocked(name string, depth int, clusterMap map[string]*xdsresource.ClusterResult, edsSeen, dnsSeen, clusterSeen map[string]bool) (bool, []string, error) { |
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.
Also, can we have better variable names for the arguments.
- s/name/clusterName
- What does
clusterMapreally represent? This needs a more descriptive name. - s/clusterSeen/clustersSeen etc
| return false, nil, nil | ||
| } | ||
|
|
||
| state := m.clusterWatchers[name] |
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.
You could avoid another map lookup by doing
state, ok := m.clusterWatchers[name];
if !ok { ... }
| // If update is not yet received for this cluster, return. | ||
| if state.lastUpdate == nil && state.lastErr == nil { | ||
| return false, nil, nil | ||
| } | ||
|
|
||
| // If resource error is seen for this cluster, save it in the cluster map | ||
| // and return. | ||
| if state.lastUpdate == nil && state.lastErr != nil { | ||
| clusterMap[name] = &xdsresource.ClusterResult{Err: state.lastErr} | ||
| return true, nil, nil | ||
| } | ||
|
|
||
| update := state.lastUpdate | ||
| clusterMap[name] = &xdsresource.ClusterResult{ | ||
| Config: xdsresource.ClusterConfig{ | ||
| Cluster: update, | ||
| }, | ||
| } |
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.
Can this be changed to a switch because it looks like all of this is handling different cases for an update/error being already present.
| var edsName string | ||
| if update.EDSServiceName == "" { | ||
| edsName = name | ||
| } else { | ||
| edsName = update.EDSServiceName | ||
| } |
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.
This can be shortened as follows:
edsName := clusterName
if update.EDSServiceName != "" {
edsName = update.EDSServiceName
}| } | ||
|
|
||
| func (dr *dnsResolver) NewAddress(addresses []resolver.Address) { | ||
| dr.UpdateState(resolver.State{Addresses: addresses}) |
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.
We know for a fact that our DNS resolver implementation does not call NewAddresses. Should we panic here instead?
| } | ||
|
|
||
| func (dr *dnsResolver) ParseServiceConfig(string) *serviceconfig.ParseResult { | ||
| return &serviceconfig.ParseResult{Err: fmt.Errorf("service config not supported")} |
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.
I understand that this is existing behavior, but do you happen to know if this is what other languages do as well?
|
|
||
| // dnsResolverState watches updates for the given DNS hostname. It implements | ||
| // resolver.ClientConn interface to work with the DNS resolver. | ||
| type dnsResolver struct { |
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.
Can we make an interface that both the endpointsWatcher and the dnsWatcher can satisfy, so that the dependency manager can treat them as equals?
This is part of A74 implementation which add CDS/EDS/DNS watchers to the dependency manager. It also adds a temporary flag that is disabled by default so that it is not used in the current RPC paths , but enabled in the dependency manager tests.
RELEASE NOTES: None