fix(resolver): filter out nodes with weight 0

fix/resolver-weight-0
baozhecheng 2 years ago
parent 3958f9d5c0
commit 70535dc751
  1. 7
      transport/grpc/resolver/discovery/resolver.go
  2. 7
      transport/http/resolver.go

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

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

Loading…
Cancel
Save