]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/telemetry: improve the formatting of perf histograms in telemetry report
authorLaura Flores <lflores@redhat.com>
Mon, 2 Aug 2021 23:05:26 +0000 (23:05 +0000)
committerLaura Flores <lflores@redhat.com>
Mon, 2 Aug 2021 23:05:26 +0000 (23:05 +0000)
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 <lflores@redhat.com>
src/pybind/mgr/telemetry/module.py

index b88adfee0d1c71c2e40a237b8273cf2e6d000b67..fba99483ecba87638bb1208d30dee0ce2b4aad45 100644 (file)
@@ -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 += '''