]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
prometheus: Optimize metrics formatting
authorBoris Ranto <branto@redhat.com>
Thu, 12 Jul 2018 15:05:18 +0000 (17:05 +0200)
committerBoris Ranto <branto@redhat.com>
Tue, 17 Jul 2018 20:28:59 +0000 (22:28 +0200)
It is faster to use join for join multiple strings than the regular
string concatenation since it does not create a new string on each
iteration.

Signed-off-by: Boris Ranto <branto@redhat.com>
src/pybind/mgr/prometheus/module.py

index 71480c6d560ee7f55d61a9bcfa4e5008c2c79e39..edc68b6580666badbbd6f926fbb53a0a279d8035 100644 (file)
@@ -570,7 +570,6 @@ class Module(MgrModule):
                     ))
                     self.metrics.set(path, value, (daemon,))
 
-
         return self.metrics.all()
 
     def get_file_sd_config(self):
@@ -630,10 +629,8 @@ class Module(MgrModule):
                 return self
 
             def format_metrics(self, metrics):
-                formatted = ''
-                for m in metrics.values():
-                    formatted += m.str_expfmt()
-                return formatted + '\n'
+                _metrics = [m.str_expfmt() for m in metrics.values()]
+                return ''.join(_metrics) + '\n'
 
             @cherrypy.expose
             def index(self):