From 1869131407c899b6c03b571a1e2e61f70934d34d Mon Sep 17 00:00:00 2001 From: Jack Murdock Date: Fri, 31 May 2019 16:33:19 -0700 Subject: [PATCH 1/3] retry on non 2XX status codes --- src/caduceus/outboundSender.go | 3 +++ src/glide.lock | 48 +++++++++++++++++----------------- src/glide.yaml | 2 +- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/caduceus/outboundSender.go b/src/caduceus/outboundSender.go index 3a8606d3..4c008645 100644 --- a/src/caduceus/outboundSender.go +++ b/src/caduceus/outboundSender.go @@ -515,6 +515,9 @@ func (obs *CaduceusOutboundSender) send(secret, acceptType string, msg *wrp.Mess Counter: obs.deliveryRetryCounter.With("url", obs.id, "event", event), // Always retry on failures up to the max count. ShouldRetry: func(error) bool { return true }, + ShouldRetryStatus: func(code int) bool { + return code < 200 && code > 299 + }, } // Send it diff --git a/src/glide.lock b/src/glide.lock index 1fbbb53b..b5c899d6 100644 --- a/src/glide.lock +++ b/src/glide.lock @@ -1,5 +1,5 @@ -hash: 8e0b5dc0f4fcee573e27644aa4b665502fecb68c941dad21430d3f491ee8519d -updated: 2019-03-19T17:17:52.093918-06:00 +hash: 08a81032ec0922b02b1a24a26be20ed5e2eddfdef877123ad8b6a7a5bfbbdb3f +updated: 2019-05-31T16:30:04.955833-07:00 imports: - name: github.com/armon/go-metrics version: 783273d703149aaeb9897cf58613d5af48861c25 @@ -42,7 +42,7 @@ imports: subpackages: - linux - name: github.com/Comcast/webpa-common - version: ee36b7e7561c779aa65a66fbef35b46720486987 + version: af2102421561cc50aa301642bb52a8376d834a61 subpackages: - concurrent - convey @@ -72,16 +72,16 @@ imports: - xmetrics - xviper - name: github.com/Comcast/wrp-go - version: a1be47de16c373712b073ce49ee15f88e593a155 + version: 277fd65d1b8ff9579b94cc01f90e87da2967f05a subpackages: - wrp - wrp/wrphttp - name: github.com/davecgh/go-spew - version: 8991bc29aa16c548c550c7ff78260e27b9ab7c73 + version: d8f796af33cc11cb798c1aaeb27a4ebc5099927d subpackages: - spew - name: github.com/fsnotify/fsnotify - version: c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9 + version: 1485a34d5d5723fea214f5710708e19a831720e4 - name: github.com/go-ini/ini version: bda519ae5f4cbc60d391ff8610711627a08b86ae - name: github.com/go-kit/kit @@ -111,7 +111,7 @@ imports: - name: github.com/go-logfmt/logfmt version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5 - name: github.com/golang/protobuf - version: 925541529c1fa6821df4e44ce2723319eb2be768 + version: b4deda0973fb4c70b50d226b1af49f3da59f5265 subpackages: - proto - name: github.com/gorilla/context @@ -121,11 +121,11 @@ imports: - name: github.com/gorilla/websocket version: ea4d1f681babbce9545c9c5f3d5194a789c89f5b - name: github.com/hashicorp/consul - version: 9a494b5fb9c86180a5702e29c485df1507a47198 + version: c97c712e96e0e53308054d5e1180289fe02dce38 subpackages: - api - name: github.com/hashicorp/go-cleanhttp - version: d5fe4b57a186c716b0e00b8c301cbd9b4182694d + version: e8ab9daed8d1ddd2d3c4efba338fe2eeae2e4f18 - name: github.com/hashicorp/go-immutable-radix version: 7f3cd4390caab3250a57f30efdb2a65dd7649ecf - name: github.com/hashicorp/go-rootcerts @@ -135,7 +135,7 @@ imports: subpackages: - simplelru - name: github.com/hashicorp/hcl - version: ef8a98b0bbce4a65b5aa4c368430a80ddc533168 + version: 65a6292f0157eff210d03ed1bf6c59b190b8b906 subpackages: - hcl/ast - hcl/parser @@ -151,7 +151,7 @@ imports: subpackages: - coordinate - name: github.com/influxdata/influxdb - version: 48797873ee24fc1dcb5a63f23474d3210f6d68c5 + version: de58584ce723da61d6cce6c4b92131143c06eea4 subpackages: - client/v2 - models @@ -165,7 +165,7 @@ imports: - name: github.com/kr/logfmt version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0 - name: github.com/magiconair/properties - version: c2353362d570a7bfa228149c62842019201cfb71 + version: 7757cc9fdb852f7579b24170bcacda2c7471bb6a - name: github.com/matttproud/golang_protobuf_extensions version: c12348ce28de40eed0136aa2b644d0ee0650e56c subpackages: @@ -175,11 +175,11 @@ imports: - name: github.com/mitchellh/go-homedir version: b8bc1bf767474819792c23f32d8286a45736f1c6 - name: github.com/mitchellh/mapstructure - version: bb74f1db0675b241733089d5a1faa5dd8b0ef57b + version: 3536a929edddb9a5b34bd6861dc4a9647cb459fe - name: github.com/pelletier/go-toml - version: c01d1270ff3e442a8a57cddc1c92dc1138598194 + version: 690ec00a4b7e125266cf1c4725ae24af22564f8f - name: github.com/pmezard/go-difflib - version: 792786c7400a136282c1664665ae0a8db921c6c2 + version: 5d4384ee4fb2527b0a1256a821ebfc92f91efefc subpackages: - difflib - name: github.com/prometheus/client_golang @@ -193,7 +193,7 @@ imports: subpackages: - go - name: github.com/prometheus/common - version: 7600349dcfe1abd18d72d3a1770870d9800a7801 + version: d811d2e9bf898806ecfb6ef6296774b13ffc314c subpackages: - expfmt - internal/bitbucket.org/ww/goautoneg @@ -219,19 +219,19 @@ imports: - name: github.com/spaolacci/murmur3 version: 0d12bf811670bf6a1a63828dfbd003eded177fce - name: github.com/spf13/afero - version: 787d034dfe70e44075ccc060d346146ef53270ad + version: f4711e4db9e9a1d3887343acb72b2bbfc2f686f5 subpackages: - mem - name: github.com/spf13/cast - version: 8965335b8c7107321228e3e3702cab9832751bac + version: 8c9545af88b134710ab1cd196795e7f2388358d7 - name: github.com/spf13/jwalterweatherman - version: 7c0cea34c8ece3fbeb2b27ab9b59511d360fb394 + version: 94f6ae3ed3bceceafa716478c5fbf8d29ca601a1 - name: github.com/spf13/pflag version: e57e3eeb33f795204c1ca35f56c44f83227c6e66 - name: github.com/spf13/viper version: 6d33b5a963d922d182c91e8a1c88d81fd150cfd4 - name: github.com/stretchr/objx - version: 9e1dfc121bca96d392da5d00591953bdb54ab306 + version: c61a9dfcced1815e7d40e214d00d1a8669a9f58c - name: github.com/stretchr/testify version: 12b6f73e6084dad08a7c6e575284b177ecafbc71 subpackages: @@ -246,7 +246,7 @@ imports: - name: github.com/VividCortex/gohistogram version: 51564d9861991fb0ad0f531c99ef602d0f9866e6 - name: golang.org/x/crypto - version: 74369b46fc6756741c016591724fd1cb8e26845f + version: e3636079e1a4c1f337f212cc5cd2aca108f6c900 subpackages: - ed25519 - ed25519/internal/edwards25519 @@ -259,16 +259,16 @@ imports: - ipv4 - ipv6 - name: golang.org/x/sys - version: 7138fd3d9dc8335c567ca206f4333fb75eb05d56 + version: a2f829d7f35f2ed1c3520c553a6226495455cae0 subpackages: - unix - name: golang.org/x/text - version: 5cec4b58c438bd98288aeb248bab2c1840713d21 + version: 5d731a35f4867878fc89f7744f7b6debb3beded6 subpackages: - transform - unicode/norm - name: gopkg.in/natefinch/lumberjack.v2 version: a96e63847dc3c67d17befa69c303767e2f84e54f - name: gopkg.in/yaml.v2 - version: 5420a8b6744d3b0345ab293f6fcba19c978f1183 + version: 51d6538a90f86fe93ac480b35f37b2be17fef232 testImports: [] diff --git a/src/glide.yaml b/src/glide.yaml index f22625c4..d0cf7fc5 100644 --- a/src/glide.yaml +++ b/src/glide.yaml @@ -1,6 +1,6 @@ package: . import: - package: github.com/Comcast/webpa-common - version: ee36b7e7561c779aa65a66fbef35b46720486987 + version: af2102421561cc50aa301642bb52a8376d834a61 - package: github.com/satori/go.uuid version: f58768cc1a7a7e77a3bd49e98cdd21419399b6a3 From a1a71479d0933b98622ef1e3516d9e3c8f61138d Mon Sep 17 00:00:00 2001 From: Jack Murdock Date: Fri, 31 May 2019 16:41:00 -0700 Subject: [PATCH 2/3] add unit tests --- src/caduceus/outboundSender.go | 2 +- src/caduceus/outboundSender_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/caduceus/outboundSender.go b/src/caduceus/outboundSender.go index 4c008645..f6d983d7 100644 --- a/src/caduceus/outboundSender.go +++ b/src/caduceus/outboundSender.go @@ -516,7 +516,7 @@ func (obs *CaduceusOutboundSender) send(secret, acceptType string, msg *wrp.Mess // Always retry on failures up to the max count. ShouldRetry: func(error) bool { return true }, ShouldRetryStatus: func(code int) bool { - return code < 200 && code > 299 + return code < 200 || code > 299 }, } diff --git a/src/caduceus/outboundSender_test.go b/src/caduceus/outboundSender_test.go index 8a31556f..761d64aa 100644 --- a/src/caduceus/outboundSender_test.go +++ b/src/caduceus/outboundSender_test.go @@ -104,6 +104,7 @@ func simpleFactorySetup(trans *transport, cutOffPeriod time.Duration, matcher [] On("With", []string{"url", w.Config.URL, "code", "201"}).Return(fakeDC). On("With", []string{"url", w.Config.URL, "code", "202"}).Return(fakeDC). On("With", []string{"url", w.Config.URL, "code", "204"}).Return(fakeDC). + On("With", []string{"url", w.Config.URL, "code", "429", "event", "iot"}).Return(fakeDC). On("With", []string{"url", w.Config.URL, "code", "failure"}).Return(fakeDC) fakeDC.On("Add", 1.0).Return() fakeDC.On("Add", 0.0).Return() @@ -218,6 +219,31 @@ func TestSimpleRetry(t *testing.T) { assert.Equal(int32(2), trans.i) } +func Test429Retry(t *testing.T) { + + assert := assert.New(t) + + trans := &transport{} + trans.fn = func(req *http.Request, count int) (*http.Response, error) { + return &http.Response{StatusCode: 429}, nil + } + + obs, err := simpleSetup(trans, time.Second, nil) + + assert.NotNil(obs) + assert.Nil(err) + + req := simpleRequest() + req.Source = "mac:112233445566" + req.TransactionUUID = "1234" + req.Destination = "event:iot" + obs.Queue(req) + + obs.Shutdown(true) + + assert.Equal(int32(2), trans.i) +} + // Simple test that covers the normal successful case with extra matchers func TestSimpleWrpWithMatchers(t *testing.T) { From 7b2600de2984ba1735053fcf260a4689871a3e54 Mon Sep 17 00:00:00 2001 From: Jack Murdock Date: Fri, 31 May 2019 16:43:09 -0700 Subject: [PATCH 3/3] updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4820699b..b0d3ac94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Changed -- +- retry on non 2xx status codes ## [0.1.3] - 2019-02-27 ### Changed