예제 #1
0
func (sinkManager *SinkManager) RegisterSink(sink sinks.Sink) bool {
	ok := sinkManager.sinks.Register(sink)
	if !ok {
		return false
	}

	sinkManager.Metrics.Inc(sink)

	sinkManager.logger.Infof("SinkManager: Sink with channel %v requested. Opened it.", sink.Channel())
	return true
}
예제 #2
0
func (messageRouter *messageRouter) dumpToSink(sink sinks.Sink, activeSinks *groupedsinks.GroupedSinks) {
	dumpChan := make(chan *logmessage.Message, 20)
	if sink := activeSinks.DumpFor(sink.AppId()); sink != nil {
		sink.Dump(dumpChan)
	} else {
		close(dumpChan)
	}
	for message := range dumpChan {
		sink.Channel() <- message
	}
}
예제 #3
0
func (sinkManager *SinkManager) UnregisterSink(sink sinks.Sink) {
	sinkManager.sinks.Delete(sink)
	close(sink.Channel())

	sinkManager.Metrics.Dec(sink)

	if syslogSink, ok := sink.(*sinks.SyslogSink); ok {
		syslogSink.Disconnect()
	}

	sinkManager.logger.Infof("SinkManager: Sink with channel %v and identifier %s requested closing. Closed it.", sink.Channel(), sink.Identifier())
}
예제 #4
0
func (messageRouter *messageRouter) unregisterSink(s sinks.Sink, activeSinks *groupedsinks.GroupedSinks) {
	messageRouter.Lock()
	defer messageRouter.Unlock()

	activeSinks.Delete(s)
	close(s.Channel())
	switch s.(type) {
	case *sinks.DumpSink:
		messageRouter.activeDumpSinksCounter--
	case *sinks.SyslogSink:
		messageRouter.activeSyslogSinksCounter--
	case *sinks.WebsocketSink:
		messageRouter.activeWebsocketSinksCounter--
	}
	messageRouter.logger.Infof("MessageRouter: Sink with channel %v requested closing. Closed it.", s.Channel())
}
예제 #5
0
	})

	Context("when remote syslog server is down", func() {
		BeforeEach(func() {
			sysLogger.SetDown(true)
			go func() {
				syslogSink.Run()
				closeSysLoggerDoneChan()
			}()
		})

		It("should still accept messages without blocking", func(done Done) {
			logMessage := NewMessage("test message", "appId")

			for i := 0; i < 100; i++ {
				syslogSink.Channel() <- logMessage
			}
			close(done)
		})

		Context("when remote syslog server comes up", func() {
			BeforeEach(func() {
				logMessage := NewMessage("test message", "appId")

				for i := 0; i < 5; i++ {
					syslogSink.Channel() <- logMessage
				}
				close(syslogSink.Channel())
				sysLogger.SetDown(false)
			})
예제 #6
0
func (messageRouter *messageRouter) registerSink(s sinks.Sink, activeSinks *groupedsinks.GroupedSinks) bool {
	messageRouter.Lock()
	defer messageRouter.Unlock()

	ok := activeSinks.Register(s)
	switch s.(type) {
	case *sinks.DumpSink:
		messageRouter.activeDumpSinksCounter++
	case *sinks.SyslogSink:
		messageRouter.activeSyslogSinksCounter++
	case *sinks.WebsocketSink:
		messageRouter.activeWebsocketSinksCounter++
		go messageRouter.dumpToSink(s, activeSinks)
	}
	messageRouter.logger.Infof("MessageRouter: Sink with channel %v requested. Opened it.", s.Channel())
	return ok
}