func main() { seed := time.Now().UnixNano() rand.Seed(seed) flag.Parse() runtime.GOMAXPROCS(runtime.NumCPU()) localIp, err := localip.LocalIP() if err != nil { panic(errors.New("Unable to resolve own IP address: " + err.Error())) } if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { panic(err) } pprof.StartCPUProfile(f) defer func() { pprof.StopCPUProfile() f.Close() }() } if *memprofile != "" { f, err := os.Create(*memprofile) if err != nil { panic(err) } go func() { defer f.Close() ticker := time.NewTicker(time.Second * 1) defer ticker.Stop() for { <-ticker.C pprof.WriteHeapProfile(f) } }() } conf, err := config.ParseConfig(*configFile) if err != nil { panic(err) } log := logger.NewLogger(*logLevel, *logFilePath, "doppler", conf.Syslog) log.Info("Startup: Setting up the doppler server") dropsonde.Initialize(conf.MetronAddress, DOPPLER_ORIGIN) storeAdapter := NewStoreAdapter(conf.EtcdUrls, conf.EtcdMaxConcurrentRequests) doppler, err := New(log, localIp, conf, storeAdapter, conf.MessageDrainBufferSize, DOPPLER_ORIGIN, time.Duration(conf.WebsocketWriteTimeoutSeconds)*time.Second, time.Duration(conf.SinkDialTimeoutSeconds)*time.Second) if err != nil { log.Errorf("Failed to create doppler: %s", err.Error()) os.Exit(-1) } go doppler.Start() log.Info("Startup: doppler server started.") killChan := make(chan os.Signal) signal.Notify(killChan, os.Kill, os.Interrupt) dumpChan := registerGoRoutineDumpSignalChannel() releaseNodeChan := dopplerservice.Announce(localIp, config.HeartbeatInterval, conf, storeAdapter, log) legacyReleaseNodeChan := dopplerservice.AnnounceLegacy(localIp, config.HeartbeatInterval, conf, storeAdapter, log) for { select { case <-dumpChan: logger.DumpGoRoutine() case <-killChan: log.Info("Shutting down") stopped := make(chan bool) legacyStopped := make(chan bool) releaseNodeChan <- stopped legacyReleaseNodeChan <- legacyStopped doppler.Stop() <-stopped <-legacyStopped os.Exit(0) } } }
}).Should(MatchJSON(dopplerMeta)) }) }) }) }) Context("AnnounceLegacy", func() { var legacyKey string BeforeEach(func() { legacyKey = fmt.Sprintf("/healthstatus/doppler/%s/%s/%d", conf.Zone, conf.JobName, conf.Index) }) It("maintains the node", func() { fakeadapter := &fakes.FakeStoreAdapter{} dopplerservice.AnnounceLegacy(localIP, time.Second, &conf, fakeadapter, loggertesthelper.Logger()) Expect(fakeadapter.MaintainNodeCallCount()).To(Equal(1)) }) It("Panics if MaintainNode returns error", func() { err := errors.New("some etcd time out error") fakeadapter := &fakes.FakeStoreAdapter{} fakeadapter.MaintainNodeReturns(nil, nil, err) Expect(func() { dopplerservice.AnnounceLegacy(localIP, time.Second, &conf, fakeadapter, loggertesthelper.Logger()) }).To(Panic()) }) It("Should maintain legacy healthstatus key and value", func() { stopChan = dopplerservice.AnnounceLegacy(localIP, time.Second, &conf, etcdAdapter, loggertesthelper.Logger()) Eventually(func() []byte {
func main() { seed := time.Now().UnixNano() rand.Seed(seed) flag.Parse() runtime.GOMAXPROCS(runtime.NumCPU()) localIp, err := localip.LocalIP() if err != nil { panic(fmt.Errorf("Unable to resolve own IP address: %s", err)) } conf, err := config.ParseConfig(*configFile) if err != nil { panic(fmt.Errorf("Unable to parse config: %s", err)) } log := logger.NewLogger(*logLevel, *logFilePath, "doppler", conf.Syslog) go func() { err := http.ListenAndServe(net.JoinHostPort(localIp, pprofPort), nil) if err != nil { log.Errorf("Error starting pprof server: %s", err.Error()) } }() log.Info("Startup: Setting up the doppler server") dropsonde.Initialize(conf.MetronAddress, DOPPLER_ORIGIN) storeAdapter := NewStoreAdapter(conf.EtcdUrls, conf.EtcdMaxConcurrentRequests) doppler, err := New(log, localIp, conf, storeAdapter, conf.MessageDrainBufferSize, DOPPLER_ORIGIN, time.Duration(conf.WebsocketWriteTimeoutSeconds)*time.Second, time.Duration(conf.SinkDialTimeoutSeconds)*time.Second) if err != nil { panic(fmt.Errorf("Failed to create doppler: %s", err)) } go doppler.Start() log.Info("Startup: doppler server started.") killChan := signalmanager.RegisterKillSignalChannel() dumpChan := signalmanager.RegisterGoRoutineDumpSignalChannel() releaseNodeChan := dopplerservice.Announce(localIp, config.HeartbeatInterval, conf, storeAdapter, log) legacyReleaseNodeChan := dopplerservice.AnnounceLegacy(localIp, config.HeartbeatInterval, conf, storeAdapter, log) for { select { case <-dumpChan: signalmanager.DumpGoRoutine() case <-killChan: log.Info("Shutting down") stopped := make(chan bool) legacyStopped := make(chan bool) releaseNodeChan <- stopped legacyReleaseNodeChan <- legacyStopped doppler.Stop() <-stopped <-legacyStopped return } } }
close(stopTheWorld) close(stopAnnounce) metronRunner.Stop() }) Describe("Metron panics", func() { Context("with Metron configured to requires TLS, and TLS disabled on Doppler", func() { BeforeEach(func() { protocols = []config.Protocol{"tls"} dopplerConfig.EnableTLSTransport = false }) Context("with Doppler advertising only on legacy endpoint", func() { It("panics", func() { stopAnnounce = dopplerservice.AnnounceLegacy("127.0.0.1", time.Minute, dopplerConfig, etcdAdapter, logger) Eventually(metronRunner.Process.Wait()).Should(Receive()) }) }) Context("with Doppler advertising UDP on meta endpoint", func() { It("panics", func() { stopAnnounce = dopplerservice.Announce("127.0.0.1", time.Minute, dopplerConfig, etcdAdapter, logger) Eventually(metronRunner.Process.Wait()).Should(Receive()) }) }) }) }) Describe("Metron doesn't panic", func() { Context("with Doppler advertising over UDP and TCP", func() {
func main() { seed := time.Now().UnixNano() rand.Seed(seed) // Put os.Exit in a deferred statement so that other defers get executed prior to // the os.Exit call. exitCode := 0 defer func() { os.Exit(exitCode) }() flag.Parse() runtime.GOMAXPROCS(runtime.NumCPU()) localIp, err := localip.LocalIP() if err != nil { panic(errors.New("Unable to resolve own IP address: " + err.Error())) } conf, err := config.ParseConfig(*configFile) if err != nil { panic(err) } log := logger.NewLogger(*logLevel, *logFilePath, "doppler", conf.Syslog) log.Info("Startup: Setting up the doppler server") profiler := profiler.New(*cpuprofile, *memprofile, 1*time.Second, log) profiler.Profile() defer profiler.Stop() dropsonde.Initialize(conf.MetronAddress, DOPPLER_ORIGIN) storeAdapter := NewStoreAdapter(conf.EtcdUrls, conf.EtcdMaxConcurrentRequests) doppler, err := New(log, localIp, conf, storeAdapter, conf.MessageDrainBufferSize, DOPPLER_ORIGIN, time.Duration(conf.WebsocketWriteTimeoutSeconds)*time.Second, time.Duration(conf.SinkDialTimeoutSeconds)*time.Second) if err != nil { log.Errorf("Failed to create doppler: %s", err.Error()) exitCode = -1 return } go doppler.Start() log.Info("Startup: doppler server started.") killChan := signalmanager.RegisterKillSignalChannel() dumpChan := signalmanager.RegisterGoRoutineDumpSignalChannel() releaseNodeChan := dopplerservice.Announce(localIp, config.HeartbeatInterval, conf, storeAdapter, log) legacyReleaseNodeChan := dopplerservice.AnnounceLegacy(localIp, config.HeartbeatInterval, conf, storeAdapter, log) for { select { case <-dumpChan: signalmanager.DumpGoRoutine() case <-killChan: log.Info("Shutting down") stopped := make(chan bool) legacyStopped := make(chan bool) releaseNodeChan <- stopped legacyReleaseNodeChan <- legacyStopped doppler.Stop() <-stopped <-legacyStopped return } } }