diff --git a/collectors/collectors_suite_test.go b/collectors/collectors_suite_test.go index 5cfd5d57..90237719 100644 --- a/collectors/collectors_suite_test.go +++ b/collectors/collectors_suite_test.go @@ -3,11 +3,11 @@ package collectors_test import ( "testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) func TestCollectors(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Collectors Suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Collectors Suite") } diff --git a/collectors/raw_metrics_collector_test.go b/collectors/raw_metrics_collector_test.go index 15e775d6..3469ebef 100644 --- a/collectors/raw_metrics_collector_test.go +++ b/collectors/raw_metrics_collector_test.go @@ -10,26 +10,26 @@ import ( "github.com/bosh-prometheus/firehose_exporter/metricmaker" "github.com/bosh-prometheus/firehose_exporter/metrics" "github.com/bosh-prometheus/firehose_exporter/testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "github.com/bosh-prometheus/firehose_exporter/collectors" ) -var _ = Describe("RawMetricsCollector", func() { +var _ = ginkgo.Describe("RawMetricsCollector", func() { var pointBuffer chan []*metrics.RawMetric var collector *collectors.RawMetricsCollector - BeforeEach(func() { + ginkgo.BeforeEach(func() { pointBuffer = make(chan []*metrics.RawMetric) collector = collectors.NewRawMetricsCollector(pointBuffer, 10*time.Minute) }) - AfterEach(func() { + ginkgo.AfterEach(func() { close(pointBuffer) }) - Context("Collect", func() { - It("should save in metric store collected points", func() { + ginkgo.Context("Collect", func() { + ginkgo.It("should save in metric store collected points", func() { go collector.Collect() pointBuffer <- []*metrics.RawMetric{ metricmaker.NewRawMetricCounter("my_metric", map[string]string{ @@ -55,11 +55,11 @@ var _ = Describe("RawMetricsCollector", func() { ms := collector.MetricStore() - Expect(ms).To(HaveKey("my_metric")) - Expect(ms).To(HaveKey("my_second_metric")) - Expect(ms["my_second_metric"]).To(HaveLen(1)) - Expect(ms["my_metric"]).To(HaveLen(2)) - Expect(ms["my_metric"]).To(testing.ContainPoints([]*metrics.RawMetric{ + gomega.Expect(ms).To(gomega.HaveKey("my_metric")) + gomega.Expect(ms).To(gomega.HaveKey("my_second_metric")) + gomega.Expect(ms["my_second_metric"]).To(gomega.HaveLen(1)) + gomega.Expect(ms["my_metric"]).To(gomega.HaveLen(2)) + gomega.Expect(ms["my_metric"]).To(testing.ContainPoints([]*metrics.RawMetric{ metricmaker.NewRawMetricCounter("my_metric", map[string]string{ "origin": "my-origin", "variadic": "2", @@ -72,8 +72,8 @@ var _ = Describe("RawMetricsCollector", func() { }) - Context("CleanPeriodic", func() { - It("should clean swept metrics", func() { + ginkgo.Context("CleanPeriodic", func() { + ginkgo.It("should clean swept metrics", func() { collector.SetCleanPeriodicDuration(70 * time.Millisecond) go collector.Collect() go collector.CleanPeriodic() @@ -86,19 +86,19 @@ var _ = Describe("RawMetricsCollector", func() { time.Sleep(50 * time.Millisecond) m.SetSweep(true) ms := collector.MetricStore() - Expect(ms).To(HaveKey("my_metric")) - Expect(ms["my_metric"]).To(HaveLen(1)) - Expect(ms["my_metric"][0].IsSwept()).To(BeTrue()) + gomega.Expect(ms).To(gomega.HaveKey("my_metric")) + gomega.Expect(ms["my_metric"]).To(gomega.HaveLen(1)) + gomega.Expect(ms["my_metric"][0].IsSwept()).To(gomega.BeTrue()) time.Sleep(50 * time.Millisecond) ms = collector.MetricStore() - Expect(ms).To(HaveKey("my_metric")) - Expect(ms["my_metric"]).To(HaveLen(0)) + gomega.Expect(ms).To(gomega.HaveKey("my_metric")) + gomega.Expect(ms["my_metric"]).To(gomega.HaveLen(0)) }) }) - Context("RenderExpFmt", func() { - BeforeEach(func() { + ginkgo.Context("RenderExpFmt", func() { + ginkgo.BeforeEach(func() { go collector.Collect() pointBuffer <- []*metrics.RawMetric{ metricmaker.NewRawMetricCounter("my_metric", map[string]string{ @@ -116,37 +116,37 @@ var _ = Describe("RawMetricsCollector", func() { } time.Sleep(50 * time.Millisecond) }) - It("should show metric in expfmt in plain text from registered internal metrics", func() { + ginkgo.It("should show metric in expfmt in plain text from registered internal metrics", func() { respRec := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "http://localhost", nil) collector.RenderExpFmt(respRec, req) content := respRec.Body.String() - Expect(content).To(ContainSubstring(`go_gc_duration_seconds`)) + gomega.Expect(content).To(gomega.ContainSubstring(`go_gc_duration_seconds`)) }) - When("no gzip is asked", func() { - It("should show metric in expfmt in plain text", func() { + ginkgo.When("no gzip is asked", func() { + ginkgo.It("should show metric in expfmt in plain text", func() { respRec := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "http://localhost", nil) collector.RenderExpFmt(respRec, req) content := respRec.Body.String() - Expect(content).To(ContainSubstring(`my_metric{origin="my-origin",variadic="1"} 1`)) - Expect(content).To(ContainSubstring(`my_metric{origin="my-origin",variadic="2"} 1`)) - Expect(content).To(ContainSubstring(`my_second_metric{origin="my-origin",variadic="1"} 1`)) + gomega.Expect(content).To(gomega.ContainSubstring(`my_metric{origin="my-origin",variadic="1"} 1`)) + gomega.Expect(content).To(gomega.ContainSubstring(`my_metric{origin="my-origin",variadic="2"} 1`)) + gomega.Expect(content).To(gomega.ContainSubstring(`my_second_metric{origin="my-origin",variadic="1"} 1`)) }) }) - When("with gzip is asked", func() { - It("should show metric in expfmt in gzip", func() { + ginkgo.When("with gzip is asked", func() { + ginkgo.It("should show metric in expfmt in gzip", func() { respRec := httptest.NewRecorder() req := httptest.NewRequest(http.MethodGet, "http://localhost", nil) req.Header.Set("Accept-Encoding", "gzip") collector.RenderExpFmt(respRec, req) gzipReader, err := gzip.NewReader(respRec.Body) - Expect(err).ToNot(HaveOccurred()) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) defer gzipReader.Close() var resB bytes.Buffer @@ -157,9 +157,9 @@ var _ = Describe("RawMetricsCollector", func() { content := resB.String() - Expect(content).To(ContainSubstring(`my_metric{origin="my-origin",variadic="1"} 1`)) - Expect(content).To(ContainSubstring(`my_metric{origin="my-origin",variadic="2"} 1`)) - Expect(content).To(ContainSubstring(`my_second_metric{origin="my-origin",variadic="1"} 1`)) + gomega.Expect(content).To(gomega.ContainSubstring(`my_metric{origin="my-origin",variadic="1"} 1`)) + gomega.Expect(content).To(gomega.ContainSubstring(`my_metric{origin="my-origin",variadic="2"} 1`)) + gomega.Expect(content).To(gomega.ContainSubstring(`my_second_metric{origin="my-origin",variadic="1"} 1`)) }) }) }) diff --git a/metricmaker/compat_test.go b/metricmaker/compat_test.go index 922362e0..b5bc4aea 100644 --- a/metricmaker/compat_test.go +++ b/metricmaker/compat_test.go @@ -2,52 +2,52 @@ package metricmaker_test import ( "github.com/bosh-prometheus/firehose_exporter/metricmaker" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) -var _ = Describe("Compat", func() { - BeforeEach(func() { +var _ = ginkgo.Describe("Compat", func() { + ginkgo.BeforeEach(func() { metricmaker.SetMetricConverters(make([]metricmaker.MetricConverter, 0)) }) - Describe("RetroCompatMetricNames", func() { - Context("when have a container metric", func() { - It("should rename metric name with old name", func() { + ginkgo.Describe("RetroCompatMetricNames", func() { + ginkgo.Context("when have a container metric", func() { + ginkgo.It("should rename metric name with old name", func() { m := metricmaker.NewRawMetricGauge("cpu", make(map[string]string), 0) metricmaker.RetroCompatMetricNames(m) - Expect(m.MetricName()).To(Equal("container_metric_cpu_percentage")) + gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_cpu_percentage")) m = metricmaker.NewRawMetricGauge("memory", make(map[string]string), 0) metricmaker.RetroCompatMetricNames(m) - Expect(m.MetricName()).To(Equal("container_metric_memory_bytes")) + gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_memory_bytes")) m = metricmaker.NewRawMetricGauge("disk", make(map[string]string), 0) metricmaker.RetroCompatMetricNames(m) - Expect(m.MetricName()).To(Equal("container_metric_disk_bytes")) + gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_disk_bytes")) m = metricmaker.NewRawMetricGauge("memory_quota", make(map[string]string), 0) metricmaker.RetroCompatMetricNames(m) - Expect(m.MetricName()).To(Equal("container_metric_memory_bytes_quota")) + gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_memory_bytes_quota")) m = metricmaker.NewRawMetricGauge("disk_quota", make(map[string]string), 0) metricmaker.RetroCompatMetricNames(m) - Expect(m.MetricName()).To(Equal("container_metric_disk_bytes_quota")) + gomega.Expect(m.MetricName()).To(gomega.Equal("container_metric_disk_bytes_quota")) }) }) - Context("when have a counter metric which is not a container metric", func() { - It("should prefix with counter_event_ add origin and suffix with total", func() { + ginkgo.Context("when have a counter metric which is not a container metric", func() { + ginkgo.It("should prefix with counter_event_ add origin and suffix with total", func() { m := metricmaker.NewRawMetricCounter("my_metric", make(map[string]string), 0) m.SetOrigin("origin") metricmaker.RetroCompatMetricNames(m) - Expect(m.MetricName()).To(Equal("counter_event_origin_my_metric_total")) + gomega.Expect(m.MetricName()).To(gomega.Equal("counter_event_origin_my_metric_total")) }) }) - Context("when have a gauge metric which is not a container metric", func() { - It("should prefix with value_metric_ add origin", func() { + ginkgo.Context("when have a gauge metric which is not a container metric", func() { + ginkgo.It("should prefix with value_metric_ add origin", func() { m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0) m.SetOrigin("origin") metricmaker.RetroCompatMetricNames(m) - Expect(m.MetricName()).To(Equal("value_metric_origin_my_metric")) + gomega.Expect(m.MetricName()).To(gomega.Equal("value_metric_origin_my_metric")) }) }) }) diff --git a/metricmaker/converters_test.go b/metricmaker/converters_test.go index 5043aed3..db0c502e 100644 --- a/metricmaker/converters_test.go +++ b/metricmaker/converters_test.go @@ -3,58 +3,58 @@ package metricmaker_test import ( "github.com/bosh-prometheus/firehose_exporter/metricmaker" "github.com/bosh-prometheus/firehose_exporter/transform" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) -var _ = Describe("Converters", func() { - BeforeEach(func() { +var _ = ginkgo.Describe("Converters", func() { + ginkgo.BeforeEach(func() { metricmaker.SetMetricConverters(make([]metricmaker.MetricConverter, 0)) }) - Describe("NormalizeName", func() { - It("should reformat name", func() { + ginkgo.Describe("NormalizeName", func() { + ginkgo.It("should reformat name", func() { m := metricmaker.NewRawMetricGauge("FooBar", make(map[string]string), 0) metricmaker.NormalizeName(m) - Expect(m.MetricName()).To(Equal("foo_bar")) + gomega.Expect(m.MetricName()).To(gomega.Equal("foo_bar")) }) }) - Describe("AddNamespace", func() { - It("should prefix with namespace given", func() { + ginkgo.Describe("AddNamespace", func() { + ginkgo.It("should prefix with namespace given", func() { m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0) metricmaker.AddNamespace("namespace")(m) - Expect(m.MetricName()).To(Equal("namespace_my_metric")) + gomega.Expect(m.MetricName()).To(gomega.Equal("namespace_my_metric")) }) }) - Describe("FindAndReplaceByName", func() { - It("should only replace name if found", func() { + ginkgo.Describe("FindAndReplaceByName", func() { + ginkgo.It("should only replace name if found", func() { m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0) metricmaker.FindAndReplaceByName("foo", "bar")(m) - Expect(m.MetricName()).To(Equal("my_metric")) + gomega.Expect(m.MetricName()).To(gomega.Equal("my_metric")) m = metricmaker.NewRawMetricGauge("foo", make(map[string]string), 0) metricmaker.FindAndReplaceByName("foo", "bar")(m) - Expect(m.MetricName()).To(Equal("bar")) + gomega.Expect(m.MetricName()).To(gomega.Equal("bar")) }) }) - Describe("InjectMapLabel", func() { - It("should inject label given", func() { + ginkgo.Describe("InjectMapLabel", func() { + ginkgo.It("should inject label given", func() { m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0) metricmaker.InjectMapLabel(map[string]string{ "foo": "bar", })(m) - Expect(m.Metric().Label).To(HaveLen(1)) - Expect(m.Metric().Label[0].GetName()).To(Equal("foo")) - Expect(m.Metric().Label[0].GetValue()).To(Equal("bar")) + gomega.Expect(m.Metric().Label).To(gomega.HaveLen(1)) + gomega.Expect(m.Metric().Label[0].GetName()).To(gomega.Equal("foo")) + gomega.Expect(m.Metric().Label[0].GetValue()).To(gomega.Equal("bar")) }) }) - Describe("PresetLabels", func() { - It("should rewrite labels", func() { + ginkgo.Describe("PresetLabels", func() { + ginkgo.It("should rewrite labels", func() { m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0) m.Metric().Label = transform.LabelsMapToLabelPairs(map[string]string{ "deployment": "deployment", @@ -63,18 +63,18 @@ var _ = Describe("Converters", func() { "ip": "127.0.0.1", }) metricmaker.PresetLabels(m) - Expect(m.Metric().Label).To(HaveLen(8)) + gomega.Expect(m.Metric().Label).To(gomega.HaveLen(8)) labelsMap := transform.LabelPairsToLabelsMap(m.Metric().Label) - Expect(labelsMap).To(HaveKeyWithValue("bosh_deployment", "deployment")) - Expect(labelsMap).To(HaveKeyWithValue("bosh_job_name", "job")) - Expect(labelsMap).To(HaveKeyWithValue("bosh_job_id", "0")) - Expect(labelsMap).To(HaveKeyWithValue("bosh_job_ip", "127.0.0.1")) + gomega.Expect(labelsMap).To(gomega.HaveKeyWithValue("bosh_deployment", "deployment")) + gomega.Expect(labelsMap).To(gomega.HaveKeyWithValue("bosh_job_name", "job")) + gomega.Expect(labelsMap).To(gomega.HaveKeyWithValue("bosh_job_id", "0")) + gomega.Expect(labelsMap).To(gomega.HaveKeyWithValue("bosh_job_ip", "127.0.0.1")) }) }) - Describe("OrderAndSanitizeLabels", func() { - It("should order and sanitize labels", func() { + ginkgo.Describe("OrderAndSanitizeLabels", func() { + ginkgo.It("should order and sanitize labels", func() { m := metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0) m.Metric().Label = transform.LabelsMapToLabelPairs(map[string]string{ "job": "job", @@ -87,28 +87,28 @@ var _ = Describe("Converters", func() { metricmaker.OrderAndSanitizeLabels(m) labels := m.Metric().Label - Expect(m.Metric().Label).To(HaveLen(5)) - Expect(labels[0].GetName()).To(Equal("deployment")) - Expect(labels[1].GetName()).To(Equal("index")) - Expect(labels[2].GetName()).To(Equal("ip")) - Expect(labels[3].GetName()).To(Equal("job")) - Expect(labels[4].GetName()).To(Equal("label_dash")) + gomega.Expect(m.Metric().Label).To(gomega.HaveLen(5)) + gomega.Expect(labels[0].GetName()).To(gomega.Equal("deployment")) + gomega.Expect(labels[1].GetName()).To(gomega.Equal("index")) + gomega.Expect(labels[2].GetName()).To(gomega.Equal("ip")) + gomega.Expect(labels[3].GetName()).To(gomega.Equal("job")) + gomega.Expect(labels[4].GetName()).To(gomega.Equal("label_dash")) }) }) - Describe("SuffixCounterWithTotal", func() { - It("should suffix only counter metrics without _total suffix with it", func() { + ginkgo.Describe("SuffixCounterWithTotal", func() { + ginkgo.It("should suffix only counter metrics without _total suffix with it", func() { m := metricmaker.NewRawMetricCounter("my_metric", make(map[string]string), 0) metricmaker.SuffixCounterWithTotal(m) - Expect(m.MetricName()).To(Equal("my_metric_total")) + gomega.Expect(m.MetricName()).To(gomega.Equal("my_metric_total")) m = metricmaker.NewRawMetricGauge("my_metric", make(map[string]string), 0) metricmaker.SuffixCounterWithTotal(m) - Expect(m.MetricName()).To(Equal("my_metric")) + gomega.Expect(m.MetricName()).To(gomega.Equal("my_metric")) m = metricmaker.NewRawMetricGauge("my_metric_total", make(map[string]string), 0) metricmaker.SuffixCounterWithTotal(m) - Expect(m.MetricName()).To(Equal("my_metric_total")) + gomega.Expect(m.MetricName()).To(gomega.Equal("my_metric_total")) }) }) }) diff --git a/metricmaker/metricmaker_suite_test.go b/metricmaker/metricmaker_suite_test.go index bf7932f9..7b91bd42 100644 --- a/metricmaker/metricmaker_suite_test.go +++ b/metricmaker/metricmaker_suite_test.go @@ -3,11 +3,11 @@ package metricmaker_test import ( "testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) func TestMetricmaker(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Metricate Suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Metricate Suite") } diff --git a/metricmaker/metricmaker_test.go b/metricmaker/metricmaker_test.go index b1732227..ce182a7a 100644 --- a/metricmaker/metricmaker_test.go +++ b/metricmaker/metricmaker_test.go @@ -4,43 +4,43 @@ import ( "code.cloudfoundry.org/go-loggregator/v8/rpc/loggregator_v2" "github.com/bosh-prometheus/firehose_exporter/metricmaker" "github.com/bosh-prometheus/firehose_exporter/metrics" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) -var _ = Describe("MetricMaker", func() { - BeforeEach(func() { +var _ = ginkgo.Describe("MetricMaker", func() { + ginkgo.BeforeEach(func() { metricmaker.SetMetricConverters(make([]metricmaker.MetricConverter, 0)) }) - Context("NewRawMetricCounter", func() { - It("should create raw metric with counter", func() { + ginkgo.Context("NewRawMetricCounter", func() { + ginkgo.It("should create raw metric with counter", func() { m := metricmaker.NewRawMetricCounter("cpu", map[string]string{ "origin": "an-origin", }, 1) - Expect(m.MetricName()).To(Equal("cpu")) - Expect(m.Origin()).To(Equal("an-origin")) - Expect(m.Metric().Counter).ToNot(BeNil()) - Expect(m.Metric().Counter.GetValue()).To(Equal(1.0)) + gomega.Expect(m.MetricName()).To(gomega.Equal("cpu")) + gomega.Expect(m.Origin()).To(gomega.Equal("an-origin")) + gomega.Expect(m.Metric().Counter).ToNot(gomega.BeNil()) + gomega.Expect(m.Metric().Counter.GetValue()).To(gomega.Equal(1.0)) }) }) - Context("NewRawMetricCounter", func() { - It("should create raw metric with counter", func() { + ginkgo.Context("NewRawMetricCounter", func() { + ginkgo.It("should create raw metric with counter", func() { m := metricmaker.NewRawMetricGauge("cpu", map[string]string{ "origin": "an-origin", }, 1) - Expect(m.MetricName()).To(Equal("cpu")) - Expect(m.Origin()).To(Equal("an-origin")) - Expect(m.Metric().Gauge).ToNot(BeNil()) - Expect(m.Metric().Gauge.GetValue()).To(Equal(1.0)) + gomega.Expect(m.MetricName()).To(gomega.Equal("cpu")) + gomega.Expect(m.Origin()).To(gomega.Equal("an-origin")) + gomega.Expect(m.Metric().Gauge).ToNot(gomega.BeNil()) + gomega.Expect(m.Metric().Gauge.GetValue()).To(gomega.Equal(1.0)) }) }) - Context("NewRawMetricsFromEnvelop", func() { - Context("envelop is timer", func() { - It("should give an empty list", func() { + ginkgo.Context("NewRawMetricsFromEnvelop", func() { + ginkgo.Context("envelop is timer", func() { + ginkgo.It("should give an empty list", func() { ms := metricmaker.NewRawMetricsFromEnvelop(&loggregator_v2.Envelope{ Timestamp: 0, SourceId: "", @@ -50,12 +50,12 @@ var _ = Describe("MetricMaker", func() { Message: &loggregator_v2.Envelope_Timer{}, }) - Expect(ms).To(HaveLen(0)) + gomega.Expect(ms).To(gomega.HaveLen(0)) }) }) - Context("envelop is counter", func() { - It("should give metric associated", func() { + ginkgo.Context("envelop is counter", func() { + ginkgo.It("should give metric associated", func() { ms := metricmaker.NewRawMetricsFromEnvelop(&loggregator_v2.Envelope{ Timestamp: 0, SourceId: "source-id", @@ -73,27 +73,27 @@ var _ = Describe("MetricMaker", func() { }, }) - Expect(ms).To(HaveLen(1)) + gomega.Expect(ms).To(gomega.HaveLen(1)) m := ms[0] - Expect(m.MetricName()).To(Equal("my_metric")) - Expect(m.Origin()).To(Equal("my-origin")) + gomega.Expect(m.MetricName()).To(gomega.Equal("my_metric")) + gomega.Expect(m.Origin()).To(gomega.Equal("my-origin")) metricDto := m.Metric() - Expect(metricDto).ToNot(BeNil()) - Expect(metricDto.Counter).ToNot(BeNil()) - Expect(metricDto.Counter.GetValue()).To(Equal(1.0)) + gomega.Expect(metricDto).ToNot(gomega.BeNil()) + gomega.Expect(metricDto.Counter).ToNot(gomega.BeNil()) + gomega.Expect(metricDto.Counter.GetValue()).To(gomega.Equal(1.0)) - Expect(metricDto.Label[0].GetName()).To(Equal("instance_id")) - Expect(metricDto.Label[0].GetValue()).To(Equal("my-instance")) - Expect(metricDto.Label[1].GetName()).To(Equal("origin")) - Expect(metricDto.Label[1].GetValue()).To(Equal("my-origin")) - Expect(metricDto.Label[2].GetName()).To(Equal("source_id")) - Expect(metricDto.Label[2].GetValue()).To(Equal("source-id")) + gomega.Expect(metricDto.Label[0].GetName()).To(gomega.Equal("instance_id")) + gomega.Expect(metricDto.Label[0].GetValue()).To(gomega.Equal("my-instance")) + gomega.Expect(metricDto.Label[1].GetName()).To(gomega.Equal("origin")) + gomega.Expect(metricDto.Label[1].GetValue()).To(gomega.Equal("my-origin")) + gomega.Expect(metricDto.Label[2].GetName()).To(gomega.Equal("source_id")) + gomega.Expect(metricDto.Label[2].GetValue()).To(gomega.Equal("source-id")) }) }) - Context("envelop is gauge", func() { - It("should give metric associated", func() { + ginkgo.Context("envelop is gauge", func() { + ginkgo.It("should give metric associated", func() { ms := metricmaker.NewRawMetricsFromEnvelop(&loggregator_v2.Envelope{ Timestamp: 0, SourceId: "source-id", @@ -118,30 +118,30 @@ var _ = Describe("MetricMaker", func() { }, }) - Expect(ms).To(HaveLen(2)) + gomega.Expect(ms).To(gomega.HaveLen(2)) // force reorder if ms[0].MetricName() != "my_metric_1" { ms = []*metrics.RawMetric{ms[1], ms[0]} } - Expect(ms[0].MetricName()).To(Equal("my_metric_1")) - Expect(ms[0].Origin()).To(Equal("my-origin")) - Expect(ms[1].MetricName()).To(Equal("my_metric_2")) - Expect(ms[1].Origin()).To(Equal("my-origin")) + gomega.Expect(ms[0].MetricName()).To(gomega.Equal("my_metric_1")) + gomega.Expect(ms[0].Origin()).To(gomega.Equal("my-origin")) + gomega.Expect(ms[1].MetricName()).To(gomega.Equal("my_metric_2")) + gomega.Expect(ms[1].Origin()).To(gomega.Equal("my-origin")) m := ms[0] metricDto := m.Metric() - Expect(metricDto).ToNot(BeNil()) - Expect(metricDto.Gauge).ToNot(BeNil()) - Expect(metricDto.Gauge.GetValue()).To(Equal(1.0)) - - Expect(metricDto.Label[0].GetName()).To(Equal("instance_id")) - Expect(metricDto.Label[0].GetValue()).To(Equal("my-instance")) - Expect(metricDto.Label[1].GetName()).To(Equal("origin")) - Expect(metricDto.Label[1].GetValue()).To(Equal("my-origin")) - Expect(metricDto.Label[2].GetName()).To(Equal("source_id")) - Expect(metricDto.Label[2].GetValue()).To(Equal("source-id")) - Expect(metricDto.Label[3].GetName()).To(Equal("unit")) - Expect(metricDto.Label[3].GetValue()).To(Equal("bytes")) + gomega.Expect(metricDto).ToNot(gomega.BeNil()) + gomega.Expect(metricDto.Gauge).ToNot(gomega.BeNil()) + gomega.Expect(metricDto.Gauge.GetValue()).To(gomega.Equal(1.0)) + + gomega.Expect(metricDto.Label[0].GetName()).To(gomega.Equal("instance_id")) + gomega.Expect(metricDto.Label[0].GetValue()).To(gomega.Equal("my-instance")) + gomega.Expect(metricDto.Label[1].GetName()).To(gomega.Equal("origin")) + gomega.Expect(metricDto.Label[1].GetValue()).To(gomega.Equal("my-origin")) + gomega.Expect(metricDto.Label[2].GetName()).To(gomega.Equal("source_id")) + gomega.Expect(metricDto.Label[2].GetValue()).To(gomega.Equal("source-id")) + gomega.Expect(metricDto.Label[3].GetName()).To(gomega.Equal("unit")) + gomega.Expect(metricDto.Label[3].GetValue()).To(gomega.Equal("bytes")) }) }) diff --git a/metrics/metrics_suite_test.go b/metrics/metrics_suite_test.go index e57e348f..159d7ef8 100644 --- a/metrics/metrics_suite_test.go +++ b/metrics/metrics_suite_test.go @@ -1,13 +1,13 @@ package metrics_test import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "testing" ) func TestMetrics(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Metrics Suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Metrics Suite") } diff --git a/metrics/raw_metric_test.go b/metrics/raw_metric_test.go index 797702a0..ca668a6c 100644 --- a/metrics/raw_metric_test.go +++ b/metrics/raw_metric_test.go @@ -5,16 +5,16 @@ import ( "github.com/bosh-prometheus/firehose_exporter/transform" "github.com/gogo/protobuf/proto" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" dto "github.com/prometheus/client_model/go" "github.com/bosh-prometheus/firehose_exporter/metrics" ) -var _ = Describe("RawMetric", func() { - Context("EstimateMetricSize", func() { - It("should give an estimate metric size based on timestamp, value and label", func() { +var _ = ginkgo.Describe("RawMetric", func() { + ginkgo.Context("EstimateMetricSize", func() { + ginkgo.It("should give an estimate metric size based on timestamp, value and label", func() { m := metrics.NewRawMetric("my_metric", "my-origin", &dto.Metric{ Label: transform.LabelsMapToLabelPairs(map[string]string{ "origin": "my-origin", @@ -22,7 +22,7 @@ var _ = Describe("RawMetric", func() { TimestampMs: nil, }) - Expect(m.EstimateMetricSize()).To(Equal(23)) + gomega.Expect(m.EstimateMetricSize()).To(gomega.Equal(23)) m = metrics.NewRawMetric("my_metric", "my-origin", &dto.Metric{ Label: transform.LabelsMapToLabelPairs(map[string]string{ @@ -30,26 +30,26 @@ var _ = Describe("RawMetric", func() { }), TimestampMs: proto.Int64(0), }) - Expect(m.EstimateMetricSize()).To(Equal(23 + 8)) + gomega.Expect(m.EstimateMetricSize()).To(gomega.Equal(23 + 8)) }) }) - Context("Set ExpireIn", func() { - It("should mark as swept when expire time is passed", func() { + ginkgo.Context("Set ExpireIn", func() { + ginkgo.It("should mark as swept when expire time is passed", func() { m := metrics.NewRawMetric("my_metric", "my-origin", &dto.Metric{ Label: transform.LabelsMapToLabelPairs(map[string]string{ "origin": "my-origin", }), }) m.ExpireIn(100 * time.Millisecond) - Expect(m.IsSwept()).To(BeFalse()) + gomega.Expect(m.IsSwept()).To(gomega.BeFalse()) time.Sleep(101 * time.Millisecond) - Expect(m.IsSwept()).To(BeTrue()) + gomega.Expect(m.IsSwept()).To(gomega.BeTrue()) }) }) - Context("Id", func() { - It("should generate an id based on metric labels", func() { + ginkgo.Context("Id", func() { + ginkgo.It("should generate an id based on metric labels", func() { m1 := metrics.NewRawMetric("my_metric", "my-origin", &dto.Metric{ Label: transform.LabelsMapToLabelPairs(map[string]string{ "origin": "my-origin", @@ -69,8 +69,8 @@ var _ = Describe("RawMetric", func() { }), }) - Expect(m1.ID()).To(Equal(m2.ID())) - Expect(m1.ID()).ToNot(Equal(m3.ID())) + gomega.Expect(m1.ID()).To(gomega.Equal(m2.ID())) + gomega.Expect(m1.ID()).ToNot(gomega.Equal(m3.ID())) }) }) }) diff --git a/nozzle/gauge_test.go b/nozzle/gauge_test.go index f3ddc502..7c8bd7c2 100644 --- a/nozzle/gauge_test.go +++ b/nozzle/gauge_test.go @@ -5,34 +5,34 @@ import ( "github.com/bosh-prometheus/firehose_exporter/metricmaker" "github.com/bosh-prometheus/firehose_exporter/metrics" - . "github.com/bosh-prometheus/firehose_exporter/nozzle" + "github.com/bosh-prometheus/firehose_exporter/nozzle" "github.com/bosh-prometheus/firehose_exporter/testing" "github.com/bosh-prometheus/firehose_exporter/transform" "github.com/gogo/protobuf/proto" dto "github.com/prometheus/client_model/go" "code.cloudfoundry.org/go-loggregator/v8/rpc/loggregator_v2" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) -var _ = Describe("Nozzle", func() { +var _ = ginkgo.Describe("Nozzle", func() { var pointBuffer chan []*metrics.RawMetric var metricStore *MetricStoreTesting - BeforeEach(func() { + ginkgo.BeforeEach(func() { pointBuffer = make(chan []*metrics.RawMetric) metricStore = NewMetricStoreTesting(pointBuffer) }) - Describe("when the envelope is a Gauge", func() { - It("converts the envelope to a Point(s)", func() { + ginkgo.Describe("when the envelope is a Gauge", func() { + ginkgo.It("converts the envelope to a Point(s)", func() { streamConnector := newSpyStreamConnector() - n := NewNozzle(streamConnector, "firehose_exporter", 0, + n := nozzle.NewNozzle(streamConnector, "firehose_exporter", 0, pointBuffer, internalMetric, - WithNozzleTimerRollup( + nozzle.WithNozzleTimerRollup( 100*time.Millisecond, []string{"tag1", "tag2", "status_code"}, []string{"tag1", "tag2"}, @@ -62,9 +62,9 @@ var _ = Describe("Nozzle", func() { }, } - Eventually(metricStore.GetPoints).Should(HaveLen(2)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(2)) - Expect(metricStore.GetPoints()).To(testing.ContainPoints([]*metrics.RawMetric{ + gomega.Expect(metricStore.GetPoints()).To(testing.ContainPoints([]*metrics.RawMetric{ metricmaker.NewRawMetricFromMetric("input", &dto.Metric{ Label: transform.LabelsMapToLabelPairs(map[string]string{ "unit": "mb/s", @@ -86,14 +86,14 @@ var _ = Describe("Nozzle", func() { })) }) - It("preserves units on tagged envelopes", func() { + ginkgo.It("preserves units on tagged envelopes", func() { streamConnector := newSpyStreamConnector() - n := NewNozzle(streamConnector, "firehose_exporter", 0, + n := nozzle.NewNozzle(streamConnector, "firehose_exporter", 0, pointBuffer, internalMetric, - WithNozzleTimerRollup( + nozzle.WithNozzleTimerRollup( 100*time.Millisecond, []string{"tag1", "tag2", "status_code"}, []string{"tag1", "tag2"}, @@ -125,9 +125,9 @@ var _ = Describe("Nozzle", func() { }, } - Eventually(metricStore.GetPoints).Should(HaveLen(2)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(2)) - Expect(metricStore.GetPoints()).To(testing.ContainPoints([]*metrics.RawMetric{ + gomega.Expect(metricStore.GetPoints()).To(testing.ContainPoints([]*metrics.RawMetric{ metricmaker.NewRawMetricFromMetric("gauge1", &dto.Metric{ Label: transform.LabelsMapToLabelPairs(map[string]string{ "unit": "unit1", diff --git a/nozzle/metrics_test.go b/nozzle/metrics_test.go index a5bcadc9..d428dde5 100644 --- a/nozzle/metrics_test.go +++ b/nozzle/metrics_test.go @@ -4,25 +4,25 @@ import ( "time" "github.com/bosh-prometheus/firehose_exporter/metrics" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" - . "github.com/bosh-prometheus/firehose_exporter/nozzle" + "github.com/bosh-prometheus/firehose_exporter/nozzle" ) -var _ = Describe("collect nozzle metrics", func() { +var _ = ginkgo.Describe("collect nozzle metrics", func() { var pointBuffer chan []*metrics.RawMetric var metricStore *MetricStoreTesting - BeforeEach(func() { + ginkgo.BeforeEach(func() { pointBuffer = make(chan []*metrics.RawMetric) metricStore = NewMetricStoreTesting(pointBuffer) }) - It("writes Ingress, Egress and Err metrics", func() { + ginkgo.It("writes Ingress, Egress and Err metrics", func() { streamConnector := newSpyStreamConnector() - n := NewNozzle(streamConnector, "firehose_exporter", 0, + n := nozzle.NewNozzle(streamConnector, "firehose_exporter", 0, pointBuffer, internalMetric, - WithNozzleTimerRollup( + nozzle.WithNozzleTimerRollup( 100*time.Millisecond, []string{"tag1", "tag2", "status_code"}, []string{"tag1", "tag2"}, @@ -33,16 +33,16 @@ var _ = Describe("collect nozzle metrics", func() { addEnvelope(1, "memory", "some-source-id", streamConnector) addEnvelope(2, "memory", "some-source-id", streamConnector) addEnvelope(3, "memory", "some-source-id", streamConnector) - Eventually(metricStore.GetPoints).Should(HaveLen(3)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(3)) }) - It("writes duration seconds histogram metrics", func() { + ginkgo.It("writes duration seconds histogram metrics", func() { streamConnector := newSpyStreamConnector() - n := NewNozzle(streamConnector, "firehose_exporter", 0, + n := nozzle.NewNozzle(streamConnector, "firehose_exporter", 0, pointBuffer, internalMetric, - WithNozzleTimerRollup( + nozzle.WithNozzleTimerRollup( 100*time.Millisecond, []string{"tag1", "tag2", "status_code"}, []string{"tag1", "tag2"}, diff --git a/nozzle/nozzle_suite_test.go b/nozzle/nozzle_suite_test.go index 701345ac..2f939250 100644 --- a/nozzle/nozzle_suite_test.go +++ b/nozzle/nozzle_suite_test.go @@ -10,17 +10,17 @@ import ( "code.cloudfoundry.org/go-loggregator/v8" "code.cloudfoundry.org/go-loggregator/v8/rpc/loggregator_v2" "github.com/bosh-prometheus/firehose_exporter/metrics" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) var internalMetric = metrics.NewInternalMetrics("firehose", "test") func TestNozzle(t *testing.T) { - log.SetOutput(GinkgoWriter) + log.SetOutput(ginkgo.GinkgoWriter) - RegisterFailHandler(Fail) - RunSpecs(t, "Nozzle Suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Nozzle Suite") } // nolint:unparam diff --git a/nozzle/nozzle_test.go b/nozzle/nozzle_test.go index bf65c413..bed4fbe9 100644 --- a/nozzle/nozzle_test.go +++ b/nozzle/nozzle_test.go @@ -9,59 +9,59 @@ import ( "github.com/bosh-prometheus/firehose_exporter/testing" "github.com/bosh-prometheus/firehose_exporter/transform" "github.com/gogo/protobuf/proto" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" dto "github.com/prometheus/client_model/go" - . "github.com/bosh-prometheus/firehose_exporter/nozzle" + "github.com/bosh-prometheus/firehose_exporter/nozzle" ) -var _ = Describe("Nozzle", func() { +var _ = ginkgo.Describe("Nozzle", func() { var ( streamConnector *spyStreamConnector - nozzle *Nozzle + noz *nozzle.Nozzle pointBuffer chan []*metrics.RawMetric metricStore *MetricStoreTesting - filterSelector *FilterSelector - filterDeployment *FilterDeployment + filterSelector *nozzle.FilterSelector + filterDeployment *nozzle.FilterDeployment ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { pointBuffer = make(chan []*metrics.RawMetric) metricStore = NewMetricStoreTesting(pointBuffer) - filterSelector = NewFilterSelector() - filterDeployment = NewFilterDeployment() + filterSelector = nozzle.NewFilterSelector() + filterDeployment = nozzle.NewFilterDeployment() streamConnector = newSpyStreamConnector() - nozzle = NewNozzle(streamConnector, "firehose_exporter", 0, + noz = nozzle.NewNozzle(streamConnector, "firehose_exporter", 0, pointBuffer, internalMetric, - WithNozzleTimerRollup( + nozzle.WithNozzleTimerRollup( 100*time.Millisecond, []string{"tag1", "tag2", "status_code"}, []string{"tag1", "tag2"}, ), - WithFilterSelector(filterSelector), - WithFilterDeployment(filterDeployment), + nozzle.WithFilterSelector(filterSelector), + nozzle.WithFilterDeployment(filterDeployment), ) }) - JustBeforeEach(func() { - go nozzle.Start() + ginkgo.JustBeforeEach(func() { + go noz.Start() }) - It("connects and reads from a logs provider server", func() { + ginkgo.It("connects and reads from a logs provider server", func() { addEnvelope(1, "memory", "some-source-id", streamConnector) addEnvelope(2, "memory", "some-source-id", streamConnector) addEnvelope(3, "memory", "some-source-id", streamConnector) - Eventually(streamConnector.requests).Should(HaveLen(1)) - Expect(streamConnector.requests()[0].ShardId).To(Equal("firehose_exporter")) - Expect(streamConnector.requests()[0].UsePreferredTags).To(BeTrue()) - Expect(streamConnector.requests()[0].Selectors).To(HaveLen(3)) + gomega.Eventually(streamConnector.requests).Should(gomega.HaveLen(1)) + gomega.Expect(streamConnector.requests()[0].ShardId).To(gomega.Equal("firehose_exporter")) + gomega.Expect(streamConnector.requests()[0].UsePreferredTags).To(gomega.BeTrue()) + gomega.Expect(streamConnector.requests()[0].Selectors).To(gomega.HaveLen(3)) - Expect(streamConnector.requests()[0].Selectors).To(ConsistOf( + gomega.Expect(streamConnector.requests()[0].Selectors).To(gomega.ConsistOf( []*loggregator_v2.Selector{ { Message: &loggregator_v2.Selector_Gauge{ @@ -81,16 +81,16 @@ var _ = Describe("Nozzle", func() { }, )) - Eventually(streamConnector.envelopes).Should(HaveLen(0)) + gomega.Eventually(streamConnector.envelopes).Should(gomega.HaveLen(0)) }) - It("writes each envelope as a point to the firehose_exporter", func() { + ginkgo.It("writes each envelope as a point to the firehose_exporter", func() { addEnvelope(1, "memory", "some-source-id", streamConnector) addEnvelope(2, "memory", "some-source-id", streamConnector) addEnvelope(3, "memory", "some-source-id", streamConnector) - Eventually(metricStore.GetPoints).Should(HaveLen(3)) - Expect(metricStore.GetPoints()).To(testing.ContainPoints([]*metrics.RawMetric{ + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(3)) + gomega.Expect(metricStore.GetPoints()).To(testing.ContainPoints([]*metrics.RawMetric{ metricmaker.NewRawMetricFromMetric("memory", &dto.Metric{ Label: transform.LabelsMapToLabelPairs(map[string]string{ "source_id": "some-source-id", @@ -118,8 +118,8 @@ var _ = Describe("Nozzle", func() { })) }) - Describe("when the envelope is a Counter", func() { - It("converts the envelope to a Point", func() { + ginkgo.Describe("when the envelope is a Counter", func() { + ginkgo.It("converts the envelope to a Point", func() { streamConnector.envelopes <- []*loggregator_v2.Envelope{ { Timestamp: 20, @@ -134,15 +134,15 @@ var _ = Describe("Nozzle", func() { }, } - Eventually(metricStore.GetPoints).Should(HaveLen(1)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(1)) point := metricStore.GetPoints()[0] - Expect(point.MetricName()).To(Equal("failures")) - Expect(point.Metric().Counter.GetValue()).To(Equal(float64(8))) - Expect(transform.LabelPairsToLabelsMap(point.Metric().Label)).To(HaveKeyWithValue("source_id", "source-id")) + gomega.Expect(point.MetricName()).To(gomega.Equal("failures")) + gomega.Expect(point.Metric().Counter.GetValue()).To(gomega.Equal(float64(8))) + gomega.Expect(transform.LabelPairsToLabelsMap(point.Metric().Label)).To(gomega.HaveKeyWithValue("source_id", "source-id")) }) }) - It("forwards all tags", func() { + ginkgo.It("forwards all tags", func() { streamConnector.envelopes <- []*loggregator_v2.Envelope{ { Timestamp: 20, @@ -160,9 +160,9 @@ var _ = Describe("Nozzle", func() { }, } - Eventually(metricStore.GetPoints).Should(HaveLen(1)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(1)) - Expect(metricStore.GetPoints()).To(testing.ContainPoint(metricmaker.NewRawMetricFromMetric("counter", &dto.Metric{ + gomega.Expect(metricStore.GetPoints()).To(testing.ContainPoint(metricmaker.NewRawMetricFromMetric("counter", &dto.Metric{ Label: transform.LabelsMapToLabelPairs(map[string]string{ "forwarded-tag-1": "forwarded value", "forwarded-tag-2": "forwarded value", @@ -174,8 +174,8 @@ var _ = Describe("Nozzle", func() { }))) }) - Context("filter selector", func() { - BeforeEach(func() { + ginkgo.Context("filter selector", func() { + ginkgo.BeforeEach(func() { filterSelector.DisableAll() streamConnector.envelopes <- []*loggregator_v2.Envelope{ { @@ -233,60 +233,60 @@ var _ = Describe("Nozzle", func() { }, } }) - Describe("when selector CounterEvent", func() { - BeforeEach(func() { - filterSelector.Filters(FilterSelectorTypeCounterEvent) + ginkgo.Describe("when selector CounterEvent", func() { + ginkgo.BeforeEach(func() { + filterSelector.Filters(nozzle.FilterSelectorTypeCounterEvent) }) - It("should only take counter metric", func() { - Eventually(metricStore.GetPoints).Should(HaveLen(1)) + ginkgo.It("should only take counter metric", func() { + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(1)) point := metricStore.GetPoints()[0] - Expect(point.MetricName()).To(Equal("failures")) - Expect(point.Metric().Counter.GetValue()).To(Equal(float64(8))) - Expect(transform.LabelPairsToLabelsMap(point.Metric().Label)).To(HaveKeyWithValue("source_id", "source-id")) + gomega.Expect(point.MetricName()).To(gomega.Equal("failures")) + gomega.Expect(point.Metric().Counter.GetValue()).To(gomega.Equal(float64(8))) + gomega.Expect(transform.LabelPairsToLabelsMap(point.Metric().Label)).To(gomega.HaveKeyWithValue("source_id", "source-id")) }) }) - Describe("when selector ContainerMetric", func() { - BeforeEach(func() { - filterSelector.Filters(FilterSelectorTypeContainerMetric) + ginkgo.Describe("when selector ContainerMetric", func() { + ginkgo.BeforeEach(func() { + filterSelector.Filters(nozzle.FilterSelectorTypeContainerMetric) }) - It("should only take container metric", func() { - Eventually(metricStore.GetPoints).Should(HaveLen(1)) + ginkgo.It("should only take container metric", func() { + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(1)) point := metricStore.GetPoints()[0] - Expect(point.MetricName()).To(Equal("cpu")) - Expect(point.Metric().Gauge.GetValue()).To(Equal(float64(1))) - Expect(transform.LabelPairsToLabelsMap(point.Metric().Label)).To(HaveKeyWithValue("source_id", "source-id")) + gomega.Expect(point.MetricName()).To(gomega.Equal("cpu")) + gomega.Expect(point.Metric().Gauge.GetValue()).To(gomega.Equal(float64(1))) + gomega.Expect(transform.LabelPairsToLabelsMap(point.Metric().Label)).To(gomega.HaveKeyWithValue("source_id", "source-id")) }) }) - Describe("when selector ValueMetric", func() { - BeforeEach(func() { - filterSelector.Filters(FilterSelectorTypeValueMetric) + ginkgo.Describe("when selector ValueMetric", func() { + ginkgo.BeforeEach(func() { + filterSelector.Filters(nozzle.FilterSelectorTypeValueMetric) }) - It("should only take gauge metric which is not container metric", func() { - Eventually(metricStore.GetPoints).Should(HaveLen(1)) + ginkgo.It("should only take gauge metric which is not container metric", func() { + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(1)) point := metricStore.GetPoints()[0] - Expect(point.MetricName()).To(Equal("a_gauge")) - Expect(point.Metric().Gauge.GetValue()).To(Equal(float64(1))) - Expect(transform.LabelPairsToLabelsMap(point.Metric().Label)).To(HaveKeyWithValue("source_id", "source-id")) + gomega.Expect(point.MetricName()).To(gomega.Equal("a_gauge")) + gomega.Expect(point.Metric().Gauge.GetValue()).To(gomega.Equal(float64(1))) + gomega.Expect(transform.LabelPairsToLabelsMap(point.Metric().Label)).To(gomega.HaveKeyWithValue("source_id", "source-id")) }) }) - Describe("when selector Http", func() { - BeforeEach(func() { - filterSelector.Filters(FilterSelectorTypeHTTPStartStop) + ginkgo.Describe("when selector Http", func() { + ginkgo.BeforeEach(func() { + filterSelector.Filters(nozzle.FilterSelectorTypeHTTPStartStop) }) - It("should only take timer metric", func() { - Eventually(metricStore.GetPoints).Should(HaveLen(2)) + ginkgo.It("should only take timer metric", func() { + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(2)) pointCounter := metricStore.GetPoints()[0] - Expect(pointCounter.MetricName()).To(Equal("http_total")) - Expect(pointCounter.Metric().Counter.GetValue()).To(Equal(float64(1))) + gomega.Expect(pointCounter.MetricName()).To(gomega.Equal("http_total")) + gomega.Expect(pointCounter.Metric().Counter.GetValue()).To(gomega.Equal(float64(1))) pointHisto := metricStore.GetPoints()[1] - Expect(pointHisto.MetricName()).To(Equal("http_duration_seconds")) - Expect(pointHisto.Metric().Histogram).ToNot(BeNil()) + gomega.Expect(pointHisto.MetricName()).To(gomega.Equal("http_duration_seconds")) + gomega.Expect(pointHisto.Metric().Histogram).ToNot(gomega.BeNil()) }) }) }) - Context("filter deployment", func() { - BeforeEach(func() { + ginkgo.Context("filter deployment", func() { + ginkgo.BeforeEach(func() { filterDeployment.SetDeployments("cf", "bosh") streamConnector.envelopes <- []*loggregator_v2.Envelope{ { @@ -339,17 +339,17 @@ var _ = Describe("Nozzle", func() { } }) - It("should only take metrics from these deployments", func() { - Eventually(metricStore.GetPoints).Should(HaveLen(2)) + ginkgo.It("should only take metrics from these deployments", func() { + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(2)) point1 := metricStore.GetPoints()[0] - Expect(point1.MetricName()).To(Equal("failures")) - Expect(point1.Metric().Counter.GetValue()).To(Equal(float64(8))) - Expect(transform.LabelPairsToLabelsMap(point1.Metric().Label)).To(HaveKeyWithValue("source_id", "source-id")) + gomega.Expect(point1.MetricName()).To(gomega.Equal("failures")) + gomega.Expect(point1.Metric().Counter.GetValue()).To(gomega.Equal(float64(8))) + gomega.Expect(transform.LabelPairsToLabelsMap(point1.Metric().Label)).To(gomega.HaveKeyWithValue("source_id", "source-id")) point2 := metricStore.GetPoints()[1] - Expect(point2.MetricName()).To(Equal("memory")) - Expect(point2.Metric().Gauge.GetValue()).To(Equal(float64(1))) - Expect(transform.LabelPairsToLabelsMap(point2.Metric().Label)).To(HaveKeyWithValue("source_id", "source-id")) + gomega.Expect(point2.MetricName()).To(gomega.Equal("memory")) + gomega.Expect(point2.Metric().Gauge.GetValue()).To(gomega.Equal(float64(1))) + gomega.Expect(transform.LabelPairsToLabelsMap(point2.Metric().Label)).To(gomega.HaveKeyWithValue("source_id", "source-id")) }) }) }) diff --git a/nozzle/rollup/counter_test.go b/nozzle/rollup/counter_test.go index b9f181b1..2f48715d 100644 --- a/nozzle/rollup/counter_test.go +++ b/nozzle/rollup/counter_test.go @@ -4,13 +4,13 @@ import ( "time" "github.com/bosh-prometheus/firehose_exporter/metrics" - . "github.com/bosh-prometheus/firehose_exporter/nozzle/rollup" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/bosh-prometheus/firehose_exporter/nozzle/rollup" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) -var _ = Describe("Counter Rollup", func() { - extract := func(batches []*PointsBatch) []*metrics.RawMetric { +var _ = ginkgo.Describe("Counter Rollup", func() { + extract := func(batches []*rollup.PointsBatch) []*metrics.RawMetric { var points []*metrics.RawMetric for _, b := range batches { points = append(points, b.Points...) @@ -18,8 +18,8 @@ var _ = Describe("Counter Rollup", func() { return points } - It("returns counters for rolled up events", func() { - counterRollup := NewCounterRollup( + ginkgo.It("returns counters for rolled up events", func() { + counterRollup := rollup.NewCounterRollup( "0", nil, ) @@ -31,12 +31,12 @@ var _ = Describe("Counter Rollup", func() { ) points := extract(counterRollup.Rollup(0)) - Expect(len(points)).To(Equal(1)) - Expect(*points[0].Metric().Counter.Value).To(BeNumerically("==", 1)) + gomega.Expect(len(points)).To(gomega.Equal(1)) + gomega.Expect(*points[0].Metric().Counter.Value).To(gomega.BeNumerically("==", 1)) }) - It("returns points that track a running total of rolled up events", func() { - counterRollup := NewCounterRollup( + ginkgo.It("returns points that track a running total of rolled up events", func() { + counterRollup := rollup.NewCounterRollup( "0", []string{"included-tag"}, ) @@ -48,8 +48,8 @@ var _ = Describe("Counter Rollup", func() { ) points := extract(counterRollup.Rollup(0)) - Expect(len(points)).To(Equal(1)) - Expect(*points[0].Metric().Counter.Value).To(BeNumerically("==", 1)) + gomega.Expect(len(points)).To(gomega.Equal(1)) + gomega.Expect(*points[0].Metric().Counter.Value).To(gomega.BeNumerically("==", 1)) counterRollup.Record( "source-id", @@ -58,12 +58,12 @@ var _ = Describe("Counter Rollup", func() { ) points = extract(counterRollup.Rollup(1)) - Expect(len(points)).To(Equal(1)) - Expect(*points[0].Metric().Counter.Value).To(BeNumerically("==", float64(2))) + gomega.Expect(len(points)).To(gomega.Equal(1)) + gomega.Expect(*points[0].Metric().Counter.Value).To(gomega.BeNumerically("==", float64(2))) }) - It("returns separate counters for distinct source IDs", func() { - counterRollup := NewCounterRollup( + ginkgo.It("returns separate counters for distinct source IDs", func() { + counterRollup := rollup.NewCounterRollup( "0", []string{"included-tag"}, ) @@ -80,11 +80,11 @@ var _ = Describe("Counter Rollup", func() { ) points := extract(counterRollup.Rollup(0)) - Expect(len(points)).To(Equal(2)) + gomega.Expect(len(points)).To(gomega.Equal(2)) }) - It("returns separate counters for different included tags", func() { - counterRollup := NewCounterRollup( + ginkgo.It("returns separate counters for different included tags", func() { + counterRollup := rollup.NewCounterRollup( "0", []string{"included-tag"}, ) @@ -101,13 +101,13 @@ var _ = Describe("Counter Rollup", func() { ) points := extract(counterRollup.Rollup(0)) - Expect(len(points)).To(Equal(2)) - Expect(*points[0].Metric().Counter.Value).To(BeNumerically("==", 1)) - Expect(*points[1].Metric().Counter.Value).To(BeNumerically("==", 1)) + gomega.Expect(len(points)).To(gomega.Equal(2)) + gomega.Expect(*points[0].Metric().Counter.Value).To(gomega.BeNumerically("==", 1)) + gomega.Expect(*points[1].Metric().Counter.Value).To(gomega.BeNumerically("==", 1)) }) - It("does not return separate counters for different excluded tags", func() { - counterRollup := NewCounterRollup( + ginkgo.It("does not return separate counters for different excluded tags", func() { + counterRollup := rollup.NewCounterRollup( "0", []string{"included-tag"}, ) @@ -124,16 +124,16 @@ var _ = Describe("Counter Rollup", func() { ) points := extract(counterRollup.Rollup(0)) - Expect(len(points)).To(Equal(1)) - Expect(*points[0].Metric().Counter.Value).To(BeNumerically("==", float64(2))) + gomega.Expect(len(points)).To(gomega.Equal(1)) + gomega.Expect(*points[0].Metric().Counter.Value).To(gomega.BeNumerically("==", float64(2))) }) - Context("CleanPeriodic", func() { - It("should clean metrics after amount of time", func() { - counterRollup := NewCounterRollup( + ginkgo.Context("CleanPeriodic", func() { + ginkgo.It("should clean metrics after amount of time", func() { + counterRollup := rollup.NewCounterRollup( "0", nil, - SetCounterCleaning(10*time.Millisecond, 50*time.Millisecond), + rollup.SetCounterCleaning(10*time.Millisecond, 50*time.Millisecond), ) counterRollup.Record( @@ -143,7 +143,7 @@ var _ = Describe("Counter Rollup", func() { ) time.Sleep(100 * time.Millisecond) points := extract(counterRollup.Rollup(0)) - Expect(len(points)).To(Equal(0)) + gomega.Expect(len(points)).To(gomega.Equal(0)) }) }) }) diff --git a/nozzle/rollup/histogram_test.go b/nozzle/rollup/histogram_test.go index c7fc1173..60bd7c3d 100644 --- a/nozzle/rollup/histogram_test.go +++ b/nozzle/rollup/histogram_test.go @@ -5,12 +5,12 @@ import ( "time" "github.com/bosh-prometheus/firehose_exporter/metrics" - . "github.com/bosh-prometheus/firehose_exporter/nozzle/rollup" + "github.com/bosh-prometheus/firehose_exporter/nozzle/rollup" "github.com/bosh-prometheus/firehose_exporter/transform" dto "github.com/prometheus/client_model/go" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) const ( @@ -27,7 +27,7 @@ func (h *histogram) Count() int { return int(*p.Metric().Histogram.SampleCount) } } - Fail("No count point found in histogram") + ginkgo.Fail("No count point found in histogram") return 0 } @@ -37,7 +37,7 @@ func (h *histogram) Sum() int { return int(*p.Metric().Histogram.SampleSum) } } - Fail("No sum point found in histogram") + ginkgo.Fail("No sum point found in histogram") return 0 } @@ -56,12 +56,12 @@ func (h *histogram) Bucket(le string) *dto.Histogram { } } } - Fail(fmt.Sprintf("No bucket point found in histogram for le = '%s'", le)) + ginkgo.Fail(fmt.Sprintf("No bucket point found in histogram for le = '%s'", le)) return nil } -var _ = Describe("Histogram Rollup", func() { - extract := func(batches []*PointsBatch) []*histogram { +var _ = ginkgo.Describe("Histogram Rollup", func() { + extract := func(batches []*rollup.PointsBatch) []*histogram { var histograms []*histogram for _, b := range batches { @@ -73,8 +73,8 @@ var _ = Describe("Histogram Rollup", func() { return histograms } - It("returns aggregate information for rolled up events", func() { - rollup := NewHistogramRollup( + ginkgo.It("returns aggregate information for rolled up events", func() { + rollup := rollup.NewHistogramRollup( "0", nil, ) @@ -91,13 +91,13 @@ var _ = Describe("Histogram Rollup", func() { ) histograms := extract(rollup.Rollup(0)) - Expect(len(histograms)).To(Equal(1)) - Expect(histograms[0].Count()).To(Equal(2)) - Expect(histograms[0].Sum()).To(Equal(15)) + gomega.Expect(len(histograms)).To(gomega.Equal(1)) + gomega.Expect(histograms[0].Count()).To(gomega.Equal(2)) + gomega.Expect(histograms[0].Sum()).To(gomega.Equal(15)) }) - It("returns batches which each includes a size estimate", func() { - rollup := NewHistogramRollup( + ginkgo.It("returns batches which each includes a size estimate", func() { + rollup := rollup.NewHistogramRollup( "0", nil, ) @@ -109,12 +109,12 @@ var _ = Describe("Histogram Rollup", func() { ) pointsBatches := rollup.Rollup(0) - Expect(len(pointsBatches)).To(Equal(1)) - Expect(pointsBatches[0].Size).To(BeNumerically(">", 0)) + gomega.Expect(len(pointsBatches)).To(gomega.Equal(1)) + gomega.Expect(pointsBatches[0].Size).To(gomega.BeNumerically(">", 0)) }) - It("returns points for each bucket in the histogram", func() { - rollup := NewHistogramRollup( + ginkgo.It("returns points for each bucket in the histogram", func() { + rollup := rollup.NewHistogramRollup( "0", nil, ) @@ -136,11 +136,11 @@ var _ = Describe("Histogram Rollup", func() { ) histograms := extract(rollup.Rollup(0)) - Expect(len(histograms)).To(Equal(1)) + gomega.Expect(len(histograms)).To(gomega.Equal(1)) }) - It("returns points with the timestamp given to Rollup", func() { - rollup := NewHistogramRollup( + ginkgo.It("returns points with the timestamp given to Rollup", func() { + rollup := rollup.NewHistogramRollup( "node-index", nil, ) @@ -152,11 +152,11 @@ var _ = Describe("Histogram Rollup", func() { ) histograms := extract(rollup.Rollup(88)) - Expect(len(histograms)).To(Equal(1)) + gomega.Expect(len(histograms)).To(gomega.Equal(1)) }) - It("returns histograms with labels based on tags", func() { - rollup := NewHistogramRollup( + ginkgo.It("returns histograms with labels based on tags", func() { + rollup := rollup.NewHistogramRollup( "node-index", []string{"included-tag"}, ) @@ -168,18 +168,18 @@ var _ = Describe("Histogram Rollup", func() { ) histograms := extract(rollup.Rollup(0)) - Expect(len(histograms)).To(Equal(1)) + gomega.Expect(len(histograms)).To(gomega.Equal(1)) for _, p := range histograms[0].Points() { - Expect(transform.LabelPairsToLabelsMap(p.Metric().Label)).To(And( - HaveKeyWithValue("included_tag", "foo"), - HaveKeyWithValue("source_id", "source-id"), - HaveKeyWithValue("node_index", "node-index"), + gomega.Expect(transform.LabelPairsToLabelsMap(p.Metric().Label)).To(gomega.And( + gomega.HaveKeyWithValue("included_tag", "foo"), + gomega.HaveKeyWithValue("source_id", "source-id"), + gomega.HaveKeyWithValue("node_index", "node-index"), )) } }) - It("returns points that track a running total of rolled up events", func() { - rollup := NewHistogramRollup( + ginkgo.It("returns points that track a running total of rolled up events", func() { + rollup := rollup.NewHistogramRollup( "0", []string{"included-tag"}, ) @@ -191,8 +191,8 @@ var _ = Describe("Histogram Rollup", func() { ) histograms := extract(rollup.Rollup(0)) - Expect(len(histograms)).To(Equal(1)) - Expect(histograms[0].Count()).To(Equal(1)) + gomega.Expect(len(histograms)).To(gomega.Equal(1)) + gomega.Expect(histograms[0].Count()).To(gomega.Equal(1)) rollup.Record( "source-id", @@ -201,12 +201,12 @@ var _ = Describe("Histogram Rollup", func() { ) histograms = extract(rollup.Rollup(1)) - Expect(len(histograms)).To(Equal(1)) - Expect(histograms[0].Count()).To(Equal(2)) + gomega.Expect(len(histograms)).To(gomega.Equal(1)) + gomega.Expect(histograms[0].Count()).To(gomega.Equal(2)) }) - It("returns separate histograms for distinct source IDs", func() { - rollup := NewHistogramRollup( + ginkgo.It("returns separate histograms for distinct source IDs", func() { + rollup := rollup.NewHistogramRollup( "0", []string{"included-tag"}, ) @@ -223,13 +223,13 @@ var _ = Describe("Histogram Rollup", func() { ) histograms := extract(rollup.Rollup(0)) - Expect(len(histograms)).To(Equal(2)) - Expect(histograms[0].Count()).To(Equal(1)) - Expect(histograms[1].Count()).To(Equal(1)) + gomega.Expect(len(histograms)).To(gomega.Equal(2)) + gomega.Expect(histograms[0].Count()).To(gomega.Equal(1)) + gomega.Expect(histograms[1].Count()).To(gomega.Equal(1)) }) - It("returns separate histograms for different included tags", func() { - rollup := NewHistogramRollup( + ginkgo.It("returns separate histograms for different included tags", func() { + rollup := rollup.NewHistogramRollup( "0", []string{"included-tag"}, ) @@ -246,13 +246,13 @@ var _ = Describe("Histogram Rollup", func() { ) histograms := extract(rollup.Rollup(0)) - Expect(len(histograms)).To(Equal(2)) - Expect(histograms[0].Count()).To(Equal(1)) - Expect(histograms[1].Count()).To(Equal(1)) + gomega.Expect(len(histograms)).To(gomega.Equal(2)) + gomega.Expect(histograms[0].Count()).To(gomega.Equal(1)) + gomega.Expect(histograms[1].Count()).To(gomega.Equal(1)) }) - It("does not return separate histograms for different excluded tags", func() { - rollup := NewHistogramRollup( + ginkgo.It("does not return separate histograms for different excluded tags", func() { + rollup := rollup.NewHistogramRollup( "0", []string{"included-tag"}, ) @@ -269,18 +269,18 @@ var _ = Describe("Histogram Rollup", func() { ) histograms := extract(rollup.Rollup(0)) - Expect(len(histograms)).To(Equal(1)) - Expect(histograms[0].Count()).To(Equal(2)) - Expect(transform.LabelPairsToLabelsMap(histograms[0].Points()[0].Metric().Label)).ToNot(HaveKey("excluded-tag")) + gomega.Expect(len(histograms)).To(gomega.Equal(1)) + gomega.Expect(histograms[0].Count()).To(gomega.Equal(2)) + gomega.Expect(transform.LabelPairsToLabelsMap(histograms[0].Points()[0].Metric().Label)).ToNot(gomega.HaveKey("excluded-tag")) }) - Context("CleanPeriodic", func() { + ginkgo.Context("CleanPeriodic", func() { - It("should clean metrics after amount of time", func() { - rollup := NewHistogramRollup( + ginkgo.It("should clean metrics after amount of time", func() { + rollup := rollup.NewHistogramRollup( "0", nil, - SetHistogramCleaning(10*time.Millisecond, 50*time.Millisecond), + rollup.SetHistogramCleaning(10*time.Millisecond, 50*time.Millisecond), ) rollup.Record( "source-id", @@ -289,7 +289,7 @@ var _ = Describe("Histogram Rollup", func() { ) time.Sleep(100 * time.Millisecond) histograms := extract(rollup.Rollup(0)) - Expect(len(histograms)).To(Equal(0)) + gomega.Expect(len(histograms)).To(gomega.Equal(0)) }) }) }) diff --git a/nozzle/rollup/rollup_suite_test.go b/nozzle/rollup/rollup_suite_test.go index e39d80f2..a265776b 100644 --- a/nozzle/rollup/rollup_suite_test.go +++ b/nozzle/rollup/rollup_suite_test.go @@ -3,11 +3,11 @@ package rollup_test import ( "testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) func TestRollup(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Rollup Suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Rollup Suite") } diff --git a/nozzle/rollup/summary_test.go b/nozzle/rollup/summary_test.go index 49be9bb8..ede343e1 100644 --- a/nozzle/rollup/summary_test.go +++ b/nozzle/rollup/summary_test.go @@ -5,12 +5,12 @@ import ( "time" "github.com/bosh-prometheus/firehose_exporter/metrics" - . "github.com/bosh-prometheus/firehose_exporter/nozzle/rollup" + "github.com/bosh-prometheus/firehose_exporter/nozzle/rollup" "github.com/bosh-prometheus/firehose_exporter/transform" dto "github.com/prometheus/client_model/go" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" ) const ( @@ -27,7 +27,7 @@ func (h *summary) Count() int { return int(*p.Metric().Summary.SampleCount) } } - Fail("No count point found in summary") + ginkgo.Fail("No count point found in summary") return 0 } @@ -37,7 +37,7 @@ func (h *summary) Sum() int { return int(*p.Metric().Summary.SampleSum) } } - Fail("No sum point found in summary") + ginkgo.Fail("No sum point found in summary") return 0 } @@ -56,12 +56,12 @@ func (h *summary) Bucket(le string) *dto.Summary { } } } - Fail(fmt.Sprintf("No bucket point found in summary for le = '%s'", le)) + ginkgo.Fail(fmt.Sprintf("No bucket point found in summary for le = '%s'", le)) return nil } -var _ = Describe("summary Rollup", func() { - extract := func(batches []*PointsBatch) []*summary { +var _ = ginkgo.Describe("summary Rollup", func() { + extract := func(batches []*rollup.PointsBatch) []*summary { var summaries []*summary for _, b := range batches { @@ -73,8 +73,8 @@ var _ = Describe("summary Rollup", func() { return summaries } - It("returns aggregate information for rolled up events", func() { - rollup := NewSummaryRollup( + ginkgo.It("returns aggregate information for rolled up events", func() { + rollup := rollup.NewSummaryRollup( "0", nil, ) @@ -91,13 +91,13 @@ var _ = Describe("summary Rollup", func() { ) summaries := extract(rollup.Rollup(0)) - Expect(len(summaries)).To(Equal(1)) - Expect(summaries[0].Count()).To(Equal(2)) - Expect(summaries[0].Sum()).To(Equal(15)) + gomega.Expect(len(summaries)).To(gomega.Equal(1)) + gomega.Expect(summaries[0].Count()).To(gomega.Equal(2)) + gomega.Expect(summaries[0].Sum()).To(gomega.Equal(15)) }) - It("returns batches which each includes a size estimate", func() { - rollup := NewSummaryRollup( + ginkgo.It("returns batches which each includes a size estimate", func() { + rollup := rollup.NewSummaryRollup( "0", nil, ) @@ -109,12 +109,12 @@ var _ = Describe("summary Rollup", func() { ) pointsBatches := rollup.Rollup(0) - Expect(len(pointsBatches)).To(Equal(1)) - Expect(pointsBatches[0].Size).To(BeNumerically(">", 0)) + gomega.Expect(len(pointsBatches)).To(gomega.Equal(1)) + gomega.Expect(pointsBatches[0].Size).To(gomega.BeNumerically(">", 0)) }) - It("returns points for each bucket in the summary", func() { - rollup := NewSummaryRollup( + ginkgo.It("returns points for each bucket in the summary", func() { + rollup := rollup.NewSummaryRollup( "0", nil, ) @@ -136,11 +136,11 @@ var _ = Describe("summary Rollup", func() { ) summaries := extract(rollup.Rollup(0)) - Expect(len(summaries)).To(Equal(1)) + gomega.Expect(len(summaries)).To(gomega.Equal(1)) }) - It("returns points with the timestamp given to Rollup", func() { - rollup := NewSummaryRollup( + ginkgo.It("returns points with the timestamp given to Rollup", func() { + rollup := rollup.NewSummaryRollup( "node-index", nil, ) @@ -152,11 +152,11 @@ var _ = Describe("summary Rollup", func() { ) summaries := extract(rollup.Rollup(88)) - Expect(len(summaries)).To(Equal(1)) + gomega.Expect(len(summaries)).To(gomega.Equal(1)) }) - It("returns summaries with labels based on tags", func() { - rollup := NewSummaryRollup( + ginkgo.It("returns summaries with labels based on tags", func() { + rollup := rollup.NewSummaryRollup( "node-index", []string{"included-tag"}, ) @@ -168,18 +168,18 @@ var _ = Describe("summary Rollup", func() { ) summaries := extract(rollup.Rollup(0)) - Expect(len(summaries)).To(Equal(1)) + gomega.Expect(len(summaries)).To(gomega.Equal(1)) for _, p := range summaries[0].Points() { - Expect(transform.LabelPairsToLabelsMap(p.Metric().Label)).To(And( - HaveKeyWithValue("included_tag", "foo"), - HaveKeyWithValue("source_id", "source-id"), - HaveKeyWithValue("node_index", "node-index"), + gomega.Expect(transform.LabelPairsToLabelsMap(p.Metric().Label)).To(gomega.And( + gomega.HaveKeyWithValue("included_tag", "foo"), + gomega.HaveKeyWithValue("source_id", "source-id"), + gomega.HaveKeyWithValue("node_index", "node-index"), )) } }) - It("returns points that track a running total of rolled up events", func() { - rollup := NewSummaryRollup( + ginkgo.It("returns points that track a running total of rolled up events", func() { + rollup := rollup.NewSummaryRollup( "0", []string{"included-tag"}, ) @@ -191,8 +191,8 @@ var _ = Describe("summary Rollup", func() { ) summaries := extract(rollup.Rollup(0)) - Expect(len(summaries)).To(Equal(1)) - Expect(summaries[0].Count()).To(Equal(1)) + gomega.Expect(len(summaries)).To(gomega.Equal(1)) + gomega.Expect(summaries[0].Count()).To(gomega.Equal(1)) rollup.Record( "source-id", @@ -201,12 +201,12 @@ var _ = Describe("summary Rollup", func() { ) summaries = extract(rollup.Rollup(1)) - Expect(len(summaries)).To(Equal(1)) - Expect(summaries[0].Count()).To(Equal(2)) + gomega.Expect(len(summaries)).To(gomega.Equal(1)) + gomega.Expect(summaries[0].Count()).To(gomega.Equal(2)) }) - It("returns separate summaries for distinct source IDs", func() { - rollup := NewSummaryRollup( + ginkgo.It("returns separate summaries for distinct source IDs", func() { + rollup := rollup.NewSummaryRollup( "0", []string{"included-tag"}, ) @@ -223,13 +223,13 @@ var _ = Describe("summary Rollup", func() { ) summaries := extract(rollup.Rollup(0)) - Expect(len(summaries)).To(Equal(2)) - Expect(summaries[0].Count()).To(Equal(1)) - Expect(summaries[1].Count()).To(Equal(1)) + gomega.Expect(len(summaries)).To(gomega.Equal(2)) + gomega.Expect(summaries[0].Count()).To(gomega.Equal(1)) + gomega.Expect(summaries[1].Count()).To(gomega.Equal(1)) }) - It("returns separate summaries for different included tags", func() { - rollup := NewSummaryRollup( + ginkgo.It("returns separate summaries for different included tags", func() { + rollup := rollup.NewSummaryRollup( "0", []string{"included-tag"}, ) @@ -246,13 +246,13 @@ var _ = Describe("summary Rollup", func() { ) summaries := extract(rollup.Rollup(0)) - Expect(len(summaries)).To(Equal(2)) - Expect(summaries[0].Count()).To(Equal(1)) - Expect(summaries[1].Count()).To(Equal(1)) + gomega.Expect(len(summaries)).To(gomega.Equal(2)) + gomega.Expect(summaries[0].Count()).To(gomega.Equal(1)) + gomega.Expect(summaries[1].Count()).To(gomega.Equal(1)) }) - It("does not return separate summaries for different excluded tags", func() { - rollup := NewSummaryRollup( + ginkgo.It("does not return separate summaries for different excluded tags", func() { + rollup := rollup.NewSummaryRollup( "0", []string{"included-tag"}, ) @@ -269,17 +269,17 @@ var _ = Describe("summary Rollup", func() { ) summaries := extract(rollup.Rollup(0)) - Expect(len(summaries)).To(Equal(1)) - Expect(summaries[0].Count()).To(Equal(2)) - Expect(transform.LabelPairsToLabelsMap(summaries[0].Points()[0].Metric().Label)).ToNot(HaveKey("excluded-tag")) + gomega.Expect(len(summaries)).To(gomega.Equal(1)) + gomega.Expect(summaries[0].Count()).To(gomega.Equal(2)) + gomega.Expect(transform.LabelPairsToLabelsMap(summaries[0].Points()[0].Metric().Label)).ToNot(gomega.HaveKey("excluded-tag")) }) - Context("CleanPeriodic", func() { - It("should clean metrics after amount of time", func() { - rollup := NewSummaryRollup( + ginkgo.Context("CleanPeriodic", func() { + ginkgo.It("should clean metrics after amount of time", func() { + rollup := rollup.NewSummaryRollup( "0", nil, - SetSummaryCleaning(10*time.Millisecond, 50*time.Millisecond), + rollup.SetSummaryCleaning(10*time.Millisecond, 50*time.Millisecond), ) rollup.Record( @@ -296,7 +296,7 @@ var _ = Describe("summary Rollup", func() { time.Sleep(100 * time.Millisecond) summaries := extract(rollup.Rollup(0)) - Expect(len(summaries)).To(Equal(0)) + gomega.Expect(len(summaries)).To(gomega.Equal(0)) }) }) }) diff --git a/nozzle/timer_test.go b/nozzle/timer_test.go index e8ef14b5..dbaaa0ae 100644 --- a/nozzle/timer_test.go +++ b/nozzle/timer_test.go @@ -5,52 +5,52 @@ import ( "github.com/bosh-prometheus/firehose_exporter/metricmaker" "github.com/bosh-prometheus/firehose_exporter/metrics" - . "github.com/bosh-prometheus/firehose_exporter/nozzle" + "github.com/bosh-prometheus/firehose_exporter/nozzle" "github.com/bosh-prometheus/firehose_exporter/transform" "github.com/gogo/protobuf/proto" dto "github.com/prometheus/client_model/go" "code.cloudfoundry.org/go-loggregator/v8/rpc/loggregator_v2" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" - . "github.com/bosh-prometheus/firehose_exporter/testing" + "github.com/bosh-prometheus/firehose_exporter/testing" ) -var _ = Describe("when the envelope is a Timer", func() { +var _ = ginkgo.Describe("when the envelope is a Timer", func() { var ( streamConnector *spyStreamConnector - nozzle *Nozzle + noz *nozzle.Nozzle pointBuffer chan []*metrics.RawMetric metricStore *MetricStoreTesting - filterSelector *FilterSelector - filterDeployment *FilterDeployment + filterSelector *nozzle.FilterSelector + filterDeployment *nozzle.FilterDeployment ) - BeforeEach(func() { + ginkgo.BeforeEach(func() { pointBuffer = make(chan []*metrics.RawMetric) metricStore = NewMetricStoreTesting(pointBuffer) - filterSelector = NewFilterSelector() - filterDeployment = NewFilterDeployment() + filterSelector = nozzle.NewFilterSelector() + filterDeployment = nozzle.NewFilterDeployment() streamConnector = newSpyStreamConnector() - nozzle = NewNozzle(streamConnector, "firehose_exporter", 0, + noz = nozzle.NewNozzle(streamConnector, "firehose_exporter", 0, pointBuffer, internalMetric, - WithNozzleTimerRollup( + nozzle.WithNozzleTimerRollup( 100*time.Millisecond, []string{"tag1", "tag2", "status_code", "app_id"}, []string{"tag1", "tag2", "app_id"}, ), - WithFilterSelector(filterSelector), - WithFilterDeployment(filterDeployment), + nozzle.WithFilterSelector(filterSelector), + nozzle.WithFilterDeployment(filterDeployment), ) }) - JustBeforeEach(func() { - go nozzle.Start() + ginkgo.JustBeforeEach(func() { + go noz.Start() }) - It("rolls up configured metrics", func() { + ginkgo.It("rolls up configured metrics", func() { intervalStart := time.Now().Truncate(100 * time.Millisecond).UnixNano() @@ -137,12 +137,12 @@ var _ = Describe("when the envelope is a Timer", func() { numberOfExpectedSeriesIncludingStatusCode := 4 numberOfExpectedSeriesExcludingStatusCode := 2 numberOfExpectedPoints := numberOfExpectedSeriesIncludingStatusCode + numberOfExpectedSeriesExcludingStatusCode - Eventually(metricStore.GetPoints).Should(HaveLen(numberOfExpectedPoints)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(numberOfExpectedPoints)) points := metricStore.GetPoints() // _count points, per series including status_code - Expect(points).To(ContainPoints([]*metrics.RawMetric{ + gomega.Expect(points).To(testing.ContainPoints([]*metrics.RawMetric{ metricmaker.NewRawMetricCounter("http_total", map[string]string{ "node_index": "0", "source_id": "source-id", @@ -172,7 +172,7 @@ var _ = Describe("when the envelope is a Timer", func() { // _duration_seconds histogram points, per series excluding status_code // only testing one series - Expect(points).To(ContainPoints([]*metrics.RawMetric{ + gomega.Expect(points).To(testing.ContainPoints([]*metrics.RawMetric{ metricmaker.NewRawMetricFromMetric("http_duration_seconds", createHistogramMetric( map[string]string{ @@ -200,11 +200,11 @@ var _ = Describe("when the envelope is a Timer", func() { firstPointTimestamp := points[0].Metric().GetTimestampMs() firstPointTime := time.Unix(firstPointTimestamp/1000, 0) - Expect(firstPointTime).To(BeTemporally("~", time.Unix(0, intervalStart), time.Second)) - Expect(firstPointTime).To(Equal(firstPointTime.Truncate(100 * time.Millisecond))) + gomega.Expect(firstPointTime).To(gomega.BeTemporally("~", time.Unix(0, intervalStart), time.Second)) + gomega.Expect(firstPointTime).To(gomega.Equal(firstPointTime.Truncate(100 * time.Millisecond))) }) - It("only rolls up gorouter metrics with a peer_type of Server", func() { + ginkgo.It("only rolls up gorouter metrics with a peer_type of Server", func() { intervalStart := time.Now().Truncate(100 * time.Millisecond).UnixNano() streamConnector.envelopes <- []*loggregator_v2.Envelope{ @@ -303,11 +303,11 @@ var _ = Describe("when the envelope is a Timer", func() { numberOfExpectedSeriesIncludingStatusCode := 2 numberOfExpectedSeriesExcludingStatusCode := 1 numberOfExpectedPoints := numberOfExpectedSeriesIncludingStatusCode + numberOfExpectedSeriesExcludingStatusCode - Eventually(metricStore.GetPoints).Should(HaveLen(numberOfExpectedPoints)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(numberOfExpectedPoints)) points := metricStore.GetPoints() // _count points, per series including status_code - Expect(points).To(ContainPoints([]*metrics.RawMetric{ + gomega.Expect(points).To(testing.ContainPoints([]*metrics.RawMetric{ metricmaker.NewRawMetricCounter("http_total", map[string]string{ "node_index": "0", "source_id": "gorouter", @@ -323,7 +323,7 @@ var _ = Describe("when the envelope is a Timer", func() { // _duration_seconds histogram points, per series excluding status_code // only testing one series - Expect(points).To(ContainPoints([]*metrics.RawMetric{ + gomega.Expect(points).To(testing.ContainPoints([]*metrics.RawMetric{ metricmaker.NewRawMetricFromMetric("http_duration_seconds", createHistogramMetric( map[string]string{ @@ -349,12 +349,12 @@ var _ = Describe("when the envelope is a Timer", func() { firstPointTimestamp := points[0].Metric().GetTimestampMs() firstPointTime := time.Unix(firstPointTimestamp/1000, 0) - Expect(firstPointTime).To(BeTemporally("~", time.Unix(0, intervalStart), time.Second)) - Expect(firstPointTime).To(Equal(firstPointTime.Truncate(100 * time.Millisecond))) + gomega.Expect(firstPointTime).To(gomega.BeTemporally("~", time.Unix(0, intervalStart), time.Second)) + gomega.Expect(firstPointTime).To(gomega.Equal(firstPointTime.Truncate(100 * time.Millisecond))) }) - It("ignores other metrics", func() { + ginkgo.It("ignores other metrics", func() { streamConnector.envelopes <- []*loggregator_v2.Envelope{ { @@ -381,16 +381,16 @@ var _ = Describe("when the envelope is a Timer", func() { }, } - Eventually(metricStore.GetPoints).Should(HaveLen(1)) - Consistently(metricStore.GetPoints, .5).Should(HaveLen(1)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(1)) + gomega.Consistently(metricStore.GetPoints, .5).Should(gomega.HaveLen(1)) m := metricmaker.NewRawMetricCounter("http", map[string]string{ "source_id": "source-id", }, 4.0) m.Metric().TimestampMs = proto.Int64(66606660666066601) - Expect(metricStore.GetPoints()).To(ContainPoint(m)) + gomega.Expect(metricStore.GetPoints()).To(testing.ContainPoint(m)) }) - It("keeps a total across rollupIntervals", func() { + ginkgo.It("keeps a total across rollupIntervals", func() { baseTimer := loggregator_v2.Envelope{ SourceId: "source-id", @@ -418,11 +418,11 @@ var _ = Describe("when the envelope is a Timer", func() { streamConnector.envelopes <- []*loggregator_v2.Envelope{&firstTimer} - Eventually(metricStore.GetPoints).Should(HaveLen(2)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(2)) streamConnector.envelopes <- []*loggregator_v2.Envelope{&secondTimer, &thirdTimer} - Eventually(metricStore.GetPoints).Should(HaveLen(4)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(4)) secondIntervalHistogram := metricmaker.NewRawMetricFromMetric("http_duration_seconds", createHistogramMetric( @@ -454,13 +454,13 @@ var _ = Describe("when the envelope is a Timer", func() { "tag2": "t2", }, 3.0) - Expect(metricStore.GetPoints()).To(ContainPoints([]*metrics.RawMetric{ + gomega.Expect(metricStore.GetPoints()).To(testing.ContainPoints([]*metrics.RawMetric{ secondIntervalHistogram, secondIntervalTotal, })) }) - It("skip metric with a source id in form of app guid", func() { + ginkgo.It("skip metric with a source id in form of app guid", func() { intervalStart := time.Now().Truncate(100 * time.Millisecond).UnixNano() streamConnector.envelopes <- []*loggregator_v2.Envelope{ @@ -498,11 +498,11 @@ var _ = Describe("when the envelope is a Timer", func() { }, }, } - Eventually(metricStore.GetPoints).Should(HaveLen(2)) + gomega.Eventually(metricStore.GetPoints).Should(gomega.HaveLen(2)) labelsFirst := transform.LabelPairsToLabelsMap(metricStore.GetPoints()[0].Metric().GetLabel()) - Expect(labelsFirst).Should(HaveKeyWithValue("app_id", "6f0b4a14-0703-442c-bc80-bea78d31d5ab")) + gomega.Expect(labelsFirst).Should(gomega.HaveKeyWithValue("app_id", "6f0b4a14-0703-442c-bc80-bea78d31d5ab")) labelsSecond := transform.LabelPairsToLabelsMap(metricStore.GetPoints()[1].Metric().GetLabel()) - Expect(labelsSecond).Should(HaveKeyWithValue("app_id", "6f0b4a14-0703-442c-bc80-bea78d31d5ab")) + gomega.Expect(labelsSecond).Should(gomega.HaveKeyWithValue("app_id", "6f0b4a14-0703-442c-bc80-bea78d31d5ab")) }) }) diff --git a/transform/normalize_name_test.go b/transform/normalize_name_test.go index fc54e156..8e9e8f22 100644 --- a/transform/normalize_name_test.go +++ b/transform/normalize_name_test.go @@ -1,26 +1,26 @@ package transform_test import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" - . "github.com/bosh-prometheus/firehose_exporter/transform" + "github.com/bosh-prometheus/firehose_exporter/transform" ) -var _ = Describe("NormalizeName", func() { - It("normalizes a name", func() { - Expect(NormalizeName("This_is_-_a-MetricName.Example/-._/._with:0_-._/totals")).To(Equal("this_is___a_metric_name_example_______with_0_____totals")) +var _ = ginkgo.Describe("NormalizeName", func() { + ginkgo.It("normalizes a name", func() { + gomega.Expect(transform.NormalizeName("This_is_-_a-MetricName.Example/-._/._with:0_-._/totals")).To(gomega.Equal("this_is___a_metric_name_example_______with_0_____totals")) }) }) -var _ = Describe("NormalizeNameDesc", func() { - It("normalizes a name description", func() { - Expect(NormalizeNameDesc("/p.This_is_-_a-MetricName.Example/with:0totals")).To(Equal("/p-This_is_-_a-MetricName.Example/with:0totals")) +var _ = ginkgo.Describe("NormalizeNameDesc", func() { + ginkgo.It("normalizes a name description", func() { + gomega.Expect(transform.NormalizeNameDesc("/p.This_is_-_a-MetricName.Example/with:0totals")).To(gomega.Equal("/p-This_is_-_a-MetricName.Example/with:0totals")) }) }) -var _ = Describe("NormalizeOriginDesc", func() { - It("normalizes a description", func() { - Expect(NormalizeOriginDesc("This_is-a.Desc.Example")).To(Equal("This_is-a-Desc-Example")) +var _ = ginkgo.Describe("NormalizeOriginDesc", func() { + ginkgo.It("normalizes a description", func() { + gomega.Expect(transform.NormalizeOriginDesc("This_is-a.Desc.Example")).To(gomega.Equal("This_is-a-Desc-Example")) }) }) diff --git a/transform/transform_suite_test.go b/transform/transform_suite_test.go index 24e1d66f..20d77e74 100644 --- a/transform/transform_suite_test.go +++ b/transform/transform_suite_test.go @@ -1,13 +1,13 @@ package transform_test import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "testing" ) func TestMetrics(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Transform Suite") + gomega.RegisterFailHandler(ginkgo.Fail) + ginkgo.RunSpecs(t, "Transform Suite") }