Просмотр исходного кода

HUE-8424 [core] Add options to dump more of rest API response to logs

Chris Conner 7 лет назад
Родитель
Сommit
719cc2fce6

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -300,6 +300,9 @@
   # Comma separated list of users' username that allow to use django debug tool. If it is empty, all users are allowed.
   ## django_debug_tool_users=
 
+  # Number of characters in rest api reponse calls to dump to the logs when debug is enabled. Set to -1 for entire response.
+  ## rest_response_size=2000
+
   # Administrators
   # ----------------
   [[django_admins]]

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -304,6 +304,9 @@
   # Comma separated list of users' username that allow to use django debug tool. If it is empty, all users are allowed.
   ## django_debug_tool_users=
 
+  # Number of characters in rest api reponse calls to dump to the logs when debug is enabled. Set to -1 for entire response.
+  ## rest_response_size=2000
+
   # Administrators
   # ----------------
   [[django_admins]]

+ 6 - 0
desktop/core/src/desktop/conf.py

@@ -397,6 +397,12 @@ COLLECT_USAGE = Config(
   type=coerce_bool,
   default=True)
 
+REST_RESPONSE_SIZE = Config(
+  key="rest_response_size",
+  help=_("Number of characters the rest api reponse calls to dump to the logs when debug is enabled.  Enter -1 for entire response."),
+  type=int,
+  default=2000)
+
 LEAFLET_TILE_LAYER = Config(
   key="leaflet_tile_layer",
   help=_("Tile layer server URL for the Leaflet map charts. Read more on http://leafletjs.com/reference.html#tilelayer. Make sure you add the tile domain to the img-src section of the 'secure_content_security_policy' configuration parameter as well."),

+ 5 - 2
desktop/core/src/desktop/lib/rest/resource.py

@@ -21,6 +21,8 @@ import time
 from desktop.lib.i18n import smart_unicode
 from desktop.lib.apputil import WARN_LEVEL_CALL_DURATION_MS, INFO_LEVEL_CALL_DURATION_MS
 
+from desktop import conf
+
 
 LOG = logging.getLogger(__name__)
 
@@ -97,13 +99,14 @@ class Resource(object):
                                 clear_cookies=clear_cookies)
 
     if log_response:
+      log_length = conf.REST_RESPONSE_SIZE.get() != -1 and conf.REST_RESPONSE_SIZE.get()
       duration = time.time() - start_time
       message = "%s %s Got response%s: %s%s" % (
           method,
           smart_unicode(path, errors='ignore'),
           ' in %dms' % (duration * 1000),
-          smart_unicode(resp.content[:1000], errors='replace'),
-          len(resp.content) > 1000 and "..." or ""
+          smart_unicode(resp.content[:log_length or None], errors='replace'),
+          log_length and len(resp.content) > log_length and "..." or ""
       )
       log_if_slow_call(duration=duration, message=message, logger=self._client.logger)