superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [incubator-superset] branch master updated: [sqllab]More granular sqllab logging (#5736)
Date Tue, 11 Sep 2018 15:52:42 GMT
This is an automated email from the ASF dual-hosted git repository.

timi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 9a4bba4  [sqllab]More granular sqllab logging (#5736)
9a4bba4 is described below

commit 9a4bba485afb422734b13ffad991475f51291e99
Author: timifasubaa <30888507+timifasubaa@users.noreply.github.com>
AuthorDate: Tue Sep 11 08:52:37 2018 -0700

    [sqllab]More granular sqllab logging (#5736)
    
    * quote hive column names (#5368)
    
    * create db migration
    
    * use stats_logger timing
    
    * trigger build
---
 superset/sql_lab.py    | 21 +++++++++++++++------
 superset/views/core.py |  8 +++++++-
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/superset/sql_lab.py b/superset/sql_lab.py
index 4612b4e..fff4271 100644
--- a/superset/sql_lab.py
+++ b/superset/sql_lab.py
@@ -76,14 +76,14 @@ def session_scope(nullpool):
 @celery_app.task(bind=True, soft_time_limit=SQLLAB_TIMEOUT)
 def get_sql_results(
     ctask, query_id, rendered_query, return_results=True, store_results=False,
-        user_name=None):
+        user_name=None, start_time=None):
     """Executes the sql query returns the results."""
     with session_scope(not ctask.request.called_directly) as session:
 
         try:
             return execute_sql(
                 ctask, query_id, rendered_query, return_results, store_results, user_name,
-                session=session)
+                session=session, start_time=start_time)
         except Exception as e:
             logging.exception(e)
             stats_logger.incr('error_sqllab_unhandled')
@@ -97,10 +97,13 @@ def get_sql_results(
 
 def execute_sql(
     ctask, query_id, rendered_query, return_results=True, store_results=False,
-    user_name=None, session=None,
+    user_name=None, session=None, start_time=None,
 ):
     """Executes the sql query returns the results."""
-
+    if store_results:
+        # only asynchronous queries
+        stats_logger.timing(
+            'sqllab.query.time_pending', utils.now_as_float() - start_time)
     query = get_query(query_id, session)
     payload = dict(query_id=query_id)
 
@@ -172,11 +175,15 @@ def execute_sql(
         cursor = conn.cursor()
         logging.info('Running query: \n{}'.format(executed_sql))
         logging.info(query.executed_sql)
+        query_start_time = utils.now_as_float()
         db_engine_spec.execute(cursor, query.executed_sql, async_=True)
         logging.info('Handling cursor')
         db_engine_spec.handle_cursor(cursor, query, session)
         logging.info('Fetching data: {}'.format(query.to_dict()))
         data = db_engine_spec.fetch_data(cursor, query.limit)
+        stats_logger.timing(
+            'sqllab.query.time_executing_query',
+            utils.now_as_float() - query_start_time)
     except SoftTimeLimitExceeded as e:
         logging.exception(e)
         if conn is not None:
@@ -225,6 +232,7 @@ def execute_sql(
     if store_results:
         key = '{}'.format(uuid.uuid4())
         logging.info('Storing results in results backend, key: {}'.format(key))
+        write_to_results_backend_start = utils.now_as_float()
         json_payload = json.dumps(
             payload, default=utils.json_iso_dttm_ser, ignore_nan=True)
         cache_timeout = database.cache_timeout
@@ -232,8 +240,9 @@ def execute_sql(
             cache_timeout = config.get('CACHE_DEFAULT_TIMEOUT', 0)
         results_backend.set(key, utils.zlib_compress(json_payload), cache_timeout)
         query.results_key = key
-        query.end_result_backend_time = utils.now_as_float()
-
+        stats_logger.timing(
+            'sqllab.query.results_backend_write',
+            utils.now_as_float() - write_to_results_backend_start)
     session.merge(query)
     session.commit()
 
diff --git a/superset/views/core.py b/superset/views/core.py
index fc9e366..e0260d1 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -2334,7 +2334,12 @@ class Superset(BaseSupersetView):
         if not results_backend:
             return json_error_response("Results backend isn't configured")
 
+        read_from_results_backend_start = utils.now_as_float()
         blob = results_backend.get(key)
+        stats_logger.timing(
+            'sqllab.query.results_backend_read',
+            read_from_results_backend_start - utils.now_as_float(),
+        )
         if not blob:
             return json_error_response(
                 'Data could not be retrieved. '
@@ -2446,7 +2451,8 @@ class Superset(BaseSupersetView):
                     rendered_query,
                     return_results=False,
                     store_results=not query.select_as_cta,
-                    user_name=g.user.username)
+                    user_name=g.user.username,
+                    start_time=utils.now_as_float())
             except Exception as e:
                 logging.exception(e)
                 msg = (


Mime
View raw message