Skip to content

Commit

Permalink
fix missed updates, report all cluster misses
Browse files Browse the repository at this point in the history
  • Loading branch information
aryszka committed Jan 17, 2016
1 parent 7500a92 commit 9c77794
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"net/url"
"path"
"strconv"
"strings"
)

const (
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 9c77794

Please sign in to comment.