From fa7a57eb3f369c157586a5c86303d0d58015a9f8 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Thu, 9 Jun 2022 13:42:52 +0200 Subject: [PATCH] feat(api): changed slowest_domains response --- api/chalicelib/core/metrics.py | 4 ++-- ee/api/chalicelib/core/metrics.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/chalicelib/core/metrics.py b/api/chalicelib/core/metrics.py index 05c5233f8..fd5809d06 100644 --- a/api/chalicelib/core/metrics.py +++ b/api/chalicelib/core/metrics.py @@ -1721,7 +1721,7 @@ def get_slowest_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1), with pg_client.PostgresClient() as cur: pg_query = f"""SELECT resources.url_host AS domain, - AVG(resources.duration) AS avg + AVG(resources.duration) AS value FROM events.resources INNER JOIN sessions USING (session_id) WHERE {" AND ".join(pg_sub_query)} GROUP BY resources.url_host @@ -1740,7 +1740,7 @@ def get_slowest_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1), avg = cur.fetchone()["avg"] else: avg = 0 - return {"avg": avg, "partition": rows} + return {"value": avg, "chart": rows, "unit": schemas.TemplatePredefinedUnits.millisecond} def get_errors_per_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1), diff --git a/ee/api/chalicelib/core/metrics.py b/ee/api/chalicelib/core/metrics.py index 2d6aa7201..5c4db36f1 100644 --- a/ee/api/chalicelib/core/metrics.py +++ b/ee/api/chalicelib/core/metrics.py @@ -1661,7 +1661,7 @@ def get_slowest_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1), with ch_client.ClickHouseClient() as ch: ch_query = f"""SELECT resources.url_host AS domain, - COALESCE(avgOrNull(resources.duration),0) AS avg + COALESCE(avgOrNull(resources.duration),0) AS value FROM resources {"INNER JOIN sessions_metadata USING(session_id)" if len(meta_condition) > 0 else ""} WHERE {" AND ".join(ch_sub_query)} GROUP BY resources.url_host @@ -1675,7 +1675,7 @@ def get_slowest_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1), FROM resources {"INNER JOIN sessions_metadata USING(session_id)" if len(meta_condition) > 0 else ""} WHERE {" AND ".join(ch_sub_query)};""" avg = ch.execute(query=ch_query, params=params)[0]["avg"] if len(rows) > 0 else 0 - return {"avg": avg, "partition": rows} + return {"value": avg, "chart": rows, "unit": schemas.TemplatePredefinedUnits.millisecond} def get_errors_per_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1),