本文整理汇总了Golang中loggregator/groupedsinks.GroupedSinks类的典型用法代码示例。如果您正苦于以下问题:Golang GroupedSinks类的具体用法?Golang GroupedSinks怎么用?Golang GroupedSinks使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GroupedSinks类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: dumpToSink
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
}
}
示例2: manageDumps
func (messageRouter *messageRouter) manageDumps(activeSinks *groupedsinks.GroupedSinks, appId string) {
if activeSinks.DumpFor(appId) == nil {
s := sinks.NewDumpSink(appId, messageRouter.dumpBufferSize, messageRouter.logger)
ok := messageRouter.registerSink(s, activeSinks)
if ok {
go s.Run()
}
}
}
示例3: unregisterSink
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())
}
示例4: registerSink
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
}
示例5: 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)
}
}
}
}
示例6: 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()
}
}
}
}
示例7: AppId
func (c *TestSink) AppId() string { return c.appId }
func (c *TestSink) Run(msgChan <-chan *logmessage.Message) {
for _ = range msgChan {
}
}
func (c *TestSink) Identifier() string { return c.identifier }
func (c *TestSink) ShouldReceiveErrors() bool { return true }
func (c *TestSink) Emit() instrumentation.Context {
return instrumentation.Context{}
}
var _ = Describe("GroupedSink", 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)