← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:numbercruncher-no-data into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:numbercruncher-no-data into launchpad:master.

Commit message:
number-cruncher: Don't send null gauges to statsd

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/430304

If a gauge has a value of None (e.g. the PPA latency statistics when no builds have happened recently, which can easily happen on dogfood), then the statsd client will raise `TypeError`.  Skip sending the gauge to statsd in this case.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:numbercruncher-no-data into launchpad:master.
diff --git a/lib/lp/services/statsd/numbercruncher.py b/lib/lp/services/statsd/numbercruncher.py
index 9baec77..b18adf5 100644
--- a/lib/lp/services/statsd/numbercruncher.py
+++ b/lib/lp/services/statsd/numbercruncher.py
@@ -70,6 +70,8 @@ class NumberCruncher(service.Service):
         return loop, stopping_deferred
 
     def _sendGauge(self, gauge_name, value, labels=None):
+        if value is None:
+            return
         self.logger.debug(
             "{}: {}".format(
                 self.statsd_client.composeMetric(gauge_name, labels), value
diff --git a/lib/lp/services/statsd/tests/test_numbercruncher.py b/lib/lp/services/statsd/tests/test_numbercruncher.py
index f636df4..d3ed3fe 100644
--- a/lib/lp/services/statsd/tests/test_numbercruncher.py
+++ b/lib/lp/services/statsd/tests/test_numbercruncher.py
@@ -418,6 +418,12 @@ class TestNumberCruncher(StatsMixin, TestCaseWithFactory):
         for gauge in gauges:
             self.assertIn(gauge, keys)
 
+    def test_updatePPABuildLatencyStats_no_data(self):
+        clock = task.Clock()
+        cruncher = NumberCruncher(clock=clock)
+        cruncher.updatePPABuildLatencyStats()
+        self.assertEqual(0, self.stats_client.gauge.call_count)
+
     def test_updatePPABuildLatencyStats_error(self):
         clock = task.Clock()
         cruncher = NumberCruncher(clock=clock)