本文整理汇总了Golang中loggregator/groupedsinks.GroupedSinks.DrainFor方法的典型用法代码示例。如果您正苦于以下问题:Golang GroupedSinks.DrainFor方法的具体用法?Golang GroupedSinks.DrainFor怎么用?Golang GroupedSinks.DrainFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类loggregator/groupedsinks.GroupedSinks
的用法示例。
在下文中一共展示了GroupedSinks.DrainFor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: manageDrains
func (messageRouter *messageRouter) manageDrains(activeSinks *groupedsinks.GroupedSinks, appId string, drainUrls []string, sourceName string) {
if sourceName != "App" {
return
}
//delete all drains for app
if len(drainUrls) == 0 {
for _, sink := range activeSinks.DrainsFor(appId) {
messageRouter.unregisterSink(sink, activeSinks)
}
return
}
//delete all drains that were not sent
for _, sink := range activeSinks.DrainsFor(appId) {
if contains(sink.Identifier(), drainUrls) {
continue
}
messageRouter.unregisterSink(sink, activeSinks)
}
//add all drains that didn't exist
for _, drainUrl := range drainUrls {
if activeSinks.DrainFor(appId, drainUrl) == nil && !messageRouter.urlIsBlackListed(drainUrl) {
dl, err := url.Parse(drainUrl)
if err != nil {
messageRouter.blacklistedURLS = append(messageRouter.blacklistedURLS, drainUrl)
errorMessage := fmt.Sprintf("MessageRouter: Error when trying to parse syslog url %v. Requesting close. Err: %v", drainUrl, err)
messageRouter.sendLoggregatorErrorMessage(errorMessage, appId)
continue
}
ipNotBlacklisted, err := iprange.IpOutsideOfRanges(*dl, messageRouter.blackListIPs)
if err != nil {
messageRouter.blacklistedURLS = append(messageRouter.blacklistedURLS, drainUrl)
errorMessage := fmt.Sprintf("MessageRouter: Error when trying to check syslog url %v against blacklist ip ranges. Requesting close. Err: %v", drainUrl, err)
messageRouter.sendLoggregatorErrorMessage(errorMessage, appId)
continue
}
if ipNotBlacklisted {
sysLogger := sinks.NewSyslogWriter(dl.Scheme, dl.Host, appId, messageRouter.skipCertVerify)
s := sinks.NewSyslogSink(appId, drainUrl, messageRouter.logger, sysLogger, messageRouter.errorChannel)
ok := messageRouter.registerSink(s, activeSinks)
if ok {
go s.Run()
}
} else {
messageRouter.blacklistedURLS = append(messageRouter.blacklistedURLS, drainUrl)
errorMsg := fmt.Sprintf("MessageRouter: Syslog drain url is blacklisted: %s", drainUrl)
messageRouter.sendLoggregatorErrorMessage(errorMsg, appId)
}
}
}
}
示例2: manageDrains
func (messageRouter *messageRouter) manageDrains(activeSinks *groupedsinks.GroupedSinks, appId string, drainUrls []string, sourceType logmessage.LogMessage_SourceType) {
if sourceType != logmessage.LogMessage_WARDEN_CONTAINER {
return
}
//delete all drains for app
if len(drainUrls) == 0 {
for _, sink := range activeSinks.DrainsFor(appId) {
messageRouter.unregisterSink(sink, activeSinks)
}
return
}
//delete all drains that were not sent
for _, sink := range activeSinks.DrainsFor(appId) {
if contains(sink.Identifier(), drainUrls) {
continue
}
messageRouter.unregisterSink(sink, activeSinks)
}
//add all drains that didn't exist
for _, drainUrl := range drainUrls {
if activeSinks.DrainFor(appId, drainUrl) == nil {
dl, err := url.Parse(drainUrl)
if err != nil {
messageRouter.logger.Warnf("MessageRouter: Error when trying to parse syslog url %v. Requesting close. Err: %v", drainUrl, err)
continue
}
sysLogger := sinks.NewSyslogWriter("tcp", dl.Host, appId)
s := sinks.NewSyslogSink(appId, drainUrl, messageRouter.logger, sysLogger)
ok := messageRouter.registerSink(s, activeSinks)
if ok {
go s.Run()
}
}
}
}
示例3:
Expect(sinkDrain).To(HaveLen(1))
Expect(sinkDrain[0]).To(Equal(sink2))
})
})
Describe("DrainFor", func() {
It("should return only sinks that match the appid and drain URL", func() {
target := "789"
sink1 := syslog.NewSyslogSink(target, "other sink", loggertesthelper.Logger(), DummySyslogWriter{}, errorChan)
sink2 := syslog.NewSyslogSink(target, "sink we are searching for", loggertesthelper.Logger(), DummySyslogWriter{}, errorChan)
groupedSinks.Register(inputChan, sink1)
groupedSinks.Register(inputChan, sink2)
sinkDrain := groupedSinks.DrainFor(target, "sink we are searching for")
Expect(sinkDrain).To(Equal(sink2))
})
It("should return nil if no drains are registered", func() {
target := "789"
sink := syslog.NewSyslogSink(target, "url2", loggertesthelper.Logger(), DummySyslogWriter{}, errorChan)
groupedSinks.Register(inputChan, sink)
Expect(groupedSinks.DrainFor(target, "url1")).To(BeNil())
})
It("should return nil if no drains exist", func() {
Expect(groupedSinks.DrainFor("empty", "empty")).To(BeNil())
})