Skip to content

Commit c3c5801

Browse files
authored
Merge pull request #76 from unistack-org/backoff
use backoff for lookup too
2 parents 3eca811 + 4ad5262 commit c3c5801

File tree

3 files changed

+58
-30
lines changed

3 files changed

+58
-30
lines changed

go.mod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ module go.unistack.org/micro-client-http/v3
22

33
go 1.16
44

5-
require go.unistack.org/micro/v3 v3.9.7
5+
require (
6+
github.com/google/gnostic v0.6.9 // indirect
7+
github.com/google/go-cmp v0.5.7 // indirect
8+
github.com/kr/pretty v0.2.1 // indirect
9+
github.com/kr/text v0.2.0 // indirect
10+
go.unistack.org/micro/v3 v3.9.7
11+
google.golang.org/protobuf v1.28.0 // indirect
12+
)

go.sum

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
1010
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
1111
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
1212
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
13+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1314
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1415
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1516
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
@@ -39,23 +40,29 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
3940
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
4041
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
4142
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
42-
github.com/google/gnostic v0.6.6 h1:MVSM2r2j9aRUvYNym66JGW96Ddd5MN4sTi59yktb6yk=
4343
github.com/google/gnostic v0.6.6/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E=
44+
github.com/google/gnostic v0.6.8 h1:bT56GPYBWh1tvBuBEd94qcS3+60b+y0HQur0ITkGuCk=
45+
github.com/google/gnostic v0.6.8/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E=
46+
github.com/google/gnostic v0.6.9 h1:ZK/5VhkoX835RikCHpSUJV9a+S3e1zLh59YnyWeBW+0=
47+
github.com/google/gnostic v0.6.9/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E=
4448
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
4549
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
4650
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
4751
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
4852
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
49-
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
5053
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
54+
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
55+
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
5156
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5257
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
5358
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
54-
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
5559
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
60+
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
61+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
5662
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
57-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
5863
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
64+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
65+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
5966
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
6067
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6168
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@@ -142,8 +149,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
142149
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
143150
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
144151
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
145-
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
146152
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
153+
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
154+
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
147155
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
148156
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
149157
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

http.go

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"go.unistack.org/micro/v3/codec"
2121
"go.unistack.org/micro/v3/errors"
2222
"go.unistack.org/micro/v3/metadata"
23+
"go.unistack.org/micro/v3/selector"
2324
rutil "go.unistack.org/micro/v3/util/reflect"
2425
)
2526

@@ -386,18 +387,7 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
386387
callOpts.Address = []string{h.opts.Proxy}
387388
}
388389

389-
// lookup the route to send the reques to
390-
// TODO apply any filtering here
391-
routes, err := h.opts.Lookup(ctx, req, callOpts)
392-
if err != nil {
393-
return errors.InternalServerError("go.micro.client", err.Error())
394-
}
395-
396-
// balance the list of nodes
397-
next, err := callOpts.Selector.Select(routes)
398-
if err != nil {
399-
return err
400-
}
390+
var next selector.Next
401391

402392
// return errors.New("go.micro.client", "request timeout", 408)
403393
call := func(i int) error {
@@ -412,6 +402,22 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
412402
time.Sleep(t)
413403
}
414404

405+
if next == nil {
406+
var routes []string
407+
// lookup the route to send the reques to
408+
// TODO apply any filtering here
409+
routes, err = h.opts.Lookup(ctx, req, callOpts)
410+
if err != nil {
411+
return errors.InternalServerError("go.micro.client", err.Error())
412+
}
413+
414+
// balance the list of nodes
415+
next, err = callOpts.Selector.Select(routes)
416+
if err != nil {
417+
return err
418+
}
419+
}
420+
415421
node := next()
416422

417423
// make the call
@@ -463,6 +469,8 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
463469
}
464470

465471
func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) {
472+
var err error
473+
466474
// make a copy of call opts
467475
callOpts := h.opts.CallOptions
468476
for _, o := range opts {
@@ -514,18 +522,7 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
514522
callOpts.Address = []string{h.opts.Proxy}
515523
}
516524

517-
// lookup the route to send the reques to
518-
// TODO apply any filtering here
519-
routes, err := h.opts.Lookup(ctx, req, callOpts)
520-
if err != nil {
521-
return nil, errors.InternalServerError("go.micro.client", err.Error())
522-
}
523-
524-
// balance the list of nodes
525-
next, err := callOpts.Selector.Select(routes)
526-
if err != nil {
527-
return nil, err
528-
}
525+
var next selector.Next
529526

530527
call := func(i int) (client.Stream, error) {
531528
// call backoff first. Someone may want an initial start delay
@@ -539,6 +536,22 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
539536
time.Sleep(t)
540537
}
541538

539+
if next == nil {
540+
var routes []string
541+
// lookup the route to send the reques to
542+
// TODO apply any filtering here
543+
routes, err = h.opts.Lookup(ctx, req, callOpts)
544+
if err != nil {
545+
return nil, errors.InternalServerError("go.micro.client", err.Error())
546+
}
547+
548+
// balance the list of nodes
549+
next, err = callOpts.Selector.Select(routes)
550+
if err != nil {
551+
return nil, err
552+
}
553+
}
554+
542555
node := next()
543556

544557
stream, cerr := h.stream(ctx, node, req, callOpts)

0 commit comments

Comments
 (0)