Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track both query start time and button push time to track delay #2502

Merged
merged 4 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,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 @@ -379,10 +380,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