Hello Piotr Kliczewski, Nir Soffer, Martin Polednik,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/59772

to review the following change.

Change subject: Introduce reports package
......................................................................

Introduce reports package

reports logic allows to send report to external providers by start close
and send functions. The report itself is simply key value attribute.

This patch includes statsd reporter which implements the send method to
statsd listener by python-statsd.
To enable reports add the following to vdsm.conf:

[reports]
enabled = false|true (disabled by default)
collector_type = statsd (following patch adds more providers)
collector_address = localhost|any hostname (currently one destination)

We still miss python-stastd for python3 so we don't require the package
in spec. If metric collector is configured to be enable and the type
implementation is not available ImportError should be raised.

Change-Id: I23c1141f097f740441d085f99e0bf76eb7f718c9
Signed-off-by: Yaniv Bronhaim <[email protected]>
Reviewed-on: https://gerrit.ovirt.org/56880
Reviewed-by: Piotr Kliczewski <[email protected]>
Reviewed-by: Nir Soffer <[email protected]>
Reviewed-by: Martin Polednik <[email protected]>
Continuous-Integration: Jenkins CI
---
M configure.ac
M lib/vdsm/Makefile.am
M lib/vdsm/config.py.in
A lib/vdsm/reports/Makefile.am
A lib/vdsm/reports/__init__.py
A lib/vdsm/reports/statsd.py
M vdsm.spec.in
M vdsm/vdsm
8 files changed, 130 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/59772/1

diff --git a/configure.ac b/configure.ac
index 70f8f83..a945869 100644
--- a/configure.ac
+++ b/configure.ac
@@ -432,6 +432,7 @@
        lib/vdsm/network/ovs/Makefile
        lib/vdsm/network/ovs/driver/Makefile
        lib/vdsm/network/tc/Makefile
+       lib/vdsm/reports/Makefile
        lib/vdsm/rpc/Makefile
        lib/vdsm/storage/Makefile
        lib/vdsm/virt/Makefile
diff --git a/lib/vdsm/Makefile.am b/lib/vdsm/Makefile.am
index fbeea7e..3fb3a65 100644
--- a/lib/vdsm/Makefile.am
+++ b/lib/vdsm/Makefile.am
@@ -19,7 +19,7 @@
 #
 include $(top_srcdir)/build-aux/Makefile.subs
 
-SUBDIRS=common tool infra profiling rpc network virt storage host
+SUBDIRS=common tool infra profiling rpc network virt storage host reports
 
 dist_vdsmpylib_PYTHON = \
        __init__.py \
diff --git a/lib/vdsm/config.py.in b/lib/vdsm/config.py.in
index 6b5156d..7da4fc0 100644
--- a/lib/vdsm/config.py.in
+++ b/lib/vdsm/config.py.in
@@ -414,6 +414,18 @@
             ' This is for internal usage and may change without warning'),
     ]),
 
+    # Section: [reports]
+    ('reports', [
+        ('enabled', 'false',
+            'Enable metric reporting (default false)'),
+
+        ('collector_address', 'localhost',
+            'Reports collector address (default localhost)'),
+
+        ('collector_type', 'statsd',
+            'Reports collector type (supporting statsd)'),
+    ]),
+
     # Section: [devel]
     ('devel', [
 
diff --git a/lib/vdsm/reports/Makefile.am b/lib/vdsm/reports/Makefile.am
new file mode 100644
index 0000000..5284662
--- /dev/null
+++ b/lib/vdsm/reports/Makefile.am
@@ -0,0 +1,22 @@
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+include $(top_srcdir)/build-aux/Makefile.subs
+
+vdsmreportsdir = $(vdsmpylibdir)/reports
+dist_vdsmreports_PYTHON = *.py
diff --git a/lib/vdsm/reports/__init__.py b/lib/vdsm/reports/__init__.py
new file mode 100644
index 0000000..0f6c65e
--- /dev/null
+++ b/lib/vdsm/reports/__init__.py
@@ -0,0 +1,47 @@
+#
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from __future__ import absolute_import
+
+import importlib
+from ..config import config
+
+_reporter = None
+
+
+def start():
+    global _reporter
+    if config.getboolean('reports', 'enabled'):
+        _reporter = importlib.import_module(
+            'vdsm.reports.' + config.get('reports', 'collector_type')
+        )
+        _reporter.start(config.get('reports', 'collector_address'))
+
+
+def stop():
+    global _reporter
+    if _reporter:
+        _reporter.stop()
+        _reporter = None
+
+
+def send(report):
+    if _reporter:
+        _reporter.send(report)
diff --git a/lib/vdsm/reports/statsd.py b/lib/vdsm/reports/statsd.py
new file mode 100644
index 0000000..8a2a4f3
--- /dev/null
+++ b/lib/vdsm/reports/statsd.py
@@ -0,0 +1,42 @@
+#
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from __future__ import absolute_import
+
+import statsd
+import six
+
+_client = None
+
+
+def start(address):
+    global _client
+    if _client is None:
+        _client = statsd.StatsClient(host=address)
+
+
+def stop():
+    # client doesn't support any close mechanism
+    pass
+
+
+def send(report):
+    for name, value in six.iteritems(report):
+        _client.gauge(name, value)
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 4dbc094..be9b96f 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1159,6 +1159,7 @@
 %dir %{python_sitelib}/%{vdsm_name}/network/ovs
 %dir %{python_sitelib}/%{vdsm_name}/network/ovs/driver
 %dir %{python_sitelib}/%{vdsm_name}/network/tc
+%dir %{python_sitelib}/%{vdsm_name}/reports
 %dir %{python_sitelib}/%{vdsm_name}/tool
 %dir %{python_sitelib}/%{vdsm_name}/tool/configurators
 %dir %{python_sitelib}/%{vdsm_name}/profiling
@@ -1243,6 +1244,7 @@
 %{python_sitelib}/%{vdsm_name}/profiling/errors.py*
 %{python_sitelib}/%{vdsm_name}/profiling/memory.py*
 %{python_sitelib}/%{vdsm_name}/profiling/profile.py*
+%{python_sitelib}/%{vdsm_name}/reports/*.py*
 %{python_sitelib}/%{vdsm_name}/storage/__init__.py*
 %{python_sitelib}/%{vdsm_name}/storage/asyncevent.py*
 %{python_sitelib}/%{vdsm_name}/storage/blkdiscard.py*
diff --git a/vdsm/vdsm b/vdsm/vdsm
index bd714e9..1cb5dda 100755
--- a/vdsm/vdsm
+++ b/vdsm/vdsm
@@ -39,6 +39,7 @@
 from vdsm.config import config
 from vdsm import libvirtconnection
 from vdsm import taskset
+from vdsm import reports
 from vdsm.panic import panic
 from vdsm.profiling import profile
 
@@ -84,6 +85,7 @@
     zombiereaper.registerSignalHandler()
 
     profile.start()
+    reports.start()
 
     libvirtconnection.start_event_loop()
 
@@ -112,6 +114,7 @@
 
             profile.stop()
         finally:
+            reports.stop()
             health.stop()
             periodic.stop()
             cif.prepareForShutdown()


-- 
To view, visit https://gerrit.ovirt.org/59772
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I23c1141f097f740441d085f99e0bf76eb7f718c9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-4.0
Gerrit-Owner: Yaniv Bronhaim <[email protected]>
Gerrit-Reviewer: Martin Polednik <[email protected]>
Gerrit-Reviewer: Nir Soffer <[email protected]>
Gerrit-Reviewer: Piotr Kliczewski <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/admin/lists/[email protected]

Reply via email to