From: Laura Flores Date: Mon, 2 Aug 2021 23:05:26 +0000 (+0000) Subject: mgr/telemetry: improve the formatting of perf histograms in telemetry report X-Git-Tag: v17.1.0~1008^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f6181ddb585f5540bcc133c7753015aa01379325;p=ceph.git mgr/telemetry: improve the formatting of perf histograms in telemetry report Currently, the JSON formatter displays lists vertically rahter than horizontally, which makes it particularly difficult for users to scroll through the perf histograms, much less read/interpret them. With this commit, I wrote a patch within the show() function (the function that is controlled by `ceph telemetry show`) which formats the the lists of ranges and values in the perf histograms as strings. This way, parts of the histogram output is displayed horizontally instead of vertically. This makes the Telemetry report much more human-readable. Signed-off-by: Laura Flores --- diff --git a/src/pybind/mgr/telemetry/module.py b/src/pybind/mgr/telemetry/module.py index b88adfee0d1c..fba99483ecba 100644 --- a/src/pybind/mgr/telemetry/module.py +++ b/src/pybind/mgr/telemetry/module.py @@ -444,7 +444,7 @@ class Module(MgrModule): # I am also putting in a catch for a KeyError since it could # happen where the code is assuming that a key exists in the # schema when it doesn't. In either case, we'll handle that - # bt returning an empty dict. + # by returning an empty dict. except (json.decoder.JSONDecodeError, KeyError) as e: self.log.debug("Error caught: {}".format(e)) return {} @@ -1014,6 +1014,28 @@ Please consider enabling the telemetry module with 'ceph telemetry on'.''' Show report of all channels ''' report = self.get_report(channels=channels) + + # Formatting the perf histograms so they are human-readable. This will change the + # ranges and values, which are currently in list form, into strings so that + # they are displayed horizontally instead of vertically. + try: + for histogram in report['osd_perf_histograms']['osd']: + # Adjust ranges by converting lists into strings + for axis in report['osd_perf_histograms']['osd'][histogram]['axes']: + for i in range(0, len(axis['ranges'])): + axis['ranges'][i] = str(axis['ranges'][i]) + + # Adjust values also by converting lists into strings + for i in range(0, len(report['osd_perf_histograms']['osd'][histogram]['values'])): + report['osd_perf_histograms']['osd'][histogram]['values'][i] = \ + str(report['osd_perf_histograms']['osd'][histogram]['values'][i]) + except KeyError: + # If the perf channel is not enabled, there should be a KeyError since + # 'osd_perf_histograms' would not be present in the report. In that case, + # the show function should pass as usual without trying to format the + # histograms. + pass + report = json.dumps(report, indent=4, sort_keys=True) if self.channel_device: report += '''