atc: test that concurrent request metric is emitted
despite the fact that we ensure that we're incrementing & decrementing
those counters, there were no tests that would ensure that we actually
emit what has been captured.
@@ -30,14 +30,17 @@ var _ = Describe("Periodic emission of metrics", func() {
metric.RegisterEmitter(emitterFactory)
emitterFactory.IsConfiguredReturns(true)
emitterFactory.NewEmitterReturns(emitter, nil)
- a := &dbfakes.FakeConn{}
- a.NameReturns("A")
- b := &dbfakes.FakeConn{}
- b.NameReturns("B")
- metric.Databases = []db.Conn{a, b}
metric.Initialize(testLogger, "test", map[string]string{}, 1000)
- process = ifrit.Invoke(metric.PeriodicallyEmit(lager.NewLogger("dont care"), 250*time.Millisecond))
+ })
+
+ JustBeforeEach(func() {
+ runner := metric.PeriodicallyEmit(
+ lager.NewLogger("dont care"),
+ 250*time.Millisecond,
+ )
+
+ process = ifrit.Invoke(runner)
})
AfterEach(func() {
@@ -46,6 +49,15 @@ var _ = Describe("Periodic emission of metrics", func() {
metric.Deinitialize(nil)
})
+ Context("database-related metrics", func() {
+ BeforeEach(func() {
+ a := &dbfakes.FakeConn{}
+ a.NameReturns("A")
+ b := &dbfakes.FakeConn{}
+ b.NameReturns("B")
+ metric.Databases = []db.Conn{a, b}
+ })
+
It("emits database queries", func() {
Eventually(emitter.EmitCallCount).Should(BeNumerically(">=", 1))
Expect(emitter.Invocations()["Emit"]).To(
@@ -81,3 +93,51 @@ var _ = Describe("Periodic emission of metrics", func() {
)
})
})
+
+ Context("concurrent requests", func() {
+ const action = "ListAllSomething"
+
+ BeforeEach(func() {
+ gauge := &metric.Gauge{}
+ gauge.Set(123)
+
+ counter := &metric.Counter{}
+ counter.IncDelta(10)
+
+ metric.ConcurrentRequests[action] = gauge
+ metric.ConcurrentRequestsLimitHit[action] = counter
+ })
+
+ It("emits", func() {
+ Eventually(emitter.EmitCallCount).Should(BeNumerically(">=", 1))
+
+ Expect(emitter.Invocations()["Emit"]).To(
+ ContainElement(
+ ContainElement(
+ MatchFields(IgnoreExtras, Fields{
+ "Name": Equal("concurrent requests"),
+ "Value": Equal(float64(123)),
+ "Attributes": Equal(map[string]string{
+ "action": action,
+ }),
+ }),
+ ),
+ ),
+ )
+
+ Expect(emitter.Invocations()["Emit"]).To(
+ ContainElement(
+ ContainElement(
+ MatchFields(IgnoreExtras, Fields{
+ "Name": Equal("concurrent requests limit hit"),
+ "Value": Equal(float64(10)),
+ "Attributes": Equal(map[string]string{
+ "action": action,
+ }),
+ }),
+ ),
+ ),
+ )
+ })
+ })
+})
