Esempio n. 1
0
		conf = config.Config{
			JobName: "doppler_z1",
			Index:   0,
			EtcdMaxConcurrentRequests: 1,
			EtcdUrls:                  []string{fmt.Sprintf("http://127.0.0.1:%d", etcdPort)},
			Zone:                      "z1",
			ContainerMetricTTLSeconds:     120,
			DropsondeIncomingMessagesPort: 1234,
		}
	})

	Context("Heartbeats", func() {
		It("arrives safely in etcd", func() {
			storeAdapter := setupAdapter(legacyETCDKey, conf)

			legacyReleaseChan := announcer.AnnounceLegacy(localIp, time.Second, &conf, storeAdapter, loggertesthelper.Logger())
			defer close(legacyReleaseChan)

			Eventually(func() error {
				_, err := storeAdapter.Get(legacyETCDKey)
				return err
			}, 3).ShouldNot(HaveOccurred())
		})
	})

	Context("Store Transport", func() {
		Context("With EnableTlsTransport set to true", func() {
			It("stores udp and tcp transport in etcd", func() {
				conf.EnableTLSTransport = true
				conf.TLSListenerConfig = config.TLSListenerConfig{
					Port: 4567,
Esempio n. 2
0
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)
	dopplerStoreAdapter := NewStoreAdapter(conf.EtcdUrls, conf.EtcdMaxConcurrentRequests)
	legacyStoreAdapter := NewStoreAdapter(conf.EtcdUrls, conf.EtcdMaxConcurrentRequests)

	doppler := New(localIp, conf, log, dopplerStoreAdapter, conf.MessageDrainBufferSize, DOPPLER_ORIGIN, time.Duration(conf.SinkDialTimeoutSeconds)*time.Second)

	if err != nil {
		panic(err)
	}

	go doppler.Start()
	log.Info("Startup: doppler server started.")

	killChan := make(chan os.Signal)
	signal.Notify(killChan, os.Kill, os.Interrupt)

	dumpChan := registerGoRoutineDumpSignalChannel()

	releaseNodeChan := announcer.Announce(localIp, config.HeartbeatInterval, conf, dopplerStoreAdapter, log)
	legacyReleaseNodeChan := announcer.AnnounceLegacy(localIp, config.HeartbeatInterval, conf, legacyStoreAdapter, log)

	for {
		select {
		case <-dumpChan:
			logger.DumpGoRoutine()
		case <-killChan:
			log.Info("Shutting down")
			doppler.Stop()
			close(releaseNodeChan)
			close(legacyReleaseNodeChan)
			return
		}
	}
}
Esempio n. 3
0
		})
	})

	Context("without a valid ETCD config", func() {
		It("does not send a heartbeat", func() {
			conf := config.Config{
				JobName: "doppler_z1",
				Index:   0,
				EtcdMaxConcurrentRequests: 10,
			}

			announcer.Announce(localIP, time.Second, &conf, adapter, loggertesthelper.Logger())
			Expect(adapter.GetMaintainedNodeName()).To(BeEmpty())
		})
	})

	Context("AnnounceLegacy", func() {
		var legacyKey string
		BeforeEach(func() {
			legacyKey = fmt.Sprintf("/healthstatus/doppler/%s/%s/%d", conf.Zone, conf.JobName, conf.Index)
		})
		It("Should maintain legacy healthstatus key and value", func() {

			announcer.AnnounceLegacy(localIP, time.Second, &conf, adapter, loggertesthelper.Logger())
			Expect(adapter.GetMaintainedNodeName()).To(Equal(legacyKey))
			Expect(string(adapter.MaintainedNodeValue)).To(Equal(localIP))
		})
	})

})