Ejemplo n.º 1
0
func init() {
	logger := gosteno.NewLogger("TestLogger")

	listener := agentlistener.NewAgentListener("localhost:3456", logger)
	incomingLogChan := listener.Start()

	sinkManager := sinkserver.NewSinkManager(1024, false, nil, logger)
	go sinkManager.Start()

	messageRouter := sinkserver.NewMessageRouter(incomingLogChan, testhelpers.UnmarshallerMaker("secret"), sinkManager, 2048, logger)
	go messageRouter.Start()

	websocketServer := sinkserver.NewWebsocketServer("localhost:8083", sinkManager, 30*time.Second, 100, logger)
	go websocketServer.Start()

	time.Sleep(50 * time.Millisecond)
}
Ejemplo n.º 2
0
func main() {
	seed := time.Now().UnixNano()
	rand.Seed(seed)

	flag.Parse()

	if *version {
		fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n",
			versionNumber, gitSha, gitSha)
		return
	}

	runtime.GOMAXPROCS(runtime.NumCPU())

	config, logger := parseConfig(logLevel, configFile, logFilePath)
	err := config.validate(logger)
	if err != nil {
		panic(err)
	}

	agentListener := agentlistener.NewAgentListener(fmt.Sprintf("0.0.0.0:%d", config.IncomingPort), logger)
	incomingLogChan := agentListener.Start()

	sinkManager := sinkserver.NewSinkManager(config.MaxRetainedLogMessages, config.SkipCertVerify, config.BlackListIps, logger)
	go sinkManager.Start()

	unmarshaller := func(data []byte) (*logmessage.Message, error) {
		return logmessage.ParseEnvelope(data, config.SharedSecret)
	}

	messageChannelLength := 2048
	messageRouter := sinkserver.NewMessageRouter(incomingLogChan, unmarshaller, sinkManager, messageChannelLength, logger)

	apiEndpoint := fmt.Sprintf("0.0.0.0:%d", config.OutgoingPort)
	keepAliveInterval := 30 * time.Second
	websocketServer := sinkserver.NewWebsocketServer(apiEndpoint, sinkManager, keepAliveInterval, config.WSMessageBufferSize, logger)

	cfc, err := cfcomponent.NewComponent(
		logger,
		"LoggregatorServer",
		config.Index,
		&LoggregatorServerHealthMonitor{},
		config.VarzPort,
		[]string{config.VarzUser, config.VarzPass},
		[]instrumentation.Instrumentable{agentListener, sinkManager, messageRouter},
	)

	if err != nil {
		panic(err)
	}

	cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger)
	err = cr.RegisterWithCollector(cfc)
	if err != nil {
		logger.Warnf("Unable to register with collector. Err: %v.", err)
	}

	go func() {
		err := cfc.StartMonitoringEndpoints()
		if err != nil {
			panic(err)
		}
	}()

	go messageRouter.Start()
	go websocketServer.Start()

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

	for {
		select {
		case <-cfcomponent.RegisterGoRoutineDumpSignalChannel():
			cfcomponent.DumpGoRoutine()
		case <-killChan:
			break
		}
	}
}
Ejemplo n.º 3
0
func (c *ChannelSink) AppId() string                     { return c.appId }
func (c *ChannelSink) Run()                              {}
func (c *ChannelSink) Channel() chan *logmessage.Message { return c.channel }
func (c *ChannelSink) Identifier() string                { return c.identifier }
func (c *ChannelSink) Logger() *gosteno.Logger           { return c.logger }
func (c *ChannelSink) ShouldReceiveErrors() bool         { return true }
func (c *ChannelSink) Emit() instrumentation.Context {
	return instrumentation.Context{}
}

var _ = Describe("SinkManager", func() {
	var sinkManager *sinkserver.SinkManager

	BeforeEach(func() {
		sinkManager = sinkserver.NewSinkManager(1, true, []iprange.IPRange{}, loggertesthelper.Logger())
		go sinkManager.Start()
	})

	Describe("SendTo", func() {
		It("should send to all known sinks", func(done Done) {

			client1ReceivedChan := make(chan *logmessage.Message)
			client2ReceivedChan := make(chan *logmessage.Message)
			sink1 := &ChannelSink{appId: "myApp",
				identifier: "myAppChan1",
				logger:     loggertesthelper.Logger(),
				channel:    client1ReceivedChan,
			}
			sink2 := &ChannelSink{appId: "myApp",
				identifier: "myAppChan2",