From 03de8f9557f0b58cf0f4d1fdb5a0ba1932ba9f75 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 23 Oct 2018 22:43:51 +0000 Subject: [PATCH] mgr/dashboard: Enable gzip compression This is related to http://tracker.ceph.com/issues/36453. It is far from a complete solution, but seems like a positive move. I tested this change by first disabling my browser cache, and then used the /docs endpoint to query /api/dashboard/health. Before compression: Content-Length: 60748 Time: 615ms After: Content-Length: 7505 Time: 92ms Then, I logged into the dashboard as normal and reloaded the page once I was in. Some values for the reload operation before compression: Total page load time: 58.48s vendor.js Content-Length: 6486025 vendor.js time: 48.09s After: Total page load time: 14.55s vendor.js Content-Length: 1143178 vendor.js time: 4.50s Signed-off-by: Zack Cerza --- qa/tasks/mgr/dashboard/test_requests.py | 23 +++++++++++++++++++++++ src/pybind/mgr/dashboard/module.py | 10 +++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 qa/tasks/mgr/dashboard/test_requests.py diff --git a/qa/tasks/mgr/dashboard/test_requests.py b/qa/tasks/mgr/dashboard/test_requests.py new file mode 100644 index 000000000000..0d9f8d9ba836 --- /dev/null +++ b/qa/tasks/mgr/dashboard/test_requests.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +from __future__ import absolute_import + +from .helper import DashboardTestCase + + +class RequestsTest(DashboardTestCase): + def test_gzip(self): + self._get('/api/summary') + self.assertHeaders({ + 'Content-Encoding': 'gzip', + 'Content-Type': 'application/json', + }) + + def test_force_no_gzip(self): + self._get('/api/summary', params=dict( + headers={'Accept-Encoding': 'identity'} + )) + self.assertNotIn('Content-Encoding', self._resp.headers) + self.assertHeaders({ + 'Content-Type': 'application/json', + }) diff --git a/src/pybind/mgr/dashboard/module.py b/src/pybind/mgr/dashboard/module.py index 2140294e5a0f..3045f96054a1 100644 --- a/src/pybind/mgr/dashboard/module.py +++ b/src/pybind/mgr/dashboard/module.py @@ -144,7 +144,15 @@ class CherryPyConfig(object): 'server.socket_host': server_addr, 'server.socket_port': int(server_port), 'error_page.default': json_error_page, - 'tools.request_logging.on': True + 'tools.request_logging.on': True, + 'tools.gzip.on': True, + 'tools.gzip.mime_types': [ + # text/html and text/plain are the default types to compress + 'text/html', 'text/plain', + # We also want JSON and JavaScript to be compressed + 'application/json', + 'application/javascript', + ], } if ssl: -- 2.47.3