Skip to content

Commit

Permalink
Track both query start time and button push time to track delay (#2502)
Browse files Browse the repository at this point in the history
* Track both query start time and button push time to track delay

* Fix

* Setting the proper precision

* More logging
  • Loading branch information
mistercrunch authored Mar 29, 2017
1 parent f374345 commit 9116766
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ def extra_table_metadata(cls, database, table_name, schema_name):
@classmethod
def handle_cursor(cls, cursor, query, session):
"""Updates progress information"""
logging.info('Polling the cursor for progress')
polled = cursor.poll()
# poll returns dict -- JSON status information or ``None``
# if the query is done
Expand All @@ -383,10 +384,14 @@ def handle_cursor(cls, cursor, query, session):
total_splits = float(stats.get('totalSplits'))
if total_splits and completed_splits:
progress = 100 * (completed_splits / total_splits)
logging.info(
'Query progress: {} / {} '
'splits'.format(completed_splits, total_splits))
if progress > query.progress:
query.progress = progress
session.commit()
time.sleep(1)
logging.info('Polling the cursor for progress')
polled = cursor.poll()

@classmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""query.start_running_time
Revision ID: a6c18f869a4e
Revises: 979c03af3341
Create Date: 2017-03-28 11:28:41.387182
"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = 'a6c18f869a4e'
down_revision = '979c03af3341'



def upgrade():
op.add_column(
'query',
sa.Column('start_running_time',
sa.Numeric(precision=20, scale=6),
nullable=True))


def downgrade():
op.drop_column('query', 'start_running_time')
1 change: 1 addition & 0 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ class Query(Model):
# Using Numeric in place of DateTime for sub-second precision
# stored as seconds since epoch, allowing for milliseconds
start_time = Column(Numeric(precision=3))
start_running_time = Column(Numeric(precision=3))
end_time = Column(Numeric(precision=3))
changed_on = Column(
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=True)
Expand Down
14 changes: 9 additions & 5 deletions superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,17 @@ def handle_error(msg):
handle_error(msg)

query.executed_sql = executed_sql
logging.info("Running query: \n{}".format(executed_sql))
query.status = QueryStatus.RUNNING
query.start_running_time = utils.now_as_float()
session.merge(query)
session.commit()
logging.info("Set query to 'running'")

engine = database.get_sqla_engine(schema=query.schema)
conn = engine.raw_connection()
cursor = conn.cursor()
logging.info("Running query: \n{}".format(executed_sql))
try:
print(query.executed_sql)
logging.info(query.executed_sql)
cursor.execute(
query.executed_sql, **db_engine_spec.cursor_execute_kwargs)
Expand All @@ -118,8 +123,6 @@ def handle_error(msg):
conn.close()
handle_error(db_engine_spec.extract_error_message(e))

query.status = QueryStatus.RUNNING
session.flush()
try:
logging.info("Handling cursor")
db_engine_spec.handle_cursor(cursor, query, session)
Expand Down Expand Up @@ -156,6 +159,7 @@ def handle_error(msg):
schema=database.force_ctas_schema
))
query.end_time = utils.now_as_float()
session.merge(query)
session.flush()

payload = {
Expand All @@ -173,7 +177,7 @@ def handle_error(msg):
results_backend.set(key, zlib.compress(payload))
query.results_key = key

session.flush()
session.merge(query)
session.commit()

if return_results:
Expand Down

0 comments on commit 9116766

Please sign in to comment.