From: Boris Ranto Date: Thu, 12 Jul 2018 15:05:18 +0000 (+0200) Subject: prometheus: Optimize metrics formatting X-Git-Tag: v14.0.1~849^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d395868d9ef787d98fa1a0f9dd0e84e41d04fd26;p=ceph.git prometheus: Optimize metrics formatting 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 --- diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index 71480c6d560e..edc68b658066 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -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):