proxy: retrieve ClientURLs from cluster

This is a simple solution to having the proxy keep up to date with the
state of the cluster. Basically, it uses the cluster configuration
provided at start up (i.e. with `-initial-cluster-state`) to determine
where to reach peer(s) in the cluster, and then it will periodically hit
the `/members` endpoint of those peer(s) (using the same mechanism that
`-cluster-state=existing` does to initialise) to update the set of valid
client URLs to proxy to.

This does not address discovery (#1376), and it would probably be better
to update the set of proxyURLs dynamically whenever we fetch the new
state of the cluster; but it needs a bit more thinking to have this done
in a clean way with the proxy interface.

Example in Procfile works again.
This commit is contained in:
Jonathan Boulle
2014-10-24 15:26:05 -07:00
parent 0fcb59e7d9
commit 719c57a29d
7 changed files with 80 additions and 58 deletions

15
main.go
View File

@ -232,11 +232,18 @@ func startProxy() {
log.Fatal(err)
}
ph, err := proxy.NewHandler(pt, cls.PeerURLs())
if err != nil {
log.Fatal(err)
// TODO(jonboulle): update peerURLs dynamically (i.e. when updating
// clientURLs) instead of just using the initial fixed list here
peerURLs := cls.PeerURLs()
uf := func() []string {
cls, err := etcdserver.GetClusterFromPeers(peerURLs)
if err != nil {
log.Printf("etcd: %v", err)
return []string{}
}
return cls.ClientURLs()
}
ph := proxy.NewHandler(pt, uf)
ph = &pkg.CORSHandler{
Handler: ph,
Info: cors,