From Yaniv Bronhaim <ybronhei(a)redhat.com>:
Yaniv Bronhaim has posted comments on this change.
Change subject: Adding simple client that sends gauge metrics to statsd port using udp
......................................................................
Patch Set 5:
(9 comments)
https://gerrit.ovirt.org/#/c/67004/5/lib/vdsm/metrics/statsd.py
File lib/vdsm/metrics/statsd.py:
Line 57: self._maxudpsize = maxudpsize
Line 58:
Line 59: def _send(self, data):
Line 60: try:
Line 61: if data:
Why support empty data? is this the original behavior? please
document this
why to send anything if the data is empty? I don't understand what
you expect to see here in my reply.. I took this condition from the original code as I
assumed its a right check to do. do you want me to write above it "" if data is
empty we don't do anything "" the first line does that... too many docs is
just confusing
Line 62: self._sock.sendto(data.encode('ascii'), self._addr)
Line 63: except (socket.error, RuntimeError):
Line 64: pass
Line 65:
Line 62: self._sock.sendto(data.encode('ascii'), self._addr)
Line 63: except (socket.error, RuntimeError):
Line 64: pass
Line 65:
Line 66: def gauge(self, stat, value):
Please document the arguments.
don't you think its
redundant? ... its quite clear from the context of the code. do you really plan to
document every func you introduce from now on? Im glad to maintain code that is clear by
its own context and not by reading its not updated comments
Line 67: self._send(self._prepare(stat, '%s|g' % value))
Line 68:
Line 69: def _prepare(self, stat, value):
Line 65:
Line 66: def gauge(self, stat, value):
Line 67: self._send(self._prepare(stat, '%s|g' % value))
Line 68:
Line 69: def _prepare(self, stat, value):
We need this only for testing, and we should avoid this kind of
testing.
what? I like this function. prepare creates the string in the format that
fits to statsd. I can add a comment if its not clear enough for you, if that's what
you meant
https://gerrit.ovirt.org/#/c/67004/5/tests/statsd_tests.py
File tests/statsd_tests.py:
Line 26: class StatsdModuleTest(TestCaseBase):
Line 27: def test_unresponsive_destination(self):
Line 28: # When clients point to not reachable ip nothing should happen.
Line 29: # we don't want to fail or log in vdsm if server is down
Line 30: statsd.StatsClient('localhost')._send('a.b.c')
Why are using using private methods in the tests? why not use a
public meth
because I want to test the internal logic as well... its a unit test,
not functional
Line 31:
Line 32: def test_send_gauge_format(self):
Line 33: def mirror_send(self, data):
Line 34: if data[-2:] != '|g':
Line 31:
Line 32: def test_send_gauge_format(self):
Line 33: def mirror_send(self, data):
Line 34: if data[-2:] != '|g':
Line 35: raise Exception("gauge format is not correct: %s",
data)
This is the entire gauge format? I think we should be more specific.
yes this is all the difference between qauge to sets and counters.. you can read in
the metrics spec
Line 36:
Line 37: c = statsd.StatsClient('localhost')
Line 38: with MonkeyPatchScope([(statsd.StatsClient, '_send',
mirror_send)]):
Line 39: c.gauge('a.b.c', 1)
Line 34: if data[-2:] != '|g':
Line 35: raise Exception("gauge format is not correct: %s",
data)
Line 36:
Line 37: c = statsd.StatsClient('localhost')
Line 38: with MonkeyPatchScope([(statsd.StatsClient, '_send',
mirror_send)]):
We don't need to monkeypatch a class when we have an instance,
you can simp
I prefer to monkeypatch.. more clear to me than override the method.
its good for keeping the instance the same if later you add more logic to the test.
about your suggestion - do we want to test socket package?... I guess not. we just want to
see if the send method gets the data as expected. I assume here that socket.sendto func is
tested by python guys
Line 39: c.gauge('a.b.c', 1)
Line 40:
Line 41: def test_prepare(self):
Line 42: c = statsd.StatsClient('localhost')
Line 39: c.gauge('a.b.c', 1)
Line 40:
Line 41: def test_prepare(self):
Line 42: c = statsd.StatsClient('localhost')
Line 43: s = c._prepare('aaa', 1)
Don't test private methods, test the behavior of the client using
the publi
again... its unit tests. uts should call all internal functions to cover
as much as possible of the code and the possible inputs. probably I don't cover all
here, but those tests are important to keep my planed behavior of those functions
Line 44: self.assertEqual(s, 'aaa:1')
Line 45:
Line 46: def test_module(self):
Line 47: statsd.start('localhost')
Line 44: self.assertEqual(s, 'aaa:1')
Line 45:
Line 46: def test_module(self):
Line 47: statsd.start('localhost')
Line 48: statsd.send({})
What does this test?
exactly what you asked before - testing
the public functions of the module. see that it doesn't raise or fail
Line 49:
Line 50: def test_stop(self):
Line 51: statsd.start('localhost')
Line 48: statsd.send({})
Line 49:
Line 50: def test_stop(self):
Line 51: statsd.start('localhost')
Line 52: statsd.stop()
What does this test?
same
--
To view, visit
https://gerrit.ovirt.org/67004
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I7bbc8a4c0e3afc25c205bfec58c5e77096803404
Gerrit-PatchSet: 5
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yaniv Bronhaim <ybronhei(a)redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken(a)redhat.com>
Gerrit-Reviewer: Irit Goihman <igoihman(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczewski(a)gmail.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei(a)redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation(a)ovirt.org>
Gerrit-HasComments: Yes