Exemplo n.º 1
0
			Expect(receivedEnvelope.GetEventType()).To(Equal(events.Envelope_HttpStartStop))

			event := receivedEnvelope.GetHttpStartStop()
			Expect(event.GetPeerType().String()).To(Equal(events.PeerType_Server.Enum().String()))
			Expect(event.GetMethod().String()).To(Equal(events.Method_HEAD.Enum().String()))
			Expect(event.GetStartTimestamp()).ToNot(BeZero())
			Expect(event.GetStopTimestamp()).ToNot(BeZero())
			Expect(event.GetUserAgent()).To(Equal("Spider-Man"))
			Expect(event.GetStatusCode()).To(BeEquivalentTo(http.StatusTeapot))

			Expect(errorChan).To(BeEmpty())
		})

		It("should emit httpStartStop events for specific apps to the stream endpoint", func() {
			id, _ := uuid.NewV4()
			msgChan, errorChan := helpers.ConnectToStream(id.String())

			udpEmitter, err := emitter.NewUdpEmitter(fmt.Sprintf("localhost:%d", config.DropsondePort))
			Expect(err).ToNot(HaveOccurred())
			emitter := emitter.NewEventEmitter(udpEmitter, helpers.ORIGIN_NAME)
			r, err := http.NewRequest("HEAD", "/", nil)
			Expect(err).ToNot(HaveOccurred())
			r.Header.Add("User-Agent", "Superman")
			r.Header.Add("X-CF-ApplicationID", id.String())
			done := make(chan struct{})
			handler := instrumented_handler.InstrumentedHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				w.WriteHeader(http.StatusTeapot)
				close(done)
			}), emitter)

			w := httptest.NewRecorder()
Exemplo n.º 2
0
		helpers.EmitToMetron(env)

		tlsConfig := &tls.Config{InsecureSkipVerify: true}
		consumer := consumer.New(config.DopplerEndpoint, tlsConfig, nil)

		getRecentLogs := func() []*events.LogMessage {
			envelopes, err := consumer.RecentLogs("foo", "")
			Expect(err).NotTo(HaveOccurred())
			return envelopes
		}

		Eventually(getRecentLogs).Should(ContainElement(env.LogMessage))
	})

	It("sends log messages for a specific app through the stream endpoint", func() {
		msgChan, errorChan := helpers.ConnectToStream("foo")

		helpers.EmitToMetron(createLogEnvelope("Stream message", "bar"))
		helpers.EmitToMetron(createLogEnvelope("Stream message", "foo"))

		receivedEnvelope, err := helpers.FindMatchingEnvelopeById("foo", msgChan)
		Expect(err).NotTo(HaveOccurred())
		Expect(receivedEnvelope).NotTo(BeNil())
		Expect(receivedEnvelope.GetEventType()).To(Equal(events.Envelope_LogMessage))

		event := receivedEnvelope.GetLogMessage()
		Expect(envelope_extensions.GetAppId(receivedEnvelope)).To(Equal("foo"))
		Expect(string(event.GetMessage())).To(Equal("Stream message"))
		Expect(event.GetMessageType().String()).To(Equal(events.LogMessage_OUT.Enum().String()))
		Expect(event.GetTimestamp()).ToNot(BeZero())
Exemplo n.º 3
0
			Expect(receivedEnvelope.GetValueMetric()).To(Equal(envelope.GetValueMetric()))
		})

		It("container metric emitted to metron", func() {
			envelope := createContainerMetric("test-id")
			helpers.EmitToMetron(envelope)

			receivedEnvelope := helpers.FindMatchingEnvelope(msgChan)
			Expect(receivedEnvelope).NotTo(BeNil())

			Expect(receivedEnvelope.GetContainerMetric()).To(Equal(envelope.GetContainerMetric()))
		})
	})
	Describe("the stream receives a", func() {
		It("container metric emitted to metron", func() {
			msgChan, errorChan := helpers.ConnectToStream("test-id")
			envelope := createContainerMetric("test-id")
			helpers.EmitToMetron(createContainerMetric("alternate-id"))
			helpers.EmitToMetron(envelope)

			receivedEnvelope, err := helpers.FindMatchingEnvelopeById("test-id", msgChan)
			Expect(err).NotTo(HaveOccurred())
			Expect(receivedEnvelope).NotTo(BeNil())

			Expect(receivedEnvelope.GetContainerMetric()).To(Equal(envelope.GetContainerMetric()))
			Expect(errorChan).To(BeEmpty())
		})
	})
})

func createCounterEvent() *events.Envelope {