From 9c77794ab89584755c7d6e0539aacb2f5af87b9b Mon Sep 17 00:00:00 2001 From: Arpad Ryszka Date: Sun, 17 Jan 2016 02:22:19 +0100 Subject: [PATCH] fix missed updates, report all cluster misses --- etcd/etcd.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/etcd/etcd.go b/etcd/etcd.go index 04e9bf12f1..c3dc40b2c3 100644 --- a/etcd/etcd.go +++ b/etcd/etcd.go @@ -41,6 +41,7 @@ import ( "net/url" "path" "strconv" + "strings" ) const ( @@ -61,6 +62,20 @@ type response struct { Node *node `json:"node"` } +type endpointErrors struct { + errors []error +} + +func (ee *endpointErrors) Error() string { + es := make([]string, len(ee.errors)+1) + es[0] = "request to one or more endpoints failed" + for i, e := range ee.errors { + es[i+1] = e.Error() + } + + return strings.Join(es, ";") +} + // A Client is used to load the whole set of routes and the updates from an // etcd store. type Client struct { @@ -98,10 +113,11 @@ type makeRequest func(string) (*http.Request, error) func (c *Client) tryEndpoints(mreq makeRequest) (*http.Response, error) { var ( - addresses []string - req *http.Request - rsp *http.Response - err error + addresses []string + req *http.Request + rsp *http.Response + err error + endpointErrs []error ) addresses = c.addresses @@ -116,12 +132,17 @@ func (c *Client) tryEndpoints(mreq makeRequest) (*http.Response, error) { break } + endpointErrs = append(endpointErrs, err) addresses = addresses[1:] } rotate := len(c.addresses) - len(addresses) c.addresses = append(c.addresses[rotate:], c.addresses[:rotate]...) + if len(addresses) == 0 { + err = &endpointErrors{endpointErrs} + } + return rsp, err } @@ -343,10 +364,6 @@ func (c *Client) LoadUpdate() ([]*eskip.Route, []string, error) { // this is going to be the tricky part data, etcdIndex := c.iterateDefs(response.Node, c.etcdIndex) - if response.etcdIndex > etcdIndex { - etcdIndex = response.etcdIndex - } - c.etcdIndex = etcdIndex var (