Copilot commented on code in PR #3420:
URL: https://github.com/apache/dubbo-go/pull/3420#discussion_r3417590802
##########
cluster/router/affinity/router.go:
##########
@@ -150,6 +164,38 @@ type affinityRoute struct {
ratio int32
}
+// SetStaticConfig applies a RouterConfig directly, bypassing YAML parsing.
+// Static and dynamic rules are not merged: later Process updates replace the
+// current state built here.
+func (a *affinityRoute) SetStaticConfig(cfg *global.RouterConfig) {
+ a.mu.Lock()
+ defer a.mu.Unlock()
+
+ a.matcher, a.enabled, a.key, a.ratio = nil, false, "", 0
+ if cfg == nil {
+ return
+ }
+ if cfg.AffinityAware.Ratio < 0 || cfg.AffinityAware.Ratio > 100 {
+ logger.Errorf("[Router][Affinity] invalid static affinity
ratio: ratio=%d, expected=0-100", cfg.AffinityAware.Ratio)
+ return
+ }
+
+ key := strings.TrimSpace(cfg.AffinityAware.Key)
+ enabled := cfg.Enabled == nil || *cfg.Enabled
+ if !enabled || key == "" {
+ return
+ }
+
+ rule := strings.Join([]string{key, key}, "=$")
+ f, err := condition.NewFieldMatcher(rule)
+ if err != nil {
+ logger.Errorf("[Router][Affinity] parse static affinity rule
failed: key=%s, rule=%s, err=%v", a.key, rule, err)
+ return
+ }
Review Comment:
In the static-config parse failure log, the `key` field is printed using
`a.key`, but `a.key` is reset to "" at the start of SetStaticConfig and isn’t
set until after matcher creation. This results in misleading logs (empty key)
when `condition.NewFieldMatcher` fails. Log the local `key` variable instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]