Skip to content

Commit

Permalink
fix(chalice): fixed autocomplet-top-values
Browse files Browse the repository at this point in the history
  • Loading branch information
tahayk committed Aug 5, 2024
1 parent e5623c6 commit 5c7e266
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
16 changes: 10 additions & 6 deletions api/chalicelib/core/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ def __search_metadata(project_id, value, key=None, source=None):
TYPE_TO_COLUMN = {
schemas.EventType.CLICK: "label",
schemas.EventType.INPUT: "label",
schemas.EventType.LOCATION: "url_path",
schemas.EventType.LOCATION: "path",
schemas.EventType.CUSTOM: "name",
schemas.EventType.REQUEST: "url_path",
schemas.EventType.GRAPHQL: "name",
schemas.FetchFilterType.FETCH_URL: "path",
schemas.GraphqlFilterType.GRAPHQL_NAME: "name",
schemas.EventType.STATE_ACTION: "name",
# For ERROR, sessions search is happening over name OR message,
# for simplicity top 10 is using name only
Expand All @@ -365,12 +365,16 @@ def __search_metadata(project_id, value, key=None, source=None):
schemas.EventType.INPUT: "events.inputs",
schemas.EventType.LOCATION: "events.pages",
schemas.EventType.CUSTOM: "events_common.customs",
schemas.EventType.REQUEST: "events_common.requests",
schemas.EventType.GRAPHQL: "events.graphql",
schemas.FetchFilterType.FETCH_URL: "events_common.requests",
schemas.GraphqlFilterType.GRAPHQL_NAME: "events.graphql",
schemas.EventType.STATE_ACTION: "events.state_actions",
}


def is_top_supported(event_type):
return TYPE_TO_COLUMN.get(event_type, False)


def get_top_values(project_id, event_type, event_key=None):
with pg_client.PostgresClient() as cur:
if schemas.FilterType.has_value(event_type):
Expand All @@ -393,7 +397,7 @@ def get_top_values(project_id, event_type, event_key=None):
LIMIT 10)
SELECT c_value AS value, row_count, trunc(row_count * 100 / total_count, 2) AS row_percentage
FROM raw;"""
elif event_type==schemas.EventType.ERROR:
elif event_type == schemas.EventType.ERROR:
colname = TYPE_TO_COLUMN.get(event_type)
query = f"""WITH raw AS (SELECT DISTINCT {colname} AS c_value,
COUNT(1) OVER (PARTITION BY {colname}) AS row_count,
Expand Down
6 changes: 3 additions & 3 deletions api/routers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def events_search(projectId: int, q: Optional[str] = None,
key: str = None, source: str = None, live: bool = False,
context: schemas.CurrentContext = Depends(OR_context)):
if type and (not q or len(q) == 0) \
and (schemas.FilterType.has_value(type) or schemas.EventType.has_value(type)):
and (autocomplete.is_top_supported(type)):
# TODO: check if type is a valid value for autocomplete
return autocomplete.get_top_values(project_id=projectId, event_type=type,event_key=key)
elif (not q or len(q) == 0) and not type:
return autocomplete.get_top_values(project_id=projectId, event_type=type, event_key=key)
elif (not q or len(q) == 0):
return {"data": []}

if live:
Expand Down
8 changes: 6 additions & 2 deletions ee/api/chalicelib/core/autocomplete_exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ def __search_metadata(project_id, value, key=None, source=None):
schemas.EventType.INPUT: "label",
schemas.EventType.LOCATION: "url_path",
schemas.EventType.CUSTOM: "name",
schemas.EventType.REQUEST: "url_path",
schemas.EventType.GRAPHQL: "name",
schemas.FetchFilterType.FETCH_URL: "url_path",
schemas.GraphqlFilterType.GRAPHQL_NAME: "name",
schemas.EventType.STATE_ACTION: "name",
# For ERROR, sessions search is happening over name OR message,
# for simplicity top 10 is using name only
Expand All @@ -290,6 +290,10 @@ def __search_metadata(project_id, value, key=None, source=None):
}


def is_top_supported(event_type):
return TYPE_TO_COLUMN.get(event_type, False)


def get_top_values(project_id, event_type, event_key=None):
with ch_client.ClickHouseClient() as cur:
if schemas.FilterType.has_value(event_type):
Expand Down

0 comments on commit 5c7e266

Please sign in to comment.