Skip to content

Commit

Permalink
chore: address PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Mar 18, 2024
1 parent cbf3bf9 commit a8ec751
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tutoraspects/commands_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def alembic(context, command) -> None:
@click.pass_obj
def performance_metrics(context) -> None:
"""
Job to import Superset assets.
Job to measure performance metrics of charts and its queries in Superset and ClickHouse.
"""
config = tutor_config.load(context.root)
runner = context.job_runner(config)
Expand Down
2 changes: 1 addition & 1 deletion tutoraspects/commands_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def import_assets() -> list[tuple[str, str]]:
@click.command(context_settings={"ignore_unknown_options": True})
def performance_metrics() -> list[tuple[str, str]]:
"""
Job to import Superset assets.
Job to measure performance metrics of charts and its queries in Superset and ClickHouse.
"""
return [
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

def performance_metrics():
"""Measure the performance of the dashboard."""
# Mock the client name to identify the queries in the clickhouse system.query_log table by
# by the http_user_agent field.
with patch("clickhouse_connect.common.build_client_name") as mock_build_client_name:
mock_build_client_name.return_value = RUN_ID
embedable_dashboards = {{SUPERSET_EMBEDDABLE_DASHBOARDS}}
Expand All @@ -51,17 +53,17 @@ def performance_metrics():
for dashboard in dashboards:
logger.info(f"Dashboard: {dashboard.slug}")
for slice in dashboard.slices:
result = meassure_chart(slice)
result = measure_chart(slice)
for query in result["queries"]:
# Remove the data from the query to avoid memory issues on large datasets.
query.pop("data")
report.append(result)
return report


def meassure_chart(slice, extra_filters=[]):
def measure_chart(slice, extra_filters=[]):
"""
Meassure the performance of a chart and return the results.
Measure the performance of a chart and return the results.
"""
logger.info(f"Fetching slice data: {slice}")
query_context = json.loads(slice.query_context)
Expand Down Expand Up @@ -107,7 +109,7 @@ def get_query_log_from_clickhouse(report):
)
slice.query_context = json.dumps(query_context)

result = meassure_chart(slice)
result = measure_chart(slice)

clickhouse_queries = {}
for query in result["queries"]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ FROM summary
WHERE
{% raw %}
{% if get_filters('course_name', remove_filter=True) == [] %}
1=1
{% elif filter_values('course_name') != [] %}
course_name in {{ filter_values('course_name') | where_in }}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ FROM summary
where
{% raw %}
{% if get_filters('problem_name_with_location', remove_filter=True) == [] %}
1=1
{% elif filter_values('problem_name_with_location') != [] %}
problem_name_with_location in {{ filter_values('problem_name_with_location') | where_in }}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ with grades as (
grade_type = 'problem'

{% raw %}
{% if get_filters('problem_name_with_location', remove_filter=True) != [] %}
{% if get_filters('problem_name_with_location', remove_filter=True) == [] %}
{% elif filter_values('problem_name_with_location') != [] %}
and entity_name_with_location in {{ filter_values('problem_name_with_location', remove_filter=True) | where_in }}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ from
where
{% raw %}
{% if get_filters('problem_name_with_location', remove_filter=True) == [] %}
1=1
{% elif filter_values('problem_name_with_location') != [] %}
problem_name_with_location in {{ filter_values('problem_name_with_location') | where_in }}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from {{ DBT_PROFILE_TARGET_DATABASE }}.fact_transcript_usage
where
{% raw %}
{% if get_filters('course_name', remove_filter=True) == [] %}
1=1
{% elif filter_values('course_name') != [] %}
course_name in {{ filter_values('course_name') | where_in }}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from {{ DBT_PROFILE_TARGET_DATABASE }}.fact_video_plays
where
{% raw %}
{% if get_filters('course_name', remove_filter=True) == [] %}
1=1
{% elif filter_values('course_name') != [] %}
course_name in {{ filter_values('course_name') | where_in }}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ from enriched_segments
where
{% raw %}
{% if get_filters('video_name_with_location', remove_filter=True) == [] %}
1=1
{% elif filter_values('video_name_with_location') != [] %}
video_name_with_location in {{ filter_values('video_name_with_location') | where_in }}
{% else %}
Expand Down

0 comments on commit a8ec751

Please sign in to comment.