From efccf6ecf3189495833ec51267a536851250d9dd Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Fri, 15 Mar 2019 20:05:46 -0700 Subject: [PATCH] mgr/telemetry: check for errors when sending report There was no error checking, and the server has been failing for some time, but no one noticed. Oops. Signed-off-by: Dan Mick (cherry picked from commit de71f38a2c0b37a96970d6b2fd62ea19b20bdf46) Conflicts: src/pybind/mgr/telemetry/module.py mostly due to store_get/store_set not existing in luminous, and we relying instead on config_get/config_set. --- src/pybind/mgr/telemetry/module.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/telemetry/module.py b/src/pybind/mgr/telemetry/module.py index fe1203411cf69..cde9c20b1df50 100644 --- a/src/pybind/mgr/telemetry/module.py +++ b/src/pybind/mgr/telemetry/module.py @@ -294,7 +294,12 @@ class Module(MgrModule): proxies['http'] = self.config['proxy'] proxies['https'] = self.config['proxy'] - requests.put(url=self.config['url'], json=report, proxies=proxies) + resp = requests.put(url=self.config['url'], + json=report, proxies=proxies) + if not resp.ok: + self.log.error("Report send failed: %d %s %s" % + (resp.status_code, resp.reason, resp.text)) + return resp def handle_command(self, command): if command['prefix'] == 'telemetry config-show': @@ -317,8 +322,15 @@ class Module(MgrModule): return 0, '', '' elif command['prefix'] == 'telemetry send': self.last_report = self.compile_report() - self.send(self.last_report) - return 0, 'Report send to {0}'.format(self.config['url']), '' + resp = self.send(self.last_report) + if resp.ok: + return 0, 'Report sent to {0}'.format(self.config['url']), '' + return 1, '', 'Failed to send report to %s: %d %s %s' % ( + self.config['url'], + resp.status_code, + resp.reason, + resp.text + ) elif command['prefix'] == 'telemetry show': report = self.last_report if not report: @@ -368,9 +380,12 @@ class Module(MgrModule): self.log.exception('Exception while compiling report:') try: - self.send(self.last_report) - self.last_upload = now - self.set_config('last_upload', str(now)) + resp = self.send(self.last_report) + # self.send logs on failure; only update last_upload + # if we succeed + if resp.ok: + self.last_upload = now + self.set_config('last_upload', str(now)) except: self.log.exception('Exception while sending report:') else: -- 2.39.5