Esempio n. 1
0
	"strconv"

	"code.cloudfoundry.org/gorouter/common/health"
	"code.cloudfoundry.org/gorouter/common/schema"
	"code.cloudfoundry.org/lager"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"encoding/json"
)

var _ = Describe("Varz", func() {

	It("contains expected keys", func() {
		varz := &health.Varz{}
		varz.LogCounts = schema.NewLogCounter()

		bytes, err := json.Marshal(varz)
		Expect(err).ToNot(HaveOccurred())

		data := make(map[string]interface{})
		err = json.Unmarshal(bytes, &data)
		Expect(err).ToNot(HaveOccurred())

		members := []string{
			"type",
			"index",
			"host",
			"credentials",
			"start",
			"uuid",
Esempio n. 2
0
		sslPort := test_util.NextAvailPort()

		cert, err := tls.LoadX509KeyPair("../test/assets/certs/server.pem", "../test/assets/certs/server.key")
		Expect(err).ToNot(HaveOccurred())

		config = test_util.SpecConfig(statusPort, proxyPort, natsPort)
		config.EnableSSL = true
		config.SSLPort = sslPort
		config.SSLCertificate = cert
		config.CipherSuites = []uint16{tls.TLS_RSA_WITH_AES_256_CBC_SHA}
		config.EndpointTimeout = 5 * time.Second

		mbusClient = natsRunner.MessageBus
		registry = rregistry.NewRouteRegistry(logger, config, new(fakes.FakeRouteRegistryReporter))
		varz = vvarz.NewVarz(registry)
		logcounter := schema.NewLogCounter()
		atomic.StoreInt32(&healthCheck, 0)
		p = proxy.NewProxy(proxy.ProxyArgs{
			Logger:               logger,
			EndpointTimeout:      config.EndpointTimeout,
			Ip:                   config.Ip,
			TraceKey:             config.TraceKey,
			Registry:             registry,
			Reporter:             varz,
			AccessLogger:         &access_log.NullAccessLogger{},
			HealthCheckUserAgent: "HTTP-Monitor/1.1",
			HeartbeatOK:          &healthCheck,
		})

		errChan := make(chan error, 2)
		rtr, err = router.NewRouter(logger, config, p, mbusClient, registry, varz, &healthCheck, logcounter, errChan)
Esempio n. 3
0
	)

	BeforeEach(func() {
		infoMsg = lager.LogFormat{
			LogLevel: lager.INFO,
			Message:  "info-message",
		}

		errMsg = lager.LogFormat{
			LogLevel: lager.ERROR,
			Message:  "error-message",
		}
	})

	It("counts the number of records", func() {
		counter := schema.NewLogCounter()
		counter.Log(infoMsg)
		Expect(counter.GetCount(strconv.Itoa(int(lager.INFO)))).To(Equal(1))

		counter.Log(infoMsg)
		Expect(counter.GetCount(strconv.Itoa(int(lager.INFO)))).To(Equal(2))
	})

	It("counts all log levels", func() {
		counter := schema.NewLogCounter()
		counter.Log(infoMsg)
		Expect(counter.GetCount(strconv.Itoa(int(lager.INFO)))).To(Equal(1))

		counter.Log(errMsg)
		Expect(counter.GetCount(strconv.Itoa(int(lager.ERROR)))).To(Equal(1))
	})
Esempio n. 4
0
func main() {
	flag.StringVar(&configFile, "c", "", "Configuration File")
	flag.Parse()

	c := config.DefaultConfig()
	logCounter := schema.NewLogCounter()

	if configFile != "" {
		c = config.InitConfigFromFile(configFile)
	}

	prefix := "gorouter.stdout"
	if c.Logging.Syslog != "" {
		prefix = c.Logging.Syslog
	}
	logger, reconfigurableSink := lagerflags.NewFromConfig(prefix,
		lagerflags.LagerConfig{LogLevel: c.Logging.Level})

	logger.Info("starting")

	err := dropsonde.Initialize(c.Logging.MetronAddress, c.Logging.JobName)
	if err != nil {
		logger.Fatal("dropsonde-initialize-error", err)
	}

	// setup number of procs
	if c.GoMaxProcs != 0 {
		runtime.GOMAXPROCS(c.GoMaxProcs)
	}

	if c.DebugAddr != "" {
		debugserver.Run(c.DebugAddr, reconfigurableSink)
	}

	logger.Info("setting-up-nats-connection")
	startMsgChan := make(chan struct{})
	natsClient := connectToNatsServer(logger.Session("nats"), c, startMsgChan)

	metricsReporter := metrics.NewMetricsReporter()
	registry := rregistry.NewRouteRegistry(logger.Session("registry"), c, metricsReporter)
	if c.SuspendPruningIfNatsUnavailable {
		registry.SuspendPruning(func() bool { return !(natsClient.Status() == nats.CONNECTED) })
	}

	subscriber := createSubscriber(logger, c, natsClient, registry, startMsgChan)

	varz := rvarz.NewVarz(registry)
	compositeReporter := metrics.NewCompositeReporter(varz, metricsReporter)

	accessLogger, err := access_log.CreateRunningAccessLogger(logger.Session("access-log"), c)
	if err != nil {
		logger.Fatal("error-creating-access-logger", err)
	}

	var crypto secure.Crypto
	var cryptoPrev secure.Crypto
	if c.RouteServiceEnabled {
		crypto = createCrypto(logger, c.RouteServiceSecret)
		if c.RouteServiceSecretPrev != "" {
			cryptoPrev = createCrypto(logger, c.RouteServiceSecretPrev)
		}
	}

	proxy := buildProxy(logger.Session("proxy"), c, registry, accessLogger, compositeReporter, crypto, cryptoPrev)
	healthCheck = 0
	router, err := router.NewRouter(logger.Session("router"), c, proxy, natsClient, registry, varz, &healthCheck, logCounter, nil)
	if err != nil {
		logger.Fatal("initialize-router-error", err)
	}

	members := grouper.Members{
		grouper.Member{Name: "subscriber", Runner: subscriber},
		grouper.Member{Name: "router", Runner: router},
	}
	if c.RoutingApiEnabled() {
		logger.Info("setting-up-routing-api")
		routeFetcher := setupRouteFetcher(logger.Session("route-fetcher"), c, registry)

		// check connectivity to routing api
		err = routeFetcher.FetchRoutes()
		if err != nil {
			logger.Fatal("routing-api-connection-failed", err)
		}
		members = append(members, grouper.Member{Name: "router-fetcher", Runner: routeFetcher})
	}

	group := grouper.NewOrdered(os.Interrupt, members)

	monitor := ifrit.Invoke(sigmon.New(group, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1))

	err = <-monitor.Wait()
	if err != nil {
		logger.Error("gorouter.exited-with-failure", err)
		os.Exit(1)
	}

	os.Exit(0)
}