diff --git a/README.md b/README.md index 4d8e31b..cb36687 100644 --- a/README.md +++ b/README.md @@ -15,17 +15,20 @@ For full example see [this section](#example) *Parameters:* -| Name | Format | Description | -|-------------|--------------------------|-------------------------------------------------------------------------------------------------------------------------------| -| tag | string | Select endpoints only with this tag | -| healthy | true/false | Return only endpoints which pass all health-checks. Default: false | -| wait | as in time.ParseDuration | Wait time for watch changes. Due this time period endpoints will be force refreshed. Default: inherits agent property | -| insecure | true/false | Allow insecure communication with Consul. Default: true | -| near | string | Sort endpoints by response duration. Can be efficient combine with `limit` parameter default: "_agent" | -| limit | int | Limit number of endpoints for the service. Default: no limit | -| timeout | as in time.ParseDuration | Http-client timeout. Default: 60s | -| max-backoff | as in time.ParseDuration | Max backoff time for reconnect to consul. Reconnects will start from 10ms to _max-backoff_ exponentialy with factor 2. Default: 1s | -| token | string | Consul token | +| Name | Format | Description | +|--------------------|--------------------------|-------------------------------------------------------------------------------------------------------------------------------| +| tag | string | Select endpoints only with this tag | +| healthy | true/false | Return only endpoints which pass all health-checks. Default: false | +| wait | as in time.ParseDuration | Wait time for watch changes. Due this time period endpoints will be force refreshed. Default: inherits agent property | +| insecure | true/false | Allow insecure communication with Consul. Default: true | +| near | string | Sort endpoints by response duration. Can be efficient combine with `limit` parameter default: "_agent" | +| limit | int | Limit number of endpoints for the service. Default: no limit | +| timeout | as in time.ParseDuration | Http-client timeout. Default: 60s | +| max-backoff | as in time.ParseDuration | Max backoff time for reconnect to consul. Reconnects will start from 10ms to _max-backoff_ exponentialy with factor 2. Default: 1s | +| token | string | Consul token | +| dc | string | Consul datacenter to choose. Optional | +| allow-stale | true/false | Allow stale results from the agent. https://www.consul.io/api/features/consistency.html#stale | +| require-consistent | true/false | RequireConsistent forces the read to be fully consistent. This is more expensive but prevents ever performing a stale read. | ## Example ```go diff --git a/consul.go b/consul.go index a8672f0..b13b46c 100644 --- a/consul.go +++ b/consul.go @@ -51,9 +51,12 @@ func watchConsulService(ctx context.Context, s servicer, tgt target, out chan<- tgt.Tag, tgt.Healthy, &api.QueryOptions{ - WaitIndex: lastIndex, - Near: tgt.Near, - WaitTime: tgt.Wait, + WaitIndex: lastIndex, + Near: tgt.Near, + WaitTime: tgt.Wait, + Datacenter: tgt.Dc, + AllowStale: tgt.AllowStale, + RequireConsistent: tgt.RequireConsistent, }, ) if err != nil { diff --git a/go.mod b/go.mod index a0d4c96..13cbfee 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.0 // indirect github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 // indirect github.com/hashicorp/serf v0.8.1 // indirect - github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7 // indirect + github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7 github.com/mitchellh/go-homedir v1.0.0 // indirect github.com/mitchellh/mapstructure v1.1.2 // indirect github.com/percolate/charlatan v1.0.5 // indirect diff --git a/go.sum b/go.sum index dd91355..76149fe 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,17 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-playground/form v3.1.3+incompatible h1:GY0v2KFh5AYLVffrkgCFcaN7hcFaX8VXMOAGQ+WtpZs= github.com/go-playground/form v3.1.3+incompatible/go.mod h1:lhcKXfTuhRtIZCIKUeJ0b5F207aeQCPbZU09ScKjwWg= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/hashicorp/consul v1.2.3 h1:ekX+fXQ7NYzD2quCCgmDekCCIp0Fsi1NE0ViC2CJm+8= github.com/hashicorp/consul v1.2.3/go.mod h1:mFrjN1mfidgJfYP1xrJCF+AfRhr6Eaqhb2+sfyn/OOI= github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 h1:9HVkPxOpo+yO93Ah4yrO67d/qh0fbLLWbKqhYjyHq9A= +github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 h1:VBj0QYQ0u2MCJzBfeYXGexnAl17GsH1yidnoxCqqD9E= github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90/go.mod h1:o4zcYY1e0GEZI6eSEr+43QDYmuGglw1qSO6qdHUHCgg= github.com/hashicorp/serf v0.8.1 h1:mYs6SMzu72+90OcPa5wr3nfznA4Dw9UyR791ZFNOIf4= github.com/hashicorp/serf v0.8.1/go.mod h1:h/Ru6tmZazX7WO/GDmwdpS975F019L4t5ng5IgwbNrE= @@ -25,32 +23,22 @@ github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnG github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/percolate/charlatan v1.0.5 h1:oXiGDWNM/9uHYm0X3upWLevqODAy49vmrKAFya2msog= github.com/percolate/charlatan v1.0.5/go.mod h1:rbsO+LTKjgLd+sGYdTryJHLJZ2f2fbLhpH3+IfsacWk= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.1.1 h1:VzGj7lhU7KEB9e9gMpAV/v5XT2NVSvLJhJLCWbnkgXg= github.com/sirupsen/logrus v1.1.1/go.mod h1:zrgwTnHtNr00buQ1vSptGe8m1f/BbgsPukg8qsT7A+A= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52 h1:JG/0uqcGdTNgq7FdU+61l5Pdmb8putNZlXb65bJBROs= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/grpc v1.2.1-0.20181011201045-c05280cc73cd h1:v9jzEUwtfbZGqmG5Vx0jvJ33997QiWwOIr3pvZgSGRU= google.golang.org/grpc v1.2.1-0.20181011201045-c05280cc73cd/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= diff --git a/target.go b/target.go index 6c26f1f..ca7e469 100644 --- a/target.go +++ b/target.go @@ -13,19 +13,22 @@ import ( ) type target struct { - Addr string `form:"-"` - User string `form:"-"` - Password string `form:"-"` - Service string `form:"-"` - Wait time.Duration `form:"wait"` - Timeout time.Duration `form:"timeout"` - MaxBackoff time.Duration `form:"max-backoff"` - Tag string `form:"tag"` - Near string `form:"near"` - Limit int `form:"limit"` - Healthy bool `form:"healthy"` - TLSInsecure bool `form:"insecure"` - Token string `form:"token"` + Addr string `form:"-"` + User string `form:"-"` + Password string `form:"-"` + Service string `form:"-"` + Wait time.Duration `form:"wait"` + Timeout time.Duration `form:"timeout"` + MaxBackoff time.Duration `form:"max-backoff"` + Tag string `form:"tag"` + Near string `form:"near"` + Limit int `form:"limit"` + Healthy bool `form:"healthy"` + TLSInsecure bool `form:"insecure"` + Token string `form:"token"` + Dc string `form:"dc"` + AllowStale bool `form:"allow-stale"` + RequireConsistent bool `form:"require-consistent"` // TODO(mbobakov): custom parameters for the http-transport // TODO(mbobakov): custom parameters for the TLS subsystem } diff --git a/target_test.go b/target_test.go index 351c48d..8fd447c 100644 --- a/target_test.go +++ b/target_test.go @@ -24,19 +24,22 @@ func Test_parseURL(t *testing.T) { }, false, }, - {"all-args", "consul://user:password@127.0.0.127:8555/my-service?wait=14s&near=host&insecure=true&limit=1&tag=production&token=test_token&max-backoff=2s", + {"all-args", "consul://user:password@127.0.0.127:8555/my-service?wait=14s&near=host&insecure=true&limit=1&tag=production&token=test_token&max-backoff=2s&dc=xx&allow-stale=true&require-consistent=true", target{ - Addr: "127.0.0.127:8555", - User: "user", - Password: "password", - Service: "my-service", - Near: "host", - Wait: 14 * time.Second, - TLSInsecure: true, - Limit: 1, - Tag: "production", - Token: "test_token", - MaxBackoff: 2 * time.Second, + Addr: "127.0.0.127:8555", + User: "user", + Password: "password", + Service: "my-service", + Near: "host", + Wait: 14 * time.Second, + TLSInsecure: true, + Limit: 1, + Tag: "production", + Token: "test_token", + MaxBackoff: 2 * time.Second, + Dc: "xx", + AllowStale: true, + RequireConsistent: true, }, false, },