Skip to content

Commit

Permalink
feat(metrics): add organization filter option
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Sep 30, 2024
1 parent 4cb45ad commit f5a7533
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions tutoraspects/commands_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def init_clickhouse() -> list[tuple[str, str]]:

# Ex: "tutor local do performance-metrics "
@click.command(context_settings={"ignore_unknown_options": True})
@click.option(
"--org",
default="",
help="An organization to apply as a filter.",
)
@click.option(
"--course_name",
default="",
Expand All @@ -169,12 +174,14 @@ def init_clickhouse() -> list[tuple[str, str]]:
"--fail_on_error", is_flag=True, default=False, help="Allow errors to fail the run."
)
def performance_metrics(
course_name, dashboard_slug, slice_name, print_sql, fail_on_error
org, course_name, dashboard_slug, slice_name, print_sql, fail_on_error
) -> (list)[tuple[str, str]]:
"""
Job to measure performance metrics of charts and its queries in Superset and ClickHouse.
"""
options = f"--course_name '{course_name}'" if course_name else ""
options = ""
options += f"--org '{org}' " if org else ""
options += f"--course_name '{course_name}' " if course_name else ""
options += f" --dashboard_slug {dashboard_slug}" if dashboard_slug else ""
options += f' --slice_name "{slice_name}"' if slice_name else ""
options += " --print_sql" if print_sql else ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
)

@click.command()
@click.option(
"--org",
default="",
help="An organization to apply as a filter.")
@click.option(
"--course_name",
default="",
Expand All @@ -71,7 +75,7 @@
@click.option(
"--fail_on_error", is_flag=True, default=False, help="Allow errors to fail the run."
)
def performance_metrics(course_name, dashboard_slug, slice_name, print_sql,
def performance_metrics(org, course_name, dashboard_slug, slice_name, print_sql,
fail_on_error):
"""
Measure the performance of the dashboard.
Expand All @@ -81,6 +85,8 @@ def performance_metrics(course_name, dashboard_slug, slice_name, print_sql,
extra_filters = []
if course_name:
extra_filters += [{"col": "course_name", "op": "IN", "val": course_name}]
if org:
extra_filters += [{"col": "org", "op": "IN", "val": org}]

with patch("clickhouse_connect.common.build_client_name") as mock_build_client_name:
mock_build_client_name.return_value = RUN_ID
Expand Down

0 comments on commit f5a7533

Please sign in to comment.