From b01c7821e5e2bf20ca4c882e0f50e744cdd23c65 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Tue, 16 Oct 2018 16:17:49 +0200 Subject: [PATCH] Initialize label statistics to zero The label statistics age gauges that keep their values. Currently nodepool doesn't initialize the label based node statistics to zero. Because of this any label state that shows up in the statistics won't be reset to zero and nodepool is stopping to send updates to this gauge. This leads to graphs that are mostly stuck to 1 if no nodes are currently in this state. This can be fixed by iterating over the supported labels and initializing all states of them to zero. Change-Id: I6c7f63f8f64a83b225386f6da567bfae5141be7b --- nodepool/stats.py | 6 +++++ .../tests/fixtures/node_no_min_ready.yaml | 6 +++++ nodepool/tests/test_launcher.py | 22 +++++++++++++++++++ .../notes/label-stats-1059f87162e461e1.yaml | 5 +++++ 4 files changed, 39 insertions(+) create mode 100644 releasenotes/notes/label-stats-1059f87162e461e1.yaml diff --git a/nodepool/stats.py b/nodepool/stats.py index 1c17cd727..7bdeee555 100755 --- a/nodepool/stats.py +++ b/nodepool/stats.py @@ -104,6 +104,12 @@ class StatsReporter(object): key = 'nodepool.provider.%s.nodes.%s' % (provider.name, state) states[key] = 0 + # Initialize label stats to 0 + for label in provider.getSupportedLabels(): + for state in zk.Node.VALID_STATES: + key = 'nodepool.label.%s.nodes.%s' % (label, state) + states[key] = 0 + for node in zk_conn.nodeIterator(): # nodepool.nodes.STATE key = 'nodepool.nodes.%s' % node.state diff --git a/nodepool/tests/fixtures/node_no_min_ready.yaml b/nodepool/tests/fixtures/node_no_min_ready.yaml index 8568ad8f2..0a848e6e5 100644 --- a/nodepool/tests/fixtures/node_no_min_ready.yaml +++ b/nodepool/tests/fixtures/node_no_min_ready.yaml @@ -10,6 +10,8 @@ zookeeper-servers: labels: - name: fake-label min-ready: 0 + - name: fake-label2 + min-ready: 0 providers: - name: fake-provider @@ -34,6 +36,10 @@ providers: diskimage: fake-image min-ram: 8192 flavor-name: 'Fake' + - name: fake-label2 + diskimage: fake-image + min-ram: 8192 + flavor-name: 'Fake' diskimages: - name: fake-image diff --git a/nodepool/tests/test_launcher.py b/nodepool/tests/test_launcher.py index 492f84ed6..27c3ec34f 100644 --- a/nodepool/tests/test_launcher.py +++ b/nodepool/tests/test_launcher.py @@ -84,6 +84,28 @@ class TestLauncher(tests.DBTestCase): self.assertReportedStat('nodepool.label.fake-label.nodes.ready', value='1', kind='g') + # Verify that we correctly initialized unused label stats to 0 + self.assertReportedStat('nodepool.label.fake-label2.nodes.building', + value='0', kind='g') + self.assertReportedStat('nodepool.label.fake-label2.nodes.testing', + value='0', kind='g') + self.assertReportedStat('nodepool.label.fake-label2.nodes.ready', + value='0', kind='g') + self.assertReportedStat('nodepool.label.fake-label2.nodes.in-use', + value='0', kind='g') + self.assertReportedStat('nodepool.label.fake-label2.nodes.used', + value='0', kind='g') + self.assertReportedStat('nodepool.label.fake-label2.nodes.hold', + value='0', kind='g') + self.assertReportedStat('nodepool.label.fake-label2.nodes.deleting', + value='0', kind='g') + self.assertReportedStat('nodepool.label.fake-label2.nodes.failed', + value='0', kind='g') + self.assertReportedStat('nodepool.label.fake-label2.nodes.init', + value='0', kind='g') + self.assertReportedStat('nodepool.label.fake-label2.nodes.aborted', + value='0', kind='g') + def test_node_assignment_order(self): """Test that nodes are assigned in the order requested""" configfile = self.setup_config('node_many_labels.yaml') diff --git a/releasenotes/notes/label-stats-1059f87162e461e1.yaml b/releasenotes/notes/label-stats-1059f87162e461e1.yaml new file mode 100644 index 000000000..aa3193e66 --- /dev/null +++ b/releasenotes/notes/label-stats-1059f87162e461e1.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + The nodes by label and state statistic gauges are now correctly reset to + zero if no node of a label and state exists.