Hello Nir Soffer, Francesco Romani,

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

    https://gerrit.ovirt.org/59773

to review the following change.

Change subject: Add hawkular reporter to reports
......................................................................

Add hawkular reporter to reports

This patch introduces hawkular module that implements the send method
using hawkular-client which is currently available only via pip both on
el7 and fedora. To use it add to vdsm.conf the following

[reports]
enabled = false|true
collector_type = hawkular (default is statsd)
collector_address = localhost|any hostname (currently one
destination)
queue_size = 100 (limits overload)

Change-Id: I71f538184855f7c58bba66acd7b6dea3a53db71b
Signed-off-by: Yaniv Bronhaim <[email protected]>
Reviewed-on: https://gerrit.ovirt.org/58660
Continuous-Integration: Jenkins CI
Reviewed-by: Nir Soffer <[email protected]>
Reviewed-by: Francesco Romani <[email protected]>
---
M lib/vdsm/config.py.in
A lib/vdsm/reports/hawkular.py
2 files changed, 88 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/73/59773/1

diff --git a/lib/vdsm/config.py.in b/lib/vdsm/config.py.in
index 7da4fc0..8bcb09c 100644
--- a/lib/vdsm/config.py.in
+++ b/lib/vdsm/config.py.in
@@ -423,7 +423,12 @@
             'Reports collector address (default localhost)'),
 
         ('collector_type', 'statsd',
-            'Reports collector type (supporting statsd)'),
+            'Reports collector type (supporting statsd or hawkular)'),
+
+        ('queue_size', '100',
+            'Number of reports to queue if collector is not responsive.'
+            ' When the queue is full, oldest reports are dropped. Used only'
+            ' by hawkular reporter (default 100).'),
     ]),
 
     # Section: [devel]
diff --git a/lib/vdsm/reports/hawkular.py b/lib/vdsm/reports/hawkular.py
new file mode 100644
index 0000000..c30a3f7
--- /dev/null
+++ b/lib/vdsm/reports/hawkular.py
@@ -0,0 +1,82 @@
+#
+# 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 collections
+import logging
+import threading
+
+import six
+from hawkular import metrics
+
+from vdsm import concurrent
+from vdsm.config import config
+
+_running = False
+_queue = collections.deque(maxlen=config.getint('reports', 'queue_size'))
+_cond = threading.Condition(threading.Lock())
+_STOP = object()
+
+
+def start(address):
+    global _running
+    if _running:
+        raise RuntimeError('trying to start reporter while running')
+    logging.info("Starting hawkular reporter")
+    concurrent.thread(_run, name='hawkular', address=address).start()
+    _running = True
+
+
+def stop():
+    logging.info("Stopping hawkular reporter")
+    with _cond:
+        _queue.clear()
+        _queue.append(_STOP)
+        _cond.notify()
+
+
+def send(report):
+    metrics_list = [_get_gauge_metric(name, value)
+                    for name, value in six.iteritems(report)]
+    _queue.append(metrics_list)
+    with _cond:
+        _cond.notify()
+
+
+def _get_gauge_metric(name, value):
+    return metrics.create_metric(metrics.MetricType.Gauge, name,
+                                 metrics.create_datapoint(float(value)))
+
+
+def _run(address):
+    global _running
+    client = metrics.HawkularMetricsClient(tenant_id="oVirt",
+                                           host=address)
+    while True:
+        with _cond:
+            while not _queue:
+                _cond.wait()
+        while _queue:
+            items = _queue.popleft()
+            if items is _STOP:
+                break
+            client.put(items)
+    _running = False


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

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

Reply via email to