gexec.NewPrefixedWriter("[e][nozzle] ", GinkgoWriter),
			)
			Expect(err).NotTo(HaveOccurred())
		})
		It("forwards metrics in a batch", func(done Done) {
			sendEventsThroughFirehose(fakeFirehoseInputChan)

			// eventually receive a batch from fake DD
			var messageBytes []byte
			Eventually(fakeOpenTSDBChan, "2s").Should(Receive(&messageBytes))

			// Break JSON blob into a list of blobs, one for each metric
			var metrics []poster.Metric

			log.Printf("Received message is: %s\n", string(messageBytes))
			err := json.Unmarshal(util.UnzipIgnoreError(messageBytes), &metrics)
			Expect(err).NotTo(HaveOccurred())

			Expect(metrics).To(ContainElement(
				poster.Metric{
					Metric:    "origin.metricName",
					Timestamp: 1,
					Value:     5,
					Tags: poster.Tags{
						Deployment: "deployment-name",
						Job:        "doppler",
						Index:      "SOME-METRIC-GUID",
						IP:         "",
					},
				}))
			Expect(metrics).To(ContainElement(
			ValueMetric: &events.ValueMetric{
				Name:  proto.String("metricName"),
				Value: proto.Float64(float64(1)),
				Unit:  proto.String("gauge"),
			},
			Deployment: proto.String("deployment-name"),
			Job:        proto.String("doppler"),
		}
		fakeFirehose.AddEvent(envelope)

		go nozzle.Start()

		var contents []byte
		Eventually(fakeOpenTSDB.ReceivedContents, 2).Should(Receive(&contents))
		var metrics []poster.Metric
		err := json.Unmarshal(util.UnzipIgnoreError(contents), &metrics)
		Expect(err).ToNot(HaveOccurred())

		Expect(logOutput).ToNot(gbytes.Say("Error while reading from the firehose"))

		// +3 internal metrics that show totalMessagesReceived, totalMetricSent, and slowConsumerAlert
		Expect(metrics).To(HaveLen(4))
	}, 3)

	It("sends a server disconnected metric when the server disconnects abnormally", func(done Done) {
		defer close(done)

		for i := 0; i < 10; i++ {
			envelope := events.Envelope{
				Origin:    proto.String("origin"),
				Timestamp: proto.Int64(1000000000),
				CpuPercentage: proto.Float64(20.0),
				MemoryBytes:   proto.Uint64(19939949),
				DiskBytes:     proto.Uint64(29488929),
			},
			Deployment: proto.String("deployment-name"),
			Job:        proto.String("doppler"),
		})

		err := c.PostMetrics()
		Expect(err).ToNot(HaveOccurred())

		var receivedBytes []byte
		Eventually(bodyChan).Should(Receive(&receivedBytes))

		var metrics []poster.Metric
		err = json.Unmarshal(util.UnzipIgnoreError(receivedBytes), &metrics)
		Expect(err).NotTo(HaveOccurred())
		Expect(metrics).To(HaveLen(3))

		validateMetrics(metrics, 2, 0)

	})

	It("emits internal metrics with the correct tags", func() {
		err := c.PostMetrics()
		Expect(err).ToNot(HaveOccurred())

		var receivedBytes []byte
		Eventually(bodyChan).Should(Receive(&receivedBytes))

		var metrics []poster.Metric