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
xds/resolver: Add support for cluster specifier plugins #4987
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
44160e9
Added support for cluster specifier plugins in xds resolver
zasweq 8a6bf55
Responded to Doug's comments
zasweq a616529
Responded to Doug's comments
zasweq 6393ab4
Responded to Doug's comments and added tests
zasweq af713af
Responded to Doug's comments
zasweq d219ac6
Responded to Doug's comments
zasweq 5b4f327
Formatting
zasweq File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -133,11 +133,7 @@ type routeCluster struct { | |
|
||
type route struct { | ||
m *xdsresource.CompositeMatcher // converted from route matchers | ||
|
||
// Exactly one of clusterSpecifierPlugin or clusters will be set. | ||
clusterSpecifierPlugin string | ||
clusters wrr.WRR // holds *routeCluster entries | ||
|
||
maxStreamDuration time.Duration | ||
// map from filter name to its config | ||
httpFilterConfigOverride map[string]httpfilter.FilterConfig | ||
|
@@ -179,15 +175,9 @@ func (cs *configSelector) SelectConfig(rpcInfo iresolver.RPCInfo) (*iresolver.RP | |
return nil, errNoMatchedRouteFound | ||
} | ||
|
||
var cluster *routeCluster | ||
if rt.clusterSpecifierPlugin != "" { | ||
cluster.name = rt.clusterSpecifierPlugin | ||
// cluster.httpFilterConfigOverride = /*Do cluster specifier plugins even have http filter config overrides*/ | ||
} else { | ||
cluster, ok := rt.clusters.Next().(*routeCluster) | ||
if !ok { | ||
return nil, status.Errorf(codes.Internal, "error retrieving cluster for match: %v (%T)", cluster, cluster) | ||
} | ||
cluster, ok := rt.clusters.Next().(*routeCluster) | ||
if !ok { | ||
return nil, status.Errorf(codes.Internal, "error retrieving cluster for match: %v (%T)", cluster, cluster) | ||
} | ||
|
||
|
||
|
@@ -381,17 +371,19 @@ func (r *xdsResolver) newConfigSelector(su serviceUpdate) (*configSelector, erro | |
} | ||
|
||
for i, rt := range su.virtualHost.Routes { | ||
clusters := newWRR() | ||
if rt.ClusterSpecifierPlugin != "" { | ||
clusters.Add(&routeCluster{ | ||
name: "cluster:" + rt.ClusterSpecifierPlugin, | ||
}, 1) | ||
|
||
ci := r.activeClusters["cluster_specifier_plugin:" + rt.ClusterSpecifierPlugin] | ||
if ci == nil { | ||
ci = &clusterInfo{refCount: 0} | ||
r.activeClusters["cluster_specifier_plugin:" + rt.ClusterSpecifierPlugin] = ci | ||
} | ||
cs.clusters["cluster_specifier_plugin:" + rt.ClusterSpecifierPlugin] = ci | ||
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. Can this bit be shared with the below section? Maybe factored into another function? |
||
|
||
cs.routes[i].clusterSpecifierPlugin = "cluster_specifier_plugin:" + rt.ClusterSpecifierPlugin | ||
} else { | ||
clusters := newWRR() | ||
for cluster, wc := range rt.WeightedClusters { | ||
clusters.Add(&routeCluster{ | ||
name: "cluster:" + cluster, | ||
|
@@ -408,8 +400,8 @@ func (r *xdsResolver) newConfigSelector(su serviceUpdate) (*configSelector, erro | |
} | ||
cs.clusters["cluster:" + cluster] = ci | ||
} | ||
cs.routes[i].clusters = clusters | ||
} | ||
cs.routes[i].clusters = clusters | ||
|
||
var err error | ||
cs.routes[i].m, err = xdsresource.RouteToMatcher(rt) | ||
|
This file contains 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
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.
Shouldn't this be
"cluster_specifier_plugin:" + rt.ClusterSpecifierPlugin
?Please use a local to hold that instead of repeating it 4 times. Also, global consts for
"cluster:"
and"cluster_specifier_plugin:"
would be a good idea to avoid any chance of a typo in one usage.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.
Yeah, good catch. Added global consts and also a local var for both branches.
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, the comment isn't showing up on this PR, but I refactored the cluster initialization into another function. It made it much cleaner.