diff --git a/README.md b/README.md index 6139217..6a4e4f6 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Name | Description web.listen-address | Address to listen on for web interface and telemetry. web.telemetry-path | Path under which to expose metrics. exporter.aurora-url | [URL](#aurora-url) to an Aurora scheduler or ZooKeeper ensemble. +zk.path | The path for the aurora scheduler znode, this defaults to `/aurora/scheduler` exporter.bypass-leader-redirect | Don't follow redirects to the leader instance. #### Aurora URL diff --git a/finder.go b/finder.go index ba899ce..7399459 100644 --- a/finder.go +++ b/finder.go @@ -14,22 +14,20 @@ import ( "github.com/samuel/go-zookeeper/zk" ) -const ( - zkPath = "/aurora/scheduler" - zkLeaderPrefix = "singleton_candidate_" -) +const zkLeaderPrefix = "singleton_candidate_" + type finder interface { leaderURL() (string, error) } -func newFinder(url string) (f finder, err error) { +func newFinder(url, znode string) (f finder, err error) { if strings.HasPrefix(url, "http") { f = &httpFinder{url: url} } if strings.HasPrefix(url, "zk://") { - f = newZkFinder(url) + f = newZkFinder(url, znode) } if f == nil { @@ -86,7 +84,7 @@ type zkFinder struct { leaderIP string } -func newZkFinder(url string) *zkFinder { +func newZkFinder(url, znode string) *zkFinder { zkSrvs, err := hostsFromURL(url) if err != nil { panic(err) @@ -104,12 +102,12 @@ func newZkFinder(url string) *zkFinder { }() f := zkFinder{conn: conn} - go f.watch() + go f.watch(znode) return &f } -func (f *zkFinder) leaderzNode() (string, error) { +func (f *zkFinder) leaderzNode(zkPath string) (string, error) { children, stat, err := f.conn.Children(zkPath) if stat == nil { err = errors.New("zkFinder: children returned nil stat") @@ -157,9 +155,9 @@ func (f *zkFinder) leaderURL() (string, error) { return fmt.Sprintf("http://%s:8081", f.leaderIP), nil } -func (f *zkFinder) watch() { +func (f *zkFinder) watch(znode string) { for _ = range time.NewTicker(1 * time.Second).C { - zNode, err := f.leaderzNode() + zNode, err := f.leaderzNode(znode) if err != nil { glog.Warning(err) continue diff --git a/main.go b/main.go index e2987a2..a6c0d31 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ var ( addr = flag.String("web.listen-address", ":9113", "Address to listen on for web interface and telemetry.") auroraURL = flag.String("exporter.aurora-url", "http://127.0.0.1:8081", "URL to an Aurora scheduler or ZooKeeper ensemble") metricPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") + zkPath = flag.String("zk.path", "/aurora/scheduler", "zkNode that aurora maintains master election.") bypassRedirect = flag.Bool("exporter.bypass-leader-redirect", false, "When scraping a HTTP scheduler url, don't follow redirects to the leader instance.") ) @@ -220,7 +221,7 @@ func newRequest(method, urlStr string, body io.Reader, bypass bool) (*http.Reque func main() { flag.Parse() - finder, err := newFinder(*auroraURL) + finder, err := newFinder(*auroraURL, *zkPath) if err != nil { log.Fatal(err) }