Exemplo n.º 1
0
				_, 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,
				}
				storeAdapter := setupAdapter(dopplerETCDKey, conf)

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

				dopplerMeta := createDopplerMeta(localIp, conf)

				Eventually(func() []byte {
					node, _ := storeAdapter.Get(dopplerETCDKey)
					return node.Value
				}, 3).Should(MatchJSON(dopplerMeta))
			})
		})

		Context("With EnableTlsTransport set to false", func() {
			It("only stores udp transport in etcd", func() {
				dopplerMeta := createDopplerMetaNoTLS(localIp, conf)
				conf.EnableTLSTransport = false
Exemplo 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
		}
	}
}
Exemplo n.º 3
0
	BeforeEach(func() {
		adapter = fakestoreadapter.New()
	})

	Context("with valid ETCD config", func() {
		var dopplerKey string

		BeforeEach(func() {
			dopplerKey = fmt.Sprintf("/doppler/meta/%s/%s/%d", conf.Zone, conf.JobName, conf.Index)
		})

		It("Panics if etcd returns error", func() {
			err := errors.New("some etcd time out error")
			adapter.MaintainNodeError = err
			Expect(func() {
				announcer.Announce(localIP, time.Second, &conf, adapter, loggertesthelper.Logger())
			}).To(Panic())
		})

		Context("when tls transport is enabled", func() {
			It("has udp and tcp value", func() {
				dopplerMeta := fmt.Sprintf(`{"version": 1, "ip": "%s", "transports":[{"protocol":"udp","port":1234},{"protocol":"tls","port":4567}]}`, localIP)

				conf.EnableTLSTransport = true
				conf.TLSListenerConfig = config.TLSListenerConfig{
					Port: 4567,
				}
				announcer.Announce(localIP, time.Second, &conf, adapter, loggertesthelper.Logger())

				Expect(adapter.GetMaintainedNodeName()).To(Equal(dopplerKey))
				Expect(adapter.MaintainedNodeValue).To(MatchJSON(dopplerMeta))