Compare commits

...

2 Commits

Author SHA1 Message Date
baozhecheng 05b5928114 fix 2 years ago
baozhecheng 70535dc751 fix(resolver): filter out nodes with weight 0 2 years ago
  1. 7
      transport/grpc/resolver/discovery/resolver.go
  2. 7
      transport/http/resolver.go

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"strconv"
"time"
"google.golang.org/grpc/attributes"
@ -66,6 +67,12 @@ func (r *discoveryResolver) update(ins []*registry.ServiceInstance) {
if _, ok := endpoints[ept]; ok {
continue
}
// filter weight <= 0
if w, ok := in.Metadata["weight"]; ok && w != "" {
if i, err := strconv.ParseInt(w, 10, 64); err == nil && i <= 0 {
continue
}
}
filtered = append(filtered, in)
}
if r.subsetSize != 0 {

@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/url"
"strconv"
"strings"
"time"
@ -130,6 +131,12 @@ func (r *resolver) update(services []*registry.ServiceInstance) bool {
if ept == "" {
continue
}
// filter weight <= 0
if w, ok := ins.Metadata["weight"]; ok && w != "" {
if i, err := strconv.ParseInt(w, 10, 64); err == nil && i <= 0 {
continue
}
}
filtered = append(filtered, ins)
}
if r.subsetSize != 0 {

Loading…
Cancel
Save