Exemplo n.º 1
0
func generateConfig(natsPort, statusPort, proxyPort uint16) *config.Config {
	c := config.DefaultConfig()

	c.Port = proxyPort
	c.Index = 2
	c.TraceKey = "my_trace_key"

	// Hardcode the IP to localhost to avoid leaving the machine while running tests
	c.Ip = "127.0.0.1"

	c.StartResponseDelayInterval = 10 * time.Millisecond
	c.PublishStartMessageIntervalInSeconds = 10
	c.PruneStaleDropletsInterval = 0
	c.DropletStaleThreshold = 0
	c.PublishActiveAppsInterval = 0
	c.Zone = "z1"

	c.EndpointTimeout = 500 * time.Millisecond

	c.Status = config.StatusConfig{
		Port: statusPort,
		User: "******",
		Pass: "******",
	}

	c.Nats = []config.NatsConfig{
		{
			Host: "localhost",
			Port: natsPort,
			User: "******",
			Pass: "******",
		},
	}

	c.Logging = config.LoggingConfig{
		File:          "/dev/stdout",
		Level:         "info",
		MetronAddress: "localhost:3457",
		JobName:       "router_test_z1_0",
	}

	c.OAuth = token_fetcher.OAuthConfig{
		TokenEndpoint: "http://localhost",
		Port:          8080,
	}

	c.RouteServiceSecret = "kCvXxNMB0JO2vinxoru9Hg=="

	return c
}
Exemplo n.º 2
0
)

func TestProxy(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Proxy Suite")
}

var _ = BeforeEach(func() {
	var err error

	crypto, err = secure.NewAesGCM([]byte("ABCDEFGHIJKLMNOP"))
	Expect(err).NotTo(HaveOccurred())

	cryptoPrev = nil

	conf = config.DefaultConfig()
	conf.TraceKey = "my_trace_key"
	conf.EndpointTimeout = 500 * time.Millisecond
})

var _ = JustBeforeEach(func() {
	var err error
	mbus := fakeyagnats.Connect()
	r = registry.NewRouteRegistry(conf, mbus, new(fakes.FakeRouteReporter))

	fakeEmitter := fake.NewFakeEventEmitter("fake")
	dropsonde.InitializeWithEmitter(fakeEmitter)

	accessLogFile = new(test_util.FakeFile)
	accessLog = access_log.NewFileAndLoggregatorAccessLogger(accessLogFile, "")
	go accessLog.Run()
Exemplo n.º 3
0
	"vulcan/router/registry"
	"vulcan/router/route"
	. "vulcan/router/varz"

	"encoding/json"
	"fmt"
	"net/http"
	"time"
)

var _ = Describe("Varz", func() {
	var Varz Varz
	var Registry *registry.RouteRegistry

	BeforeEach(func() {
		Registry = registry.NewRouteRegistry(config.DefaultConfig(), fakeyagnats.Connect(), new(fakes.FakeRouteReporter))
		Varz = NewVarz(Registry)
	})

	It("contains the following items", func() {
		v := Varz

		members := []string{
			"responses_2xx",
			"responses_3xx",
			"responses_4xx",
			"responses_5xx",
			"responses_xxx",
			"latency",
			"rate",
			"tags",
Exemplo n.º 4
0
func main() {
	c := config.DefaultConfig()
	logCounter := vcap.NewLogCounter()

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

	InitLoggerFromConfig(c, logCounter)
	logger := steno.NewLogger("router.main")

	err := dropsonde.Initialize(c.Logging.MetronAddress, c.Logging.JobName)
	if err != nil {
		logger.Errorf("Dropsonde failed to initialize: %s", err.Error())
		os.Exit(1)
	}

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

	if c.DebugAddr != "" {
		cf_debug_server.Run(c.DebugAddr)
	}

	logger.Info("Setting up etcd connection")
	etcdEndpoint, err := endpoint.NewEtcdEndpoint(c)
	if err != nil {
		os.Exit(1)
	}
	metricsReporter := metrics.NewMetricsReporter()
	registry := rregistry.NewRouteRegistry(c, etcdEndpoint, metricsReporter)

	logger.Info("Setting up routing_api route fetcher")
	setupRouteFetcher(c, registry)

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

	accessLogger, err := access_log.CreateRunningAccessLogger(c)
	if err != nil {
		logger.Fatalf("Error creating access logger: %s\n", err)
	}

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

	proxy := buildProxy(c, registry, accessLogger, compositeReporter, crypto, cryptoPrev)

	router, err := router.NewRouter(c, proxy, etcdEndpoint, registry, varz, logCounter)
	if err != nil {
		logger.Errorf("An error occurred: %s", err.Error())
		os.Exit(1)
	}

	errChan := router.Run()

	logger.Info("gorouter.started")

	waitOnErrOrSignal(c, logger, errChan, router)

	os.Exit(0)
}
Exemplo n.º 5
0
	"vulcan/router/route"

	"encoding/json"
	"time"
)

var _ = Describe("RouteRegistry", func() {
	var r *RouteRegistry
	var messageBus *fakeyagnats.FakeNATSConn
	var reporter *fakes.FakeRouteReporter

	var fooEndpoint, barEndpoint, bar2Endpoint *route.Endpoint
	var configObj *config.Config

	BeforeEach(func() {
		configObj = config.DefaultConfig()
		configObj.PruneStaleDropletsInterval = 50 * time.Millisecond
		configObj.DropletStaleThreshold = 10 * time.Millisecond

		messageBus = fakeyagnats.Connect()
		reporter = new(fakes.FakeRouteReporter)

		r = NewRouteRegistry(configObj, messageBus, reporter)
		fooEndpoint = route.NewEndpoint("12345", "192.168.1.1", 1234,
			"id1", map[string]string{
				"runtime":   "ruby18",
				"framework": "sinatra",
			}, -1, "")

		barEndpoint = route.NewEndpoint("54321", "192.168.1.2", 4321,
			"id2", map[string]string{
package access_log_test

import (
	. "vulcan/router/access_log"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"vulcan/router/config"
)

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

	It("creates null access loger if no access log and loggregator is disabled", func() {
		config := config.DefaultConfig()

		Expect(CreateRunningAccessLogger(config)).To(BeAssignableToTypeOf(&NullAccessLogger{}))
	})

	It("creates an access log when loggegrator is enabled", func() {
		config := config.DefaultConfig()
		config.Logging.LoggregatorEnabled = true
		config.AccessLog = ""

		accessLogger, _ := CreateRunningAccessLogger(config)
		Expect(accessLogger.(*FileAndLoggregatorAccessLogger).FileWriter()).To(BeNil())
		Expect(accessLogger.(*FileAndLoggregatorAccessLogger).DropsondeSourceInstance()).To(Equal("0"))

	})

	It("creates an access log if an access log is specified", func() {
		config := config.DefaultConfig()
Exemplo n.º 7
0
		cfg           *config.Config
		tokenFetcher  *testTokenFetcher.FakeTokenFetcher
		registry      *testRegistry.FakeRegistryInterface
		fetcher       *RouteFetcher
		logger        *gosteno.Logger
		sink          *gosteno.TestingSink
		client        *fake_routing_api.FakeClient
		retryInterval int

		token *token_fetcher.Token

		response []db.Route
	)

	BeforeEach(func() {
		cfg = config.DefaultConfig()

		retryInterval := 0
		tokenFetcher = &testTokenFetcher.FakeTokenFetcher{}
		registry = &testRegistry.FakeRegistryInterface{}
		sink = gosteno.NewTestingSink()

		loggerConfig := &gosteno.Config{
			Sinks: []gosteno.Sink{
				sink,
			},
		}
		gosteno.Init(loggerConfig)
		logger = gosteno.NewLogger("route_fetcher_test")

		token = &token_fetcher.Token{