]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/influx: Catch ConnectionError if raised
authorWido den Hollander <wido@42on.com>
Tue, 30 Jan 2018 14:45:40 +0000 (15:45 +0100)
committerWido den Hollander <wido@42on.com>
Wed, 6 Jun 2018 13:50:10 +0000 (15:50 +0200)
The InfluxDBClient can also re-raise a ConnectionError from the
python requests module if that was caught.

The Exception might be:

  ConnectionError: ('Connection aborted.', error(104, 'Connection reset by peer'))

Catch and log this error instead of having it raised which might
cause problems further down.

Signed-off-by: Wido den Hollander <wido@42on.com>
(cherry picked from commit a0c2c8b900cd2bab2ef8041722036036efd2cb0f)

src/pybind/mgr/influx/module.py

index bf4c3942489bfb8a332b2363802bb3fbc288219c..067229ee75bc005ce0ed4afb8e0d4e86b1fe7419 100644 (file)
@@ -9,6 +9,7 @@ from mgr_module import MgrModule
 try:
     from influxdb import InfluxDBClient
     from influxdb.exceptions import InfluxDBClientError
+    from requests.exceptions import ConnectionError
 except ImportError:
     InfluxDBClient = None
 
@@ -170,6 +171,13 @@ class Module(MgrModule):
         if not self.config['hostname']:
             self.log.error("No Influx server configured, please set one using: "
                            "ceph influx config-set hostname <hostname>")
+            self.set_health_checks({
+                'MGR_INFLUX_NO_SERVER': {
+                    'severity': 'warning',
+                    'summary': 'No InfluxDB server configured',
+                    'detail': ['Configuration option hostname not set']
+                }
+            })
             return
 
         # If influx server has authentication turned off then
@@ -189,6 +197,19 @@ class Module(MgrModule):
         try:
             client.write_points(self.get_df_stats(), 'ms')
             client.write_points(self.get_daemon_stats(), 'ms')
+            self.set_health_checks(dict())
+        except ConnectionError as e:
+            self.log.exception("Failed to connect to Influx host %s:%d",
+                               self.config['hostname'], self.config['port'])
+            self.set_health_checks({
+                'MGR_INFLUX_SEND_FAILED': {
+                    'severity': 'warning',
+                    'summary': 'Failed to send data to InfluxDB server at %s:%d'
+                               ' due to an connection error'
+                               % (self.config['hostname'], self.config['port']),
+                    'detail': [str(e)]
+                }
+            })
         except InfluxDBClientError as e:
             if e.code == 404:
                 self.log.info("Database '%s' not found, trying to create "
@@ -198,6 +219,13 @@ class Module(MgrModule):
                               self.config['username'])
                 client.create_database(self.config['database'])
             else:
+                self.set_health_checks({
+                    'MGR_INFLUX_SEND_FAILED': {
+                        'severity': 'warning',
+                        'summary': 'Failed to send data to InfluxDB',
+                        'detail': [str(e)]
+                    }
+                })
                 raise
 
     def shutdown(self):