Skip to content

Commit

Permalink
mgr/telemetry: check for errors when sending report
Browse files Browse the repository at this point in the history
There was no error checking, and the server has been failing for
some time, but no one noticed.  Oops.

Signed-off-by: Dan Mick <[email protected]>
  • Loading branch information
dmick committed Mar 16, 2019
1 parent 6006666 commit de71f38
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/pybind/mgr/telemetry/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ def send(self, report):
proxies['http'] = self.proxy
proxies['https'] = self.proxy

requests.put(url=self.url, json=report, proxies=proxies)
resp = requests.put(url=self.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, inbuf, command):
if command['prefix'] == 'telemetry status':
Expand All @@ -279,8 +283,16 @@ def handle_command(self, inbuf, command):
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.url), ''
resp = self.send(self.last_report)
if resp.ok:
return 0, 'Report sent to {0}'.format(self.url), ''
return 1, '', 'Failed to send report to %s: %d %s %s' % (
self.url,
resp.status_code,
resp.reason,
resp.text
)

elif command['prefix'] == 'telemetry show':
report = self.last_report
if not report:
Expand Down Expand Up @@ -328,9 +340,12 @@ def serve(self):
self.log.exception('Exception while compiling report:')

try:
self.send(self.last_report)
self.last_upload = now
self.set_store('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_store('last_upload', str(now))
except:
self.log.exception('Exception while sending report:')
else:
Expand Down

0 comments on commit de71f38

Please sign in to comment.