Exemple #1
0
	var (
		msgChan   chan *events.Envelope
		errorChan chan error
	)
	BeforeEach(func() {
		msgChan, errorChan = helpers.ConnectToFirehose()
	})

	AfterEach(func() {
		Expect(errorChan).To(BeEmpty())
	})

	Context("When a counter event is emitted to metron", func() {
		It("Gets delivered to firehose", func() {
			envelope := createCounterEvent()
			helpers.EmitToMetron(envelope)

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

			receivedCounterEvent := receivedEnvelope.GetCounterEvent()
			Expect(receivedCounterEvent).To(Equal(counterEvent))
			helpers.EmitToMetron(envelope)

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

			receivedCounterEvent = receivedEnvelope.GetCounterEvent()
			Expect(receivedCounterEvent.GetTotal()).To(Equal(uint64(10)))

		})
	"github.com/cloudfoundry/dropsonde/envelope_extensions"
	"github.com/cloudfoundry/noaa/consumer"
	"github.com/cloudfoundry/sonde-go/events"
	"github.com/gogo/protobuf/proto"
)

const (
	cfSetupTimeOut     = 10 * time.Second
	cfPushTimeOut      = 2 * time.Minute
	defaultMemoryLimit = "256MB"
)

var _ = Describe("Logs", func() {
	It("gets through recent logs", func() {
		env := createLogEnvelope("I AM A BANANA!", "foo")
		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")
	Describe("the firehose receives a", func() {
		var (
			msgChan   <-chan *events.Envelope
			errorChan <-chan error
		)
		BeforeEach(func() {
			msgChan, errorChan = helpers.ConnectToFirehose()
		})

		AfterEach(func() {
			Expect(errorChan).To(BeEmpty())
		})

		It("counter event emitted to metron with correct total", func() {
			envelope := createCounterEvent()
			helpers.EmitToMetron(envelope)

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

			Expect(receivedEnvelope.GetCounterEvent()).To(Equal(envelope.GetCounterEvent()))
			helpers.EmitToMetron(envelope)

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

			Expect(receivedEnvelope.GetCounterEvent().GetTotal()).To(Equal(uint64(10)))
		})

		It("value metric emitted to metron", func() {
			envelope := createValueMetric()
			var buildValueMetric = func(name string, value float64) *events.Envelope {
				valueMetric := createValueMetric()
				valueMetric.ValueMetric.Name = proto.String(name)
				valueMetric.ValueMetric.Value = proto.Float64(value)
				return valueMetric
			}

			var readFromErrors = func(errs <-chan error) {
				defer GinkgoRecover()
				Consistently(errs).ShouldNot(Receive())
			}

			var emitControlMessages = func() {
				for i := 0; i < 20; i++ {
					time.Sleep(10 * time.Millisecond)
					helpers.EmitToMetron(buildValueMetric("controlValue", 0))
				}
			}

			var waitForControl = func(msgs <-chan *events.Envelope) {
				Eventually(msgs).Should(Receive())
			}

			var readEnvelopes = func(t time.Duration, msgs <-chan *events.Envelope) []*events.Envelope {
				var envelopes []*events.Envelope
				timer := time.NewTimer(t)
				for {
					select {
					case <-timer.C:
						return envelopes
					case e := <-msgs:
	var (
		msgChan   chan *events.Envelope
		errorChan chan error
	)
	BeforeEach(func() {
		msgChan, errorChan = helpers.ConnectToFirehose()
	})

	AfterEach(func() {
		Expect(errorChan).To(BeEmpty())
	})

	Context("When a Http start/stop event emited into metron", func() {
		It("should expect HttpStartStop metric out of firehose", func() {
			startEnvelope := createHttpStartEvent()
			helpers.EmitToMetron(startEnvelope)

			stopEnvelope := createHttpStopEvent()
			helpers.EmitToMetron(stopEnvelope)

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

			receivedHttpStartStopEvent := receivedEnvelop.GetHttpStartStop()

			// not too sure if this deep equal would mach both objects
			Expect(receivedHttpStartStopEvent).To(Equal(httpStartStop))

			Expect(receivedHttpStartStopEvent.GetRequestId()).To(Equal(requestId))
			Expect(receivedHttpStartStopEvent.GetPeerType().String()).To(Equal(events.PeerType_Client.Enum().String()))
			Expect(receivedHttpStartStopEvent.GetMethod().String()).To(Equal(events.Method_GET.Enum().String()))