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


Golang Envelope.GetLogMessage方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry/sonde-go/events.Envelope.GetLogMessage方法的典型用法代码示例。如果您正苦于以下问题:Golang Envelope.GetLogMessage方法的具体用法?Golang Envelope.GetLogMessage怎么用?Golang Envelope.GetLogMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry/sonde-go/events.Envelope的用法示例。


在下文中一共展示了Envelope.GetLogMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: listenForLogs

func listenForLogs() {
	for {
		buffer := make([]byte, 1024)
		n, _, err := udpConn.ReadFrom(buffer)
		if err != nil {
			return
		}

		if n == 0 {
			panic("Received empty packet")
		}
		envelope := new(events.Envelope)
		err = proto.Unmarshal(buffer[0:n], envelope)
		if err != nil {
			panic(err)
		}

		if envelope.GetEventType() == events.Envelope_LogMessage {
			logLock.Lock()
			logMessages = append(logMessages, envelope.GetLogMessage())
			logLock.Unlock()

		}
	}
}
开发者ID:drnic,项目名称:noop-cf-boshrelease,代码行数:25,代码来源:log_integration_test.go

示例2: GetAppId

func GetAppId(envelope *events.Envelope) string {
	if envelope.GetEventType() == events.Envelope_LogMessage {
		return envelope.GetLogMessage().GetAppId()
	}

	if envelope.GetEventType() == events.Envelope_ContainerMetric {
		return envelope.GetContainerMetric().GetApplicationId()
	}

	var event hasAppId
	switch envelope.GetEventType() {
	case events.Envelope_HttpStart:
		event = envelope.GetHttpStart()
	case events.Envelope_HttpStop:
		event = envelope.GetHttpStop()
	case events.Envelope_HttpStartStop:
		event = envelope.GetHttpStartStop()
	default:
		return SystemAppId
	}

	uuid := event.GetApplicationId()
	if uuid != nil {
		return formatUUID(uuid)
	}
	return SystemAppId
}
开发者ID:Reejoshi,项目名称:cli,代码行数:27,代码来源:envelope_extensions.go

示例3: TranslateDropsondeToLegacyLogMessage

func TranslateDropsondeToLegacyLogMessage(message []byte) ([]byte, error) {
	var receivedEnvelope events.Envelope
	err := proto.Unmarshal(message, &receivedEnvelope)
	if err != nil {
		return nil, fmt.Errorf("TranslateDropsondeToLegacyLogMessage: Unable to unmarshal bytes as Envelope: %v", err)
	}

	if receivedEnvelope.GetEventType() != events.Envelope_LogMessage {
		return nil, fmt.Errorf("TranslateDropsondeToLegacyLogMessage: Envelope contained %s instead of LogMessage", receivedEnvelope.GetEventType().String())
	}

	logMessage := receivedEnvelope.GetLogMessage()
	if logMessage == nil {
		return nil, fmt.Errorf("TranslateDropsondeToLegacyLogMessage: Envelope's LogMessage was nil: %v", receivedEnvelope)
	}

	messageBytes, err := proto.Marshal(
		&logmessage.LogMessage{
			Message:     logMessage.GetMessage(),
			MessageType: (*logmessage.LogMessage_MessageType)(logMessage.MessageType),
			Timestamp:   proto.Int64(logMessage.GetTimestamp()),
			AppId:       proto.String(logMessage.GetAppId()),
			SourceId:    proto.String(logMessage.GetSourceInstance()),
			SourceName:  proto.String(logMessage.GetSourceType()),
		},
	)
	if err != nil {
		return nil, fmt.Errorf("TranslateDropsondeToLegacyLogMessage: Failed marshalling converted dropsonde message: %v", err)
	}

	return messageBytes, nil
}
开发者ID:lyuyun,项目名称:loggregator,代码行数:32,代码来源:legacy_log_translator.go

示例4: processEnvelope

func (l *logCounter) processEnvelope(env *events.Envelope) {
	if env.GetEventType() != events.Envelope_LogMessage {
		return
	}
	logMsg := env.GetLogMessage()

	msg := string(logMsg.GetMessage())
	if strings.HasPrefix(msg, "mismatched prefix") {
		return
	}
	if !strings.HasPrefix(msg, l.cfg.MessagePrefix) {
		fmt.Printf("mismatched prefix: log message %s did not match prefix: %s\n", string(logMsg.GetMessage()), string(l.cfg.MessagePrefix))
		return
	}

	if len(msg) < sepEnd {
		fmt.Printf("Cannot parse message %s\n", msg)
		return
	}

	id := Identity{
		appID: logMsg.GetAppId(),
		runID: msg[prefixEnd:guidEnd],
	}

	l.counterLock.Lock()
	defer l.counterLock.Unlock()
	counter, ok := l.counters[id]
	if !ok {
		counter = make(map[string]bool)
		l.counters[id] = counter
	}
	counter[msg[sepEnd:]] = true
}
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:34,代码来源:logcounter.go

示例5: DecodeProtoBufLogMessage

func DecodeProtoBufLogMessage(actual []byte) *events.LogMessage {
	var receivedEnvelope events.Envelope
	err := proto.Unmarshal(actual, &receivedEnvelope)
	if err != nil {
		Fail(err.Error())
	}
	return receivedEnvelope.GetLogMessage()
}
开发者ID:rakutentech,项目名称:loggregator,代码行数:8,代码来源:helpers.go

示例6: sendMessage

func (s *SyslogSink) sendMessage(messageEnvelope *events.Envelope) bool {
	logMessage := messageEnvelope.GetLogMessage()

	_, err := s.syslogWriter.Write(messagePriorityValue(logMessage), logMessage.GetMessage(), logMessage.GetSourceType(), logMessage.GetSourceInstance(), *logMessage.Timestamp)

	if err != nil {
		s.Debugf("Syslog Sink %s: Error when trying to send data to sink. Backing off. Err: %v\n", s.drainUrl, err)
		return false
	} else {
		s.Debugf("Syslog Sink %s: Successfully sent data\n", s.drainUrl)
		return true
	}
}
开发者ID:khj0651,项目名称:loggregator,代码行数:13,代码来源:syslog_sink.go

示例7: LogMessage

func LogMessage(msg *events.Envelope) Event {
	logMessage := msg.GetLogMessage()

	fields := logrus.Fields{
		"cf_app_id":       logMessage.GetAppId(),
		"timestamp":       logMessage.GetTimestamp(),
		"source_type":     logMessage.GetSourceType(),
		"message_type":    logMessage.GetMessageType().String(),
		"source_instance": logMessage.GetSourceInstance(),
	}

	return Event{
		Fields: fields,
		Msg:    string(logMessage.GetMessage()),
	}
}
开发者ID:yacloud-io,项目名称:firehose-to-syslog,代码行数:16,代码来源:events.go

示例8: valid

func valid(env *events.Envelope) bool {
	switch env.GetEventType() {
	case events.Envelope_HttpStartStop:
		return env.GetHttpStartStop() != nil
	case events.Envelope_LogMessage:
		return env.GetLogMessage() != nil
	case events.Envelope_ValueMetric:
		return env.GetValueMetric() != nil
	case events.Envelope_CounterEvent:
		return env.GetCounterEvent() != nil
	case events.Envelope_Error:
		return env.GetError() != nil
	case events.Envelope_ContainerMetric:
		return env.GetContainerMetric() != nil
	}
	return true
}
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:17,代码来源:event_unmarshaller.go

示例9:

			client := noaa.NewConsumer(dropsondeEndpoint, &tls.Config{}, nil)
			messages := make(chan *events.Envelope)
			go client.StreamWithoutReconnect(APP_ID, AUTH_TOKEN, messages)

			var request *http.Request
			Eventually(fakeDoppler.TrafficControllerConnected, 10).Should(Receive(&request))
			Expect(request.URL.Path).To(Equal("/apps/1234/stream"))

			currentTime := time.Now().UnixNano()
			dropsondeMessage := makeDropsondeMessage("Hello through NOAA", APP_ID, currentTime)
			fakeDoppler.SendLogMessage(dropsondeMessage)

			var receivedEnvelope *events.Envelope
			Eventually(messages).Should(Receive(&receivedEnvelope))

			receivedMessage := receivedEnvelope.GetLogMessage()
			Expect(receivedMessage.GetMessage()).To(BeEquivalentTo("Hello through NOAA"))
			Expect(receivedMessage.GetAppId()).To(Equal(APP_ID))
			Expect(receivedMessage.GetTimestamp()).To(Equal(currentTime))

			client.Close()
		})

		It("closes the upstream websocket connection when done", func() {
			client := noaa.NewConsumer(dropsondeEndpoint, &tls.Config{}, nil)
			messages := make(chan *events.Envelope)
			go client.StreamWithoutReconnect(APP_ID, AUTH_TOKEN, messages)

			var request *http.Request
			Eventually(fakeDoppler.TrafficControllerConnected, 10).Should(Receive(&request))
			Eventually(fakeDoppler.ConnectionPresent).Should(BeTrue())
开发者ID:khj0651,项目名称:loggregator,代码行数:31,代码来源:dropsonde_end_to_end_test.go

示例10:

		receivedChan := make(chan []byte, 2)
		_, stopKeepAlive, droppedChannel := AddWSSink(receivedChan, serverPort, "/apps/myOtherApp/recentlogs")

		Eventually(droppedChannel).Should(Receive())

		var firstMarshalledEnvelope, secondMarshalledEnvelope []byte
		Eventually(receivedChan).Should(Receive(&firstMarshalledEnvelope))
		Eventually(receivedChan).Should(Receive(&secondMarshalledEnvelope))

		var envelope1 events.Envelope
		var envelope2 events.Envelope

		proto.Unmarshal(firstMarshalledEnvelope, &envelope1)
		proto.Unmarshal(secondMarshalledEnvelope, &envelope2)

		Expect(envelope1.GetLogMessage().GetMessage()).To(BeEquivalentTo(expectedFirstMessageString))
		Expect(envelope2.GetLogMessage().GetMessage()).To(BeEquivalentTo(expectedSecondMessageString))

		stopKeepAlive <- true
	})

	It("doesn't hang when there are no messages", func() {
		receivedChan := make(chan []byte, 1)
		AddWSSink(receivedChan, serverPort, "/apps/myOtherApp/recentlogs")

		doneChan := make(chan bool)
		go func() {
			dumpAllMessages(receivedChan)
			close(doneChan)
		}()
开发者ID:Jonty,项目名称:loggregator,代码行数:30,代码来源:sinkserver_dump_test.go

示例11:

		})
	})

	Context("as a channel", func() {
		JustBeforeEach(func() {
			go buffer.Run()
		})

		It("works like a channel", func() {

			sendLogMessages("message 1", inMessageChan)

			var readMessage *events.Envelope
			Eventually(buffer.GetOutputChannel).Should(Receive(&readMessage))

			Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 1"))

			sendLogMessages("message 2", inMessageChan)

			Eventually(buffer.GetOutputChannel).Should(Receive(&readMessage))
			Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 2"))

		})

		Context("tracking dropped messages", func() {
			var fakeEventEmitter *fake.FakeEventEmitter

			receiveDroppedMessages := func() uint64 {
				var t uint64
				for i, _ := range fakeEventEmitter.GetMessages() {
					e := fakeEventEmitter.GetMessages()[i].Event.(*events.CounterEvent)
开发者ID:yingkitw,项目名称:loggregator,代码行数:31,代码来源:truncating_buffer_test.go

示例12:

		})

		JustBeforeEach(func() {
			incoming, errors = cnsmr.StreamWithoutReconnect(appGuid, authToken)
		})

		Context("when there is no TLS Config or consumerProxyFunc setting", func() {
			Context("when the connection can be established", func() {
				It("receives messages on the incoming channel", func(done Done) {
					defer close(done)

					fakeHandler.InputChan <- marshalMessage(createMessage("hello", 0))

					var message *events.Envelope
					Eventually(incoming).Should(Receive(&message))
					Expect(message.GetLogMessage().GetMessage()).To(Equal([]byte("hello")))
					fakeHandler.Close()

				})

				Context("with a specific app ID", func() {
					BeforeEach(func() {
						appGuid = "the-app-guid"
					})

					It("sends messages for a specific app", func() {
						fakeHandler.Close()

						Eventually(fakeHandler.GetLastURL).Should(ContainSubstring("/apps/the-app-guid/stream"))
					})
				})
开发者ID:cloudfoundry,项目名称:v3-cli-plugin,代码行数:31,代码来源:async_test.go

示例13:

		})
	})

	Context("as a channel", func() {
		JustBeforeEach(func() {
			go buffer.Run()
		})

		It("works like a channel", func() {

			sendLogMessages("message 1", inMessageChan)

			var readMessage *events.Envelope
			Eventually(buffer.GetOutputChannel).Should(Receive(&readMessage))

			Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 1"))

			sendLogMessages("message 2", inMessageChan)

			Eventually(buffer.GetOutputChannel).Should(Receive(&readMessage))
			Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 2"))

		})

		Context("tracking dropped messages", func() {
			var (
				fakeEventEmitter *fake.FakeEventEmitter
				mockBatcher      *mockMetricBatcher
			)

			tracksDroppedMessagesAnd := func(itMsg string, delta, total int) {
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:31,代码来源:truncating_buffer_test.go

示例14:

		})
	})

	Context("as a channel", func() {
		JustBeforeEach(func() {
			go buffer.Run()
		})

		It("works like a channel", func() {

			sendLogMessages("message 1", inMessageChan)

			var readMessage *events.Envelope
			Eventually(buffer.GetOutputChannel).Should(Receive(&readMessage))

			Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 1"))

			sendLogMessages("message 2", inMessageChan)

			Eventually(buffer.GetOutputChannel).Should(Receive(&readMessage))
			Expect(readMessage.GetLogMessage().GetMessage()).To(ContainSubstring("message 2"))

		})

		Context("tracking dropped messages", func() {
			var fakeEventEmitter *fake.FakeEventEmitter

			BeforeEach(func() {
				fakeEventEmitter = fake.NewFakeEventEmitter("doppler")
				sender := metric_sender.NewMetricSender(fakeEventEmitter)
				batcher := metricbatcher.New(sender, 100*time.Millisecond)
开发者ID:lyuyun,项目名称:loggregator,代码行数:31,代码来源:truncating_buffer_test.go

示例15:

			lm, _ = emitter.Wrap(factories.NewLogMessage(events.LogMessage_OUT, "my message", appId, "App"), "origin")
		})

		AfterEach(func() {
			close(stopKeepAlive)
			<-connectionDropped
			cleanup()
		})

		It("sends data to the websocket firehose client", func() {
			sinkManager.SendTo(appId, lm)

			rlm, err := receiveEnvelope(wsReceivedChan)
			Expect(err).NotTo(HaveOccurred())
			Expect(rlm.GetLogMessage().GetMessage()).To(Equal(lm.GetLogMessage().GetMessage()))
		})

		Context("when data is sent to the websocket firehose client", func() {
			JustBeforeEach(func() {
				sinkManager.SendTo(appId, lm)
			})

			It("emits counter metric sentMessagesFirehose", func() {
				Eventually(mockBatcher.BatchCounterInput).Should(BeCalled(
					With("sentMessagesFirehose"),
				))

				Eventually(mockChainer.SetTagInput).Should(BeCalled(
					With("subscription_id", subscriptionID),
				))
开发者ID:kei-yamazaki,项目名称:loggregator,代码行数:30,代码来源:websocket_server_test.go


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