From fead3df0baccd307d7c79d2c35db786ed6ae64c5 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 8 Jul 2024 10:42:03 +0200 Subject: [PATCH] Apply statsd arg sanitization to all pages The previous sanitization would only run on the `or` portion. --- lib/galaxy/web/framework/middleware/statsd.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/galaxy/web/framework/middleware/statsd.py b/lib/galaxy/web/framework/middleware/statsd.py index d817569f3d8e..01225c9c38aa 100644 --- a/lib/galaxy/web/framework/middleware/statsd.py +++ b/lib/galaxy/web/framework/middleware/statsd.py @@ -28,19 +28,13 @@ def __call__(self, environ, start_response): start_time = time.time() req = self.application(environ, start_response) dt = int((time.time() - start_time) * 1000) - page = ( - environ.get("controller_action_key", None) - or environ.get("PATH_INFO", "NOPATH") - .strip("/") - .replace("/", ".") - .encode("ascii", errors="replace") - .decode() - ) - self.galaxy_stasd_client.timing(page, dt) + page = environ.get("controller_action_key", None) or environ.get("PATH_INFO", "NOPATH") + sanitized_page = page.strip("/").replace("/", ".").encode("ascii", errors="replace").decode() + self.galaxy_stasd_client.timing(sanitized_page, dt) try: times = QUERY_COUNT_LOCAL.times - self.galaxy_stasd_client.timing(f"sql.{page}", sum(times) * 1000.0) - self.galaxy_stasd_client.incr(f"sqlqueries.{page}", len(times)) + self.galaxy_stasd_client.timing(f"sql.{sanitized_page}", sum(times) * 1000.0) + self.galaxy_stasd_client.incr(f"sqlqueries.{sanitized_page}", len(times)) except AttributeError: # Not logging query counts, skip pass