本文整理汇总了Golang中github.com/cloudfoundry/loggregatorlib/agentlistener.NewAgentListener函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAgentListener函数的具体用法?Golang NewAgentListener怎么用?Golang NewAgentListener使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAgentListener函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestThatItWorksWithTwoLoggregators
func TestThatItWorksWithTwoLoggregators(t *testing.T) {
listener1, dataChan1 := agentlistener.NewAgentListener("localhost:9998", logger)
go listener1.Start()
listener2, dataChan2 := agentlistener.NewAgentListener("localhost:9997", logger)
go listener2.Start()
loggregatorServers := []string{"localhost:9998", "localhost:9997"}
hasher := hasher.NewHasher(loggregatorServers)
rt, err := NewRouter("localhost:3457", hasher, newCfConfig(), logger)
assert.NoError(t, err)
go rt.Start(logger)
time.Sleep(50 * time.Millisecond)
logEmitter, _ := emitter.NewEmitter("localhost:3457", "ROUTER", "42", "secret", logger)
logEmitter.Emit("2", "My message")
receivedData := <-dataChan1
receivedEnvelope := &logmessage.LogEnvelope{}
proto.Unmarshal(receivedData, receivedEnvelope)
assert.Equal(t, receivedEnvelope.GetLogMessage().GetAppId(), "2")
assert.Equal(t, string(receivedEnvelope.GetLogMessage().GetMessage()), "My message")
logEmitter.Emit("1", "Another message")
receivedData = <-dataChan2
receivedEnvelope = &logmessage.LogEnvelope{}
proto.Unmarshal(receivedData, receivedEnvelope)
assert.Equal(t, receivedEnvelope.GetLogMessage().GetAppId(), "1")
assert.Equal(t, string(receivedEnvelope.GetLogMessage().GetMessage()), "Another message")
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:34,代码来源:input_router_test.go
示例2: NewRouter
func NewRouter(host string, h *hasher, config cfcomponent.Config, logger *gosteno.Logger) (r *router, err error) {
var instrumentables []instrumentation.Instrumentable
loggregatorClients := make(map[string]loggregatorclient.LoggregatorClient, len(h.loggregatorServers()))
for _, server := range h.loggregatorServers() {
client := loggregatorclient.NewLoggregatorClient(server, logger, loggregatorclient.DefaultBufferSize)
loggregatorClients[server] = client
instrumentables = append(instrumentables, client)
}
al := agentlistener.NewAgentListener(host, logger)
instrumentables = append(instrumentables, al)
cfc, err := cfcomponent.NewComponent(
0,
"LoggregatorRouter",
0,
&LoggregatorRouterMonitor{},
config.VarzPort,
[]string{config.VarzUser, config.VarzPass},
instrumentables,
)
if err != nil {
return
}
r = &router{Component: cfc, h: h, lcs: loggregatorClients, agentListener: al, host: host}
return
}
开发者ID:narayana1208,项目名称:loggregator,代码行数:31,代码来源:router.go
示例3: TestThatItIgnoresBadMessages
func TestThatItIgnoresBadMessages(t *testing.T) {
listener, dataChannel := agentlistener.NewAgentListener("localhost:9996", logger)
go listener.Start()
loggregatorServers := []string{"localhost:9996"}
hasher := hasher.NewHasher(loggregatorServers)
r, err := NewRouter("localhost:3455", hasher, newCfConfig(), logger)
assert.NoError(t, err)
go r.Start(logger)
time.Sleep(50 * time.Millisecond)
lc := loggregatorclient.NewLoggregatorClient("localhost:3455", logger, loggregatorclient.DefaultBufferSize)
lc.Send([]byte("This is poorly formatted"))
logEmitter, _ := emitter.NewEmitter("localhost:3455", "ROUTER", "42", "secret", logger)
logEmitter.Emit("my_awesome_app", "Hello World")
received := <-dataChannel
receivedEnvelope := &logmessage.LogEnvelope{}
proto.Unmarshal(received, receivedEnvelope)
assert.Equal(t, receivedEnvelope.GetLogMessage().GetAppId(), "my_awesome_app")
assert.Equal(t, string(receivedEnvelope.GetLogMessage().GetMessage()), "Hello World")
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:25,代码来源:input_router_test.go
示例4: NewRouter
func NewRouter(host string, hasher *hasher.Hasher, config cfcomponent.Config, logger *gosteno.Logger) (r *Router, err error) {
var instrumentables []instrumentation.Instrumentable
servers := hasher.LoggregatorServers()
loggregatorClients := make(map[string]loggregatorclient.LoggregatorClient, len(servers))
for _, server := range servers {
client := loggregatorclient.NewLoggregatorClient(server, logger, loggregatorclient.DefaultBufferSize)
loggregatorClients[server] = client
instrumentables = append(instrumentables, client)
}
agentListener, dataChan := agentlistener.NewAgentListener(host, logger)
instrumentables = append(instrumentables, agentListener)
cfc, err := cfcomponent.NewComponent(
logger,
"LoggregatorTrafficcontroller",
0,
&TrafficControllerMonitor{},
config.VarzPort,
[]string{config.VarzUser, config.VarzPass},
instrumentables,
)
if err != nil {
return
}
r = &Router{Component: cfc, hasher: hasher, loggregatorClients: loggregatorClients, agentListener: agentListener, dataChan: dataChan, host: host}
return
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:32,代码来源:input_router.go
示例5: init
func init() {
logger := gosteno.NewLogger("TestLogger")
listener := agentlistener.NewAgentListener("localhost:3456", logger)
dataChannel := listener.Start()
messageRouter := sinkserver.NewMessageRouter(10, false, nil, logger)
go messageRouter.Start()
httpServer := sinkserver.NewHttpServer(messageRouter, 30*time.Second, testhelpers.UnmarshallerMaker("secret"), 100, logger)
go httpServer.Start(dataChannel, "localhost:8081")
time.Sleep(50 * time.Millisecond)
}
开发者ID:pxie,项目名称:loggregator,代码行数:13,代码来源:loggregator_test.go
示例6: init
func init() {
logger := gosteno.NewLogger("TestLogger")
listener := agentlistener.NewAgentListener("localhost:3456", logger)
incomingLogChan := listener.Start()
sinkManager := sinkserver.NewSinkManager(1024, false, nil, logger)
go sinkManager.Start()
messageRouter := sinkserver.NewMessageRouter(incomingLogChan, testhelpers.UnmarshallerMaker("secret"), sinkManager, 2048, logger)
go messageRouter.Start()
websocketServer := sinkserver.NewWebsocketServer("localhost:8083", sinkManager, 30*time.Second, 100, logger)
go websocketServer.Start()
time.Sleep(50 * time.Millisecond)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:17,代码来源:loggregator_test.go
示例7: main
func main() {
logger := loggertesthelper.Logger()
flag.Parse()
listener := agentlistener.NewAgentListener(*host, logger)
dataChannel := listener.Start()
for data := range dataChannel {
if logMessage, err := extractLogMessage(data); err == nil {
fmt.Printf("MESSAGE: %+v\n", logMessage)
} else if logEnvelope, err := extractLogEnvelope(data); err == nil {
validEnvelope := logEnvelope.VerifySignature(*secret)
fmt.Printf("ENVELOPE (valid: %t): %+v\n", validEnvelope, logEnvelope)
} else {
fmt.Println("ERROR parsing protobuffer")
}
}
}
开发者ID:uabassguy,项目名称:loggregator,代码行数:19,代码来源:main.go
示例8: New
func New(host string, config *config.Config, logger *gosteno.Logger, storeAdapter storeadapter.StoreAdapter, messageDrainBufferSize uint, dropsondeOrigin string, dialTimeout time.Duration) *Doppler {
cfcomponent.Logger = logger
keepAliveInterval := 30 * time.Second
appStoreCache := cache.NewAppServiceCache()
appStoreWatcher, newAppServiceChan, deletedAppServiceChan := store.NewAppServiceStoreWatcher(storeAdapter, appStoreCache)
dropsondeListener, dropsondeBytesChan := agentlistener.NewAgentListener(fmt.Sprintf("%s:%d", host, config.DropsondeIncomingMessagesPort), logger, "dropsondeListener")
signatureVerifier := signature.NewVerifier(logger, config.SharedSecret)
unmarshallerCollection := dropsonde_unmarshaller.NewDropsondeUnmarshallerCollection(logger, config.UnmarshallerCount)
blacklist := blacklist.New(config.BlackListIps)
metricTTL := time.Duration(config.ContainerMetricTTLSeconds) * time.Second
sinkTimeout := time.Duration(config.SinkInactivityTimeoutSeconds) * time.Second
sinkIOTimeout := time.Duration(config.SinkIOTimeoutSeconds) * time.Second
sinkManager := sinkmanager.New(config.MaxRetainedLogMessages, config.SkipCertVerify, blacklist, logger, messageDrainBufferSize, dropsondeOrigin, sinkTimeout, sinkIOTimeout, metricTTL, dialTimeout)
return &Doppler{
Logger: logger,
dropsondeListener: dropsondeListener,
sinkManager: sinkManager,
messageRouter: sinkserver.NewMessageRouter(sinkManager, logger),
websocketServer: websocketserver.New(fmt.Sprintf("%s:%d", host, config.OutgoingPort), sinkManager, keepAliveInterval, config.MessageDrainBufferSize, dropsondeOrigin, logger),
newAppServiceChan: newAppServiceChan,
deletedAppServiceChan: deletedAppServiceChan,
appStoreWatcher: appStoreWatcher,
storeAdapter: storeAdapter,
dropsondeBytesChan: dropsondeBytesChan,
dropsondeUnmarshallerCollection: unmarshallerCollection,
envelopeChan: make(chan *events.Envelope),
wrappedEnvelopeChan: make(chan *events.Envelope),
signatureVerifier: signatureVerifier,
dropsondeVerifiedBytesChan: make(chan []byte),
uptimeMonitor: monitor.NewUptimeMonitor(time.Duration(config.MonitorIntervalSeconds) * time.Second),
}
}
开发者ID:rakutentech,项目名称:loggregator,代码行数:38,代码来源:doppler.go
示例9: TestEndtoEndMessage
func TestEndtoEndMessage(t *testing.T) {
logger := gosteno.NewLogger("TestLogger")
listener := agentlistener.NewAgentListener("localhost:3456", logger)
dataChannel := listener.Start()
sinkServer := sinkserver.NewSinkServer(messagestore.NewMessageStore(10), logger, testhelpers.SuccessfulAuthorizer, 30*time.Second)
go sinkServer.Start(dataChannel, "localhost:8081")
time.Sleep(1 * time.Millisecond)
receivedChan := make(chan []byte)
ws, _, _ := testhelpers.AddWSSink(t, receivedChan, "8081", "/tail/?app=myApp", testhelpers.VALID_SPACE_AUTHENTICATION_TOKEN)
defer ws.Close()
time.Sleep(50 * time.Millisecond)
connection, err := net.Dial("udp", "localhost:3456")
expectedMessageString := "Some Data"
expectedMessage := testhelpers.MarshalledLogMessage(t, expectedMessageString, "myApp")
_, err = connection.Write(expectedMessage)
assert.NoError(t, err)
testhelpers.AssertProtoBufferMessageEquals(t, expectedMessageString, <-receivedChan)
}
开发者ID:narayana1208,项目名称:loggregator,代码行数:23,代码来源:loggregator_test.go
示例10: TestThatItWorksWithOneLoggregator
func TestThatItWorksWithOneLoggregator(t *testing.T) {
listener, dataChannel := agentlistener.NewAgentListener("localhost:9999", logger)
go listener.Start()
loggregatorServers := []string{"localhost:9999"}
hasher := hasher.NewHasher(loggregatorServers)
r, err := NewRouter("localhost:3456", hasher, newCfConfig(), logger)
assert.NoError(t, err)
go r.Start(logger)
time.Sleep(50 * time.Millisecond)
logEmitter, _ := emitter.NewEmitter("localhost:3456", "ROUTER", "42", "secret", logger)
logEmitter.Emit("my_awesome_app", "Hello World")
received := <-dataChannel
receivedEnvelope := &logmessage.LogEnvelope{}
proto.Unmarshal(received, receivedEnvelope)
assert.Equal(t, receivedEnvelope.GetLogMessage().GetAppId(), "my_awesome_app")
assert.Equal(t, string(receivedEnvelope.GetLogMessage().GetMessage()), "Hello World")
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:23,代码来源:input_router_test.go
示例11:
"github.com/gogo/protobuf/proto"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("AgentListener", func() {
var listener agentlistener.AgentListener
var dataChannel <-chan []byte
var listenerStopped chan struct{}
BeforeEach(func() {
listenerStopped = make(chan struct{})
loggertesthelper.TestLoggerSink.Clear()
listener, dataChannel = agentlistener.NewAgentListener("127.0.0.1:3456", loggertesthelper.Logger(), "agentListener")
go func() {
listener.Start()
close(listenerStopped)
}()
Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring("Listening on port 127.0.0.1:3456"))
})
AfterEach(func() {
listener.Stop()
<-listenerStopped
})
Context("with a listner running", func() {
It("listens to the socket and forwards log lines", func(done Done) {
开发者ID:Amit-PivotalLabs,项目名称:loggregator,代码行数:31,代码来源:agent_listener_test.go
示例12: main
func main() {
seed := time.Now().UnixNano()
rand.Seed(seed)
flag.Parse()
if *version {
fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n",
versionNumber, gitSha, gitSha)
return
}
runtime.GOMAXPROCS(runtime.NumCPU())
config, logger := parseConfig(logLevel, configFile, logFilePath)
err := config.validate(logger)
if err != nil {
panic(err)
}
agentListener := agentlistener.NewAgentListener(fmt.Sprintf("0.0.0.0:%d", config.IncomingPort), logger)
incomingLogChan := agentListener.Start()
sinkManager := sinkserver.NewSinkManager(config.MaxRetainedLogMessages, config.SkipCertVerify, config.BlackListIps, logger)
go sinkManager.Start()
unmarshaller := func(data []byte) (*logmessage.Message, error) {
return logmessage.ParseEnvelope(data, config.SharedSecret)
}
messageChannelLength := 2048
messageRouter := sinkserver.NewMessageRouter(incomingLogChan, unmarshaller, sinkManager, messageChannelLength, logger)
apiEndpoint := fmt.Sprintf("0.0.0.0:%d", config.OutgoingPort)
keepAliveInterval := 30 * time.Second
websocketServer := sinkserver.NewWebsocketServer(apiEndpoint, sinkManager, keepAliveInterval, config.WSMessageBufferSize, logger)
cfc, err := cfcomponent.NewComponent(
logger,
"LoggregatorServer",
config.Index,
&LoggregatorServerHealthMonitor{},
config.VarzPort,
[]string{config.VarzUser, config.VarzPass},
[]instrumentation.Instrumentable{agentListener, sinkManager, messageRouter},
)
if err != nil {
panic(err)
}
cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger)
err = cr.RegisterWithCollector(cfc)
if err != nil {
logger.Warnf("Unable to register with collector. Err: %v.", err)
}
go func() {
err := cfc.StartMonitoringEndpoints()
if err != nil {
panic(err)
}
}()
go messageRouter.Start()
go websocketServer.Start()
killChan := make(chan os.Signal)
signal.Notify(killChan, os.Kill)
for {
select {
case <-cfcomponent.RegisterGoRoutineDumpSignalChannel():
cfcomponent.DumpGoRoutine()
case <-killChan:
break
}
}
}
开发者ID:james-masson,项目名称:loggregator,代码行数:79,代码来源:main.go
示例13: main
func main() {
seed := time.Now().UnixNano()
rand.Seed(seed)
flag.Parse()
if *version {
fmt.Printf("version: %s\ngitSha: %s\nsourceUrl: https://github.com/cloudfoundry/loggregator/tree/%s\n\n",
versionNumber, gitSha, gitSha)
return
}
runtime.GOMAXPROCS(runtime.NumCPU())
config := &Config{IncomingPort: 3456, OutgoingPort: 8080}
err := cfcomponent.ReadConfigInto(config, *configFile)
if err != nil {
panic(err)
}
logger := cfcomponent.NewLogger(*logLevel, *logFilePath, "loggregator", config.Config)
logger.Info("Startup: Setting up the loggregator server")
err = config.validate(logger)
if err != nil {
panic(err)
}
listener := agentlistener.NewAgentListener(fmt.Sprintf("0.0.0.0:%d", config.IncomingPort), logger)
incomingData := listener.Start()
messageRouter := sinkserver.NewMessageRouter(config.MaxRetainedLogMessages, logger)
unmarshaller := func(data []byte) (*logmessage.Message, error) {
return logmessage.ParseEnvelope(data, config.SharedSecret)
}
httpServer := sinkserver.NewHttpServer(messageRouter, 30*time.Second, unmarshaller, logger)
cfc, err := cfcomponent.NewComponent(
logger,
"LoggregatorServer",
config.Index,
&LoggregatorServerHealthMonitor{},
config.VarzPort,
[]string{config.VarzUser, config.VarzPass},
[]instrumentation.Instrumentable{listener, messageRouter},
)
if err != nil {
panic(err)
}
cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger)
err = cr.RegisterWithCollector(cfc)
if err != nil {
logger.Warnf("Unable to register with collector. Err: %v.", err)
}
go func() {
err := cfc.StartMonitoringEndpoints()
if err != nil {
panic(err)
}
}()
go messageRouter.Start()
go httpServer.Start(incomingData, fmt.Sprintf("0.0.0.0:%d", config.OutgoingPort))
killChan := make(chan os.Signal)
signal.Notify(killChan, os.Kill)
for {
select {
case <-cfcomponent.RegisterGoRoutineDumpSignalChannel():
cfcomponent.DumpGoRoutine()
case <-killChan:
break
}
}
}
开发者ID:uabassguy,项目名称:loggregator,代码行数:81,代码来源:main.go
示例14: main
func main() {
flag.Parse()
if *version {
fmt.Printf("\n\nversion: %s\ngitSha: %s\n\n", versionNumber, gitSha)
return
}
runtime.GOMAXPROCS(runtime.NumCPU())
logger := cfcomponent.NewLogger(*logLevel, *logFilePath, "loggregator")
config := &Config{SourcePort: 3456, WebPort: 8080, UaaVerificationKeyFile: *uaaVerificationKeyFile}
err := cfcomponent.ReadConfigInto(config, *configFile)
if err != nil {
panic(err)
}
err = config.validate(logger)
if err != nil {
panic(err)
}
listener := agentlistener.NewAgentListener(fmt.Sprintf("0.0.0.0:%d", config.SourcePort), logger)
incomingData := listener.Start()
authorizer := authorization.NewLogAccessAuthorizer(config.decoder, config.ApiHost)
sinkServer := sinkserver.NewSinkServer(
messagestore.NewMessageStore(config.MaxRetainedLogMessages),
logger,
authorizer,
30*time.Second,
)
cfc, err := cfcomponent.NewComponent(
config.WebPort,
"LoggregatorServer",
config.Index,
&LoggregatorServerHealthMonitor{},
config.VarzPort,
[]string{config.VarzUser, config.VarzPass},
[]instrumentation.Instrumentable{listener, sinkServer},
)
if err != nil {
panic(err)
}
rr := routerregistrar.NewRouterRegistrar(config.MbusClient, logger)
uri := servernamer.ServerName(
net.JoinHostPort(cfc.IpAddress, strconv.Itoa(int(config.SourcePort))),
"loggregator."+config.SystemDomain)
err = rr.RegisterWithRouter(cfc.IpAddress, config.WebPort, []string{uri})
if err != nil {
logger.Fatalf("Did not get response from router when greeting. Using default keep-alive for now. Err: %v.", err)
}
cr := collectorregistrar.NewCollectorRegistrar(config.MbusClient, logger)
err = cr.RegisterWithCollector(cfc)
if err != nil {
logger.Warnf("Unable to register with collector. Err: %v.", err)
}
go func() {
err := cfc.StartMonitoringEndpoints()
if err != nil {
panic(err)
}
}()
go sinkServer.Start(incomingData, fmt.Sprintf("0.0.0.0:%d", config.WebPort))
killChan := make(chan os.Signal)
signal.Notify(killChan, os.Kill)
for {
select {
case <-cfcomponent.RegisterGoRoutineDumpSignalChannel():
cfcomponent.DumpGoRoutine()
case <-killChan:
rr.UnregisterFromRouter(cfc.IpAddress, cfc.WebPort, []string{uri})
break
}
}
}
开发者ID:narayana1208,项目名称:loggregator,代码行数:85,代码来源:main.go
示例15:
)
var _ = Describe("AgentListener", func() {
var listener agentlistener.AgentListener
var dataChannel <-chan []byte
var listenerStopped chan struct{}
var agentAddress string
BeforeEach(func() {
listenerStopped = make(chan struct{})
loggertesthelper.TestLoggerSink.Clear()
port := 3456 + config.GinkgoConfig.ParallelNode
agentAddress = net.JoinHostPort("127.0.0.1", strconv.Itoa(port))
listener, dataChannel = agentlistener.NewAgentListener(agentAddress, loggertesthelper.Logger(), "agentListener")
go func() {
listener.Start()
close(listenerStopped)
}()
Eventually(loggertesthelper.TestLoggerSink.LogContents).Should(ContainSubstring("Listening on port " + agentAddress))
})
AfterEach(func() {
listener.Stop()
<-listenerStopped
})
Context("with a listner running", func() {
It("listens to the socket and forwards log lines", func(done Done) {
开发者ID:pkdevbox,项目名称:loggregatorlib,代码行数:31,代码来源:agent_listener_test.go
注:本文中的github.com/cloudfoundry/loggregatorlib/agentlistener.NewAgentListener函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论