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
This commit is contained in:
Tobias Henkel 2018-10-16 16:17:49 +02:00
parent 53df54566f
commit b01c7821e5
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
4 changed files with 39 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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')

View File

@ -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.