Commit 63966882 authored by Jason Madden's avatar Jason Madden

Make the nagios metrics come back in a deterministic order. This fixes the...

Make the nagios metrics come back in a deterministic order. This fixes the nagios test under PyPy, but they still fail under Python 3 for the same reason test_ruok does.
parent fe7510d0
...@@ -73,12 +73,10 @@ def check(addr, output_metrics, status, per): ...@@ -73,12 +73,10 @@ def check(addr, output_metrics, status, per):
s.connect(addr) s.connect(addr)
except socket.error as err: except socket.error as err:
return error("Can't connect %s" % err) return error("Can't connect %s" % err)
fp = s.makefile()
fp.write('\x00\x00\x00\x04ruok') s.sendall(b'\x00\x00\x00\x04ruok')
fp.flush() proto = s.recv(struct.unpack(">I", s.recv(4))[0])
proto = fp.read(struct.unpack(">I", fp.read(4))[0]) datas = s.recv(struct.unpack(">I", s.recv(4))[0])
datas = fp.read(struct.unpack(">I", fp.read(4))[0])
fp.close()
s.close() s.close()
data = json.loads(datas) data = json.loads(datas)
if not data: if not data:
...@@ -88,7 +86,7 @@ def check(addr, output_metrics, status, per): ...@@ -88,7 +86,7 @@ def check(addr, output_metrics, status, per):
messages = [] messages = []
level = 0 level = 0
if output_metrics: if output_metrics:
for storage_id, sdata in data.items(): for storage_id, sdata in sorted(data.items()):
for name in nodiff_names: for name in nodiff_names:
new_metric(metrics, storage_id, name, sdata[name]) new_metric(metrics, storage_id, name, sdata[name])
...@@ -110,7 +108,7 @@ def check(addr, output_metrics, status, per): ...@@ -110,7 +108,7 @@ def check(addr, output_metrics, status, per):
with open(status, 'w') as f: # save current with open(status, 'w') as f: # save current
f.write(json.dumps(data)) f.write(json.dumps(data))
for storage_id, sdata in data.items(): for storage_id, sdata in sorted(data.items()):
if sdata['last-transaction'] == NO_TRANSACTION: if sdata['last-transaction'] == NO_TRANSACTION:
messages.append("Empty storage %r" % storage_id) messages.append("Empty storage %r" % storage_id)
level = max(level, 1) level = max(level, 1)
......
...@@ -118,34 +118,34 @@ profixes metrics with a storage id. ...@@ -118,34 +118,34 @@ profixes metrics with a storage id.
... """) ... """)
>>> saddr = ':'.join(map(str, addr)) # (host, port) -> host:port >>> saddr = ':'.join(map(str, addr)) # (host, port) -> host:port
>>> nagios([saddr, '-m', '-sstatus']) >>> nagios([saddr, '-m', '-sstatus'])
Empty storage u'second'|second:active_txns=0 Empty storage u'first'|first:active_txns=0
Empty storage u'first' Empty storage u'second'
| second:connections=0 | first:connections=0
second:waiting=0
first:active_txns=0
first:connections=0
first:waiting=0 first:waiting=0
second:active_txns=0
second:connections=0
second:waiting=0
1 1
>>> nagios([saddr, '-m', '-sstatus']) >>> nagios([saddr, '-m', '-sstatus'])
Empty storage u'second'|second:active_txns=0 Empty storage u'first'|first:active_txns=0
Empty storage u'first' Empty storage u'second'
| second:connections=0 | first:connections=0
second:waiting=0
first:active_txns=0
first:connections=0
first:waiting=0 first:waiting=0
second:aborts=0.0 second:active_txns=0
second:commits=0.0 second:connections=0
second:conflicts=0.0 second:waiting=0
second:conflicts_resolved=0.0
second:loads=0.0
second:stores=0.0
first:aborts=0.0 first:aborts=0.0
first:commits=0.0 first:commits=0.0
first:conflicts=0.0 first:conflicts=0.0
first:conflicts_resolved=0.0 first:conflicts_resolved=0.0
first:loads=0.0 first:loads=42.42
first:stores=0.0 first:stores=0.0
second:aborts=0.0
second:commits=0.0
second:conflicts=0.0
second:conflicts_resolved=0.0
second:loads=42.42
second:stores=0.0
1 1
>>> stop() >>> stop()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment