当前位置: 首页>>代码示例>>Golang>>正文


Golang GroupedSinks.DrainFor方法代码示例

本文整理汇总了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)
			}
		}
	}
}
开发者ID:pxie,项目名称:loggregator,代码行数:52,代码来源:message_router.go

示例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()
			}
		}
	}
}
开发者ID:uabassguy,项目名称:loggregator,代码行数:37,代码来源:message_router.go

示例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())
		})
开发者ID:nkuacac,项目名称:loggregator,代码行数:31,代码来源:grouped_sinks_test.go


注:本文中的loggregator/groupedsinks.GroupedSinks.DrainFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。