-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: Outlier Detection configuration in Cluster Resolver Balancer #5371
Changes from 1 commit
72138c7
0f84478
770161c
2e16f0a
6e8454e
4572880
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 |
---|---|---|
|
@@ -158,7 +158,7 @@ func buildPriorityConfig(priorities []priorityConfig, xdsLBPolicy *internalservi | |
retAddrs = append(retAddrs, addrs...) | ||
var odCfg *outlierdetection.LBConfig | ||
if envconfig.XDSOutlierDetection { | ||
odCfg = makeClusterImplOutlierDetectionChild(*config, *p.mechanism.OutlierDetection) | ||
odCfg = makeClusterImplOutlierDetectionChild(*config, p.mechanism.OutlierDetection) | ||
retConfig.Children[name] = &priority.Child{ | ||
Config: &internalserviceconfig.BalancerConfig{Name: outlierdetection.Name, Config: odCfg}, | ||
// Not ignore re-resolution from DNS children, they will trigger | ||
|
@@ -181,15 +181,18 @@ func buildPriorityConfig(priorities []priorityConfig, xdsLBPolicy *internalservi | |
func convertClusterImplMapToOutlierDetection(ciCfgs map[string]*clusterimpl.LBConfig, odCfg *outlierdetection.LBConfig) map[string]*outlierdetection.LBConfig { | ||
odCfgs := make(map[string]*outlierdetection.LBConfig, len(ciCfgs)) | ||
for n, c := range ciCfgs { | ||
odCfgs[n] = makeClusterImplOutlierDetectionChild(*c, *odCfg) | ||
odCfgs[n] = makeClusterImplOutlierDetectionChild(*c, odCfg) | ||
} | ||
return odCfgs | ||
} | ||
|
||
func makeClusterImplOutlierDetectionChild(ciCfg clusterimpl.LBConfig, odCfg outlierdetection.LBConfig) *outlierdetection.LBConfig { | ||
odCfgRet := odCfg | ||
odCfgRet.ChildPolicy = &internalserviceconfig.BalancerConfig{Name: clusterimpl.Name, Config: &ciCfg} // This can panic if odCfg is nil. This shouldn't be nil though, as per CDS balancer. I can add check if you want. | ||
return &odCfgRet | ||
func makeClusterImplOutlierDetectionChild(ciCfg clusterimpl.LBConfig, odCfg *outlierdetection.LBConfig) *outlierdetection.LBConfig { | ||
odCfgRet := &outlierdetection.LBConfig{} | ||
if odCfg != nil { | ||
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. Is it valid for this to be nil? Why? For the JSON config, can we make the field a value instead of a pointer so it's never nil? Then pass by value to avoid the explicit copy. 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. It's not valid. This config is prepared by the cluster resolver, so we're guaranteed for this not to be nil, but this handles the nil panic I discussed earlier with you. 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. Had the discovery mechanism hold onto a value, and pass it by value around. I kept this function returning a pointer though, as that is the value of internalserviceconfig.BalancerConfig that I populate. |
||
*odCfgRet = *odCfg | ||
} | ||
odCfgRet.ChildPolicy = &internalserviceconfig.BalancerConfig{Name: clusterimpl.Name, Config: &ciCfg} | ||
return odCfgRet | ||
} | ||
|
||
func buildClusterImplConfigForDNS(g *nameGenerator, addrStrs []string, mechanism DiscoveryMechanism) (string, *clusterimpl.LBConfig, []resolver.Address) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ package outlierdetection | |
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
|
||
"google.golang.org/grpc/balancer" | ||
|
@@ -43,7 +44,7 @@ func (bb) Build(cc balancer.ClientConn, bOpts balancer.BuildOptions) balancer.Ba | |
|
||
func (bb) ParseConfig(s json.RawMessage) (serviceconfig.LoadBalancingConfig, error) { | ||
var lbCfg *LBConfig | ||
if err := json.Unmarshal(s, &lbCfg); err != nil { | ||
if err := json.Unmarshal(s, &lbCfg); err != nil { // Validates child config if present as well. | ||
return nil, fmt.Errorf("xds: unable to unmarshal LBconfig: %s, error: %v", string(s), err) | ||
} | ||
|
||
|
@@ -90,6 +91,11 @@ func (bb) ParseConfig(s json.RawMessage) (serviceconfig.LoadBalancingConfig, err | |
if lbCfg.FailurePercentageEjection != nil && lbCfg.FailurePercentageEjection.EnforcementPercentage > 100 { | ||
return nil, fmt.Errorf("LBConfig.FailurePercentageEjection.EnforcementPercentage = %v; must be <= 100", lbCfg.FailurePercentageEjection.EnforcementPercentage) | ||
} | ||
|
||
if lbCfg.ChildPolicy == nil { | ||
return nil, errors.New("LBConfig.ChildPolicy needs to be present") | ||
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. s/needs to/must/? 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. Done. |
||
} | ||
|
||
return lbCfg, nil | ||
} | ||
|
||
|
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 not pass
ciCfg
by pointer? Generally structs should be passed by pointer unless there's a good reason not to.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.
See: go/go-style/decisions#pass-values
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.
Switched to passing by pointer.