Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for znode flag #19

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 9 additions & 11 deletions finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
)
Expand Down Expand Up @@ -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)
}
Expand Down