Skip to content

Commit

Permalink
feat(chalice): table of requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tahayk committed Aug 12, 2024
1 parent 31d1394 commit 5cdd8eb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/chalicelib/core/custom_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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 @@ -152,6 +156,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
21 changes: 21 additions & 0 deletions api/chalicelib/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,23 @@ 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 = "events_common.requests"
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 @@ -360,6 +377,10 @@ 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 = "path"
extra_col = ", path"
distinct_on += ",path"

if metric_format == schemas.MetricExtendedFormatType.SESSION_COUNT:
main_query = f"""SELECT COUNT(*) AS count,
Expand Down
2 changes: 1 addition & 1 deletion api/or_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def custom_route_handler(request: Request) -> Response:
response: Response = await original_route_handler(request)
except RequestValidationError as exc:
# 422 validation exception
logger.warning(f"422 exception when calling: {request.method} {request.url}")
logger.warning(f"!!! 422 exception when calling: {request.method} {request.url}")
logger.warning(exc.errors())
raise exc
except HTTPException as e:
Expand Down
1 change: 1 addition & 0 deletions api/schemas/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ class MetricOfTable(str, Enum):
SESSIONS = "sessions"
ERRORS = "jsException"
REFERRER = "referrer"
FETCH = EventType.REQUEST_DETAILS.value


class MetricOfTimeseries(str, Enum):
Expand Down
2 changes: 1 addition & 1 deletion ee/api/or_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def custom_route_handler(request: Request) -> Response:
response: Response = await original_route_handler(request)
except RequestValidationError as exc:
# 422 validation exception
logger.warning(f"422 exception when calling: {request.method} {request.url}")
logger.warning(f"!!! 422 exception when calling: {request.method} {request.url}")
logger.warning(exc.errors())
raise exc
except HTTPException as e:
Expand Down

0 comments on commit 5cdd8eb

Please sign in to comment.