Skip to content

Commit

Permalink
feat(chalice): table of requests CH
Browse files Browse the repository at this point in the history
  • Loading branch information
tahayk committed Aug 12, 2024
1 parent 5cdd8eb commit b73022e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ee/api/chalicelib/core/custom_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down
26 changes: 26 additions & 0 deletions ee/api/chalicelib/core/sessions_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b73022e

Please sign in to comment.