func setupSourceTest(app, proc, rev, env string) (*visor.Instance, error) { store, err := visor.DialURI(visor.DefaultURI, visor.DefaultRoot) if err != nil { return nil, err } ins, err := store.RegisterInstance(app, rev, proc, env) if err != nil { return nil, err } ins, err = ins.Claim("1.2.3.4") if err != nil { return nil, err } ins, err = ins.Started("1.2.3.4", "lolcathost", 2221, 2222) if err != nil { return nil, err } return ins, nil }
func main() { var ( addr = flag.String("addr", "127.0.0.1:9999", "addr to accept client connections") clientBuffer = flag.Int("client.buffer", 64, "line buffer size for client connections") clientTimeout = flag.Duration("client.timeout", time.Second, "read/write timeout for client connections") doozerURI = flag.String("doozer.uri", visor.DefaultURI, "URI for doozer connection") doozerRoot = flag.String("doozer.root", "/bazooka", "root for data in doozer tree") historyBuffer = flag.Int("history.buffer", 1000, "number of lines of history to keep per topic") logDir = flag.String("log.dir", "/var/log", "location for log directories") telemetryAddr = flag.String("telemetry.addr", "127.0.0.1:9998", "addr to expose telemetry") version = flag.Bool("version", false, "show bazooka-log version") pubc = make(chan Line) subc = make(chan Subscription) unsubc = make(chan Subscription) histc = make(chan HistoryRequest) errc = make(chan error) sigc = make(chan os.Signal, 1) ) flag.Parse() log.SetOutput(os.Stdout) if *version { fmt.Fprintf(os.Stdout, "bazooka-log@%s(%s)", Version, CommitID) os.Exit(0) } logf("main: bazooka-log@%s(%s) started", Version, CommitID) signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) expvar.NewString("commitID").Set(CommitID) expvar.NewString("version").Set(Version) host, _, err := net.SplitHostPort(*addr) if err != nil { log.Fatalf("main: %s", err) } store, err := visor.DialURI(*doozerURI, *doozerRoot) if err != nil { log.Fatalf("main: %s", err) } store, err = store.RegisterLogger(*addr, Version) if err != nil { log.Fatalf("main: %s", err) } collector := &collector{ store: store, host: host, logDir: *logDir, pubc: pubc, errc: errc, lookup: NewLookup(), } server := &server{ buffer: *clientBuffer, timeout: *clientTimeout, subc: subc, unsubc: unsubc, errc: errc, histc: histc, lookup: NewLookup(), } expvar.Publish("collector", collector) expvar.Publish("server", server) go fanout(pubc, subc, unsubc, histc, *historyBuffer) go collector.WatchAndSource() go server.ListenAndServe(*addr) go telemetry(*telemetryAddr, errc) for { select { case err := <-errc: log.Fatal(err) case <-sigc: logf("main: bazooka-log@%s(%s) shutdown", Version, CommitID) signal.Stop(sigc) err := store.UnregisterLogger(*addr) if err != nil { log.Fatalf("main: %s", err) } return } } }