func (sinkManager *SinkManager) registerNewSyslogSink(appId string, syslogSinkUrl string) { parsedSyslogDrainUrl, err := sinkManager.urlBlacklistManager.CheckUrl(syslogSinkUrl) if err != nil { errorMsg := fmt.Sprintf("SinkManager: Invalid syslog drain URL: %s. Err: %v", syslogSinkUrl, err) sinkManager.SendSyslogErrorToLoggregator(errorMsg, appId) } else { syslogWriter := syslogwriter.NewSyslogWriter(parsedSyslogDrainUrl, appId, sinkManager.skipCertVerify) syslogSink := syslog.NewSyslogSink(appId, syslogSinkUrl, sinkManager.logger, syslogWriter, sinkManager.errorChannel) sinkManager.RegisterSink(syslogSink) } }
defer mutex.Unlock() close(sysLoggerDoneChan) } newSysLoggerDoneChan := func() { mutex.Lock() defer mutex.Unlock() sysLoggerDoneChan = make(chan bool) } BeforeEach(func() { newSysLoggerDoneChan() sysLogger = NewSyslogWriterRecorder() errorChannel = make(chan *logmessage.Message, 10) inputChan = make(chan *logmessage.Message) syslogSink = syslog.NewSyslogSink("appId", "syslog://using-fake", loggertesthelper.Logger(), sysLogger, errorChannel).(*syslog.SyslogSink) }) AfterEach(func() { select { case <-sysLoggerDoneChan: default: closeSysLoggerDoneChan() } }) Context("when remote syslog server is down", func() { BeforeEach(func() { sysLogger.SetDown(true) go func() {
var fakeTimeProvider *faketimeprovider.FakeTimeProvider var groupedSinks *groupedsinks.GroupedSinks var inputChan, errorChan chan *logmessage.Message BeforeEach(func() { fakeTimeProvider = faketimeprovider.New(time.Now()) groupedSinks = groupedsinks.NewGroupedSinks() inputChan = make(chan *logmessage.Message) errorChan = make(chan *logmessage.Message) }) Describe("BroadCast", func() { It("should send message to all registered sinks that match the appId", func(done Done) { appId := "123" appSink := syslog.NewSyslogSink("123", "url", loggertesthelper.Logger(), DummySyslogWriter{}, errorChan) otherInputChan := make(chan *logmessage.Message) groupedSinks.Register(otherInputChan, appSink) appId = "789" appSink = syslog.NewSyslogSink(appId, "url", loggertesthelper.Logger(), DummySyslogWriter{}, errorChan) groupedSinks.Register(inputChan, appSink) msg := NewMessage("test message", appId) go groupedSinks.BroadCast(appId, msg) Expect(<-inputChan).To(Equal(msg)) Expect(otherInputChan).To(HaveLen(0)) close(done) })
Eventually(func() []*logmessage.Message { return sinkManager.RecentLogsFor("appId") }).Should(HaveLen(0)) }) }) Context("with a SyslogSink", func() { var syslogSink sinks.Sink BeforeEach(func() { url, err := url.Parse("syslog://localhost:9998") Expect(err).To(BeNil()) writer := syslogwriter.NewSyslogWriter(url, "appId", true) errorChan := make(chan *logmessage.Message) syslogSink = syslog.NewSyslogSink("appId", "localhost:9999", loggertesthelper.Logger(), writer, errorChan) sinkManager.RegisterSink(syslogSink) }) It("removes the sink", func() { Expect(sinkManager.Metrics.SyslogSinks).To(Equal(1)) sinkManager.UnregisterSink(syslogSink) Expect(sinkManager.Metrics.SyslogSinks).To(Equal(0)) }) }) Context("when called twice", func() { var dumpSink *dump.DumpSink