diff --git a/ee/api/chalicelib/core/custom_metrics.py b/ee/api/chalicelib/core/custom_metrics.py index f7d6964278..a41d4fd9b3 100644 --- a/ee/api/chalicelib/core/custom_metrics.py +++ b/ee/api/chalicelib/core/custom_metrics.py @@ -161,6 +161,10 @@ def __get_table_of_referrers(project_id: int, data: schemas.CardTable, user_id: return __get_table_of_series(project_id=project_id, data=data) +def __get_table_of_requests(project_id: int, data: schemas.CardTable, user_id: int = None): + return __get_table_of_series(project_id=project_id, data=data) + + def __get_table_chart(project_id: int, data: schemas.CardTable, user_id: int): supported = { schemas.MetricOfTable.SESSIONS: __get_table_of_sessions, @@ -172,6 +176,7 @@ def __get_table_chart(project_id: int, data: schemas.CardTable, user_id: int): schemas.MetricOfTable.USER_COUNTRY: __get_table_of_countries, schemas.MetricOfTable.VISITED_URL: __get_table_of_urls, schemas.MetricOfTable.REFERRER: __get_table_of_referrers, + schemas.MetricOfTable.FETCH: __get_table_of_requests } return supported.get(data.metric_of, not_supported)(project_id=project_id, data=data, user_id=user_id) diff --git a/ee/api/chalicelib/core/sessions_exp.py b/ee/api/chalicelib/core/sessions_exp.py index dde34bdc43..2c870be494 100644 --- a/ee/api/chalicelib/core/sessions_exp.py +++ b/ee/api/chalicelib/core/sessions_exp.py @@ -382,6 +382,29 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de if v not in extra_conditions[e.operator].value: extra_conditions[e.operator].value.append(v) extra_conditions = list(extra_conditions.values()) + elif metric_of == schemas.MetricOfTable.FETCH: + extra_event = f"""SELECT DISTINCT ev.session_id, ev.url_path + FROM {exp_ch_helper.get_main_events_table(data.startTimestamp)} AS ev + WHERE ev.datetime >= toDateTime(%(startDate)s / 1000) + AND ev.datetime <= toDateTime(%(endDate)s / 1000) + AND ev.project_id = %(project_id)s + AND ev.event_type = 'REQUEST'""" + extra_deduplication.append("url_path") + extra_conditions = {} + for e in data.events: + if e.type == schemas.EventType.REQUEST_DETAILS: + if e.operator not in extra_conditions: + extra_conditions[e.operator] = schemas.SessionSearchEventSchema2.model_validate({ + "type": e.type, + "isEvent": True, + "value": [], + "operator": e.operator, + "filters": [] + }) + for v in e.value: + if v not in extra_conditions[e.operator].value: + extra_conditions[e.operator].value.append(v) + extra_conditions = list(extra_conditions.values()) elif metric_of == schemas.MetricOfTable.ISSUES and len(metric_value) > 0: data.filters.append(schemas.SessionSearchFilterSchema(value=metric_value, type=schemas.FilterType.ISSUE, @@ -427,6 +450,9 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de elif metric_of == schemas.MetricOfTable.REFERRER: main_col = "referrer" extra_col = ", referrer" + elif metric_of == schemas.MetricOfTable.FETCH: + main_col = "url_path" + extra_col = ", s.url_path" if metric_format == schemas.MetricExtendedFormatType.SESSION_COUNT: main_query = f"""SELECT COUNT(DISTINCT {main_col}) OVER () AS main_count,