From 8c7c25e7cd1af4346e473217227eb7d1e74011b0 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Wed, 24 Aug 2022 14:39:52 +0100 Subject: [PATCH] feat(chalice): changed errors_per_domains to use requests only instead of all resources --- api/chalicelib/core/metrics.py | 10 +++++----- ee/api/chalicelib/core/metrics_new.py | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api/chalicelib/core/metrics.py b/api/chalicelib/core/metrics.py index d5fe5db52..9a0d213cf 100644 --- a/api/chalicelib/core/metrics.py +++ b/api/chalicelib/core/metrics.py @@ -1719,15 +1719,15 @@ def get_slowest_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1), def get_errors_per_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1), endTimestamp=TimeUTC.now(), **args): pg_sub_query = __get_constraints(project_id=project_id, data=args) - pg_sub_query.append("resources.success = FALSE") + pg_sub_query.append("requests.success = FALSE") with pg_client.PostgresClient() as cur: pg_query = f"""SELECT - resources.url_host AS domain, - COUNT(resources.session_id) AS errors_count - FROM events.resources INNER JOIN sessions USING (session_id) + requests.host AS domain, + COUNT(requests.session_id) AS errors_count + FROM events_common.requests INNER JOIN sessions USING (session_id) WHERE {" AND ".join(pg_sub_query)} - GROUP BY resources.url_host + GROUP BY requests.host ORDER BY errors_count DESC LIMIT 5;""" cur.execute(cur.mogrify(pg_query, {"project_id": project_id, diff --git a/ee/api/chalicelib/core/metrics_new.py b/ee/api/chalicelib/core/metrics_new.py index 4086f99b8..a4a2955ef 100644 --- a/ee/api/chalicelib/core/metrics_new.py +++ b/ee/api/chalicelib/core/metrics_new.py @@ -1684,19 +1684,19 @@ def get_slowest_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1), def get_errors_per_domains(project_id, startTimestamp=TimeUTC.now(delta_days=-1), endTimestamp=TimeUTC.now(), **args): - raise Exception("not supported widget") - ch_sub_query = __get_basic_constraints(table_name="resources", data=args) - ch_sub_query.append("resources.success = 0") + ch_sub_query = __get_basic_constraints(table_name="requests", data=args) + ch_sub_query.append("requests.event_type = 'REQUEST'") + ch_sub_query.append("requests.success = 0") meta_condition = __get_meta_constraint(args) ch_sub_query += meta_condition with ch_client.ClickHouseClient() as ch: ch_query = f"""SELECT - resources.url_host AS domain, - COUNT(resources.session_id) AS errors_count - FROM resources {"INNER JOIN sessions_metadata USING(session_id)" if len(meta_condition) > 0 else ""} + requests.url_host AS domain, + COUNT(requests.session_id) AS errors_count + FROM {sessions_helper.get_main_events_table(startTimestamp)} AS requests WHERE {" AND ".join(ch_sub_query)} - GROUP BY resources.url_host + GROUP BY requests.url_host ORDER BY errors_count DESC LIMIT 5;""" rows = ch.execute(query=ch_query,