feat(api): FAILED_FETCH search

feat(DB): new indexes
This commit is contained in:
Taha Yassine Kraiem 2021-12-31 14:13:13 +01:00
parent 66ce43ea08
commit dcb69816e4
7 changed files with 43 additions and 9 deletions

View file

@ -8,5 +8,7 @@ def get_col(perf: schemas.PerformanceEventType):
schemas.PerformanceEventType.location_avg_cpu_load: {"column": "avg_cpu", "extraJoin": "events.performance"},
schemas.PerformanceEventType.location_avg_memory_usage: {"column": "avg_used_js_heap_size",
"extraJoin": "events.performance"},
schemas.PerformanceEventType.fetch_failed: {"column": "success", "extraJoin": None},
schemas.PerformanceEventType.fetch_duration: {"column": "duration", "extraJoin": None},
# schemas.PerformanceEventType.location_largest_contentful_paint_time: "timestamp"
}.get(perf)

View file

@ -474,6 +474,29 @@ def search2_pg(data: schemas.SessionsSearchPayloadSchema, project_id, user_id, f
event_where.append(
_multiple_conditions(f"(main1.reason {op} %({e_k})s OR main1.name {op} %({e_k})s)",
event.value, value_key=e_k))
elif event_type == schemas.PerformanceEventType.fetch_failed:
event_from = event_from % f"{events.event_type.REQUEST.table} AS main "
if not is_any:
event_where.append(
_multiple_conditions(f"main.{events.event_type.REQUEST.column} {op} %({e_k})s",
event.value, value_key=e_k))
col = performance_event.get_col(event_type)
colname = col["column"]
event_where.append(f"main.{colname} = FALSE")
elif event_type == schemas.PerformanceEventType.fetch_duration:
event_from = event_from % f"{events.event_type.REQUEST.table} AS main "
if not is_any:
event_where.append(
_multiple_conditions(f"main.{events.event_type.REQUEST.column} {op} %({e_k})s",
event.value, value_key=e_k))
col = performance_event.get_col(event_type)
colname = col["column"]
tname = "main"
e_k += "_custom"
full_args = {**full_args, **_multiple_values(event.custom, value_key=e_k)}
event_where.append(f"{tname}.{colname} IS NOT NULL AND {tname}.{colname}>0 AND " +
_multiple_conditions(f"{tname}.{colname} {event.customOperator} %({e_k})s",
event.custom, value_key=e_k))
elif event_type in [schemas.PerformanceEventType.location_dom_complete,
schemas.PerformanceEventType.location_largest_contentful_paint_time,
schemas.PerformanceEventType.location_ttfb,
@ -505,8 +528,10 @@ def search2_pg(data: schemas.SessionsSearchPayloadSchema, project_id, user_id, f
event.value[0].value = [event.value[0].value]
if not isinstance(event.value[1].value, list):
event.value[1].value = [event.value[1].value]
event.value[0].value = helper.values_for_operator(value=event.value[0].value, op=event.value[0].operator)
event.value[1].value = helper.values_for_operator(value=event.value[1].value, op=event.value[0].operator)
event.value[0].value = helper.values_for_operator(value=event.value[0].value,
op=event.value[0].operator)
event.value[1].value = helper.values_for_operator(value=event.value[1].value,
op=event.value[0].operator)
e_k1 = e_k + "_e1"
e_k2 = e_k + "_e2"
full_args = {**full_args,

View file

@ -376,6 +376,8 @@ class PerformanceEventType(str, Enum):
location_ttfb = "TTFB"
location_avg_cpu_load = "AVG_CPU_LOAD"
location_avg_memory_usage = "AVG_MEMORY_USAGE"
fetch_failed = "FETCH_FAILED"
fetch_duration = "FETCH_DURATION"
class FilterType(str, Enum):
@ -457,6 +459,8 @@ class _SessionSearchEventRaw(BaseModel):
@root_validator
def check_card_number_omitted(cls, values):
if isinstance(values.get("type"), PerformanceEventType):
if values.get("type") == PerformanceEventType.fetch_failed:
return values
assert values.get("custom") is not None, "custom should not be None for PerformanceEventType"
assert values.get("customOperator") is not None \
, "customOperator should not be None for PerformanceEventType"

View file

@ -62,8 +62,9 @@ ALTER TABLE sessions
ADD COLUMN utm_medium text NULL DEFAULT NULL,
ADD COLUMN utm_campaign text NULL DEFAULT NULL;
CREATE INDEX sessions_utm_source_gin_idx ON public.sessions USING GIN (utm_source gin_trgm_ops);
CREATE INDEX sessions_utm_medium_gin_idx ON public.sessions USING GIN (utm_medium gin_trgm_ops);
CREATE INDEX sessions_utm_campaign_gin_idx ON public.sessions USING GIN (utm_campaign gin_trgm_ops);
CREATE INDEX IF NOT EXISTS sessions_utm_source_gin_idx ON public.sessions USING GIN (utm_source gin_trgm_ops);
CREATE INDEX IF NOT EXISTS sessions_utm_medium_gin_idx ON public.sessions USING GIN (utm_medium gin_trgm_ops);
CREATE INDEX IF NOT EXISTS sessions_utm_campaign_gin_idx ON public.sessions USING GIN (utm_campaign gin_trgm_ops);
CREATE INDEX IF NOT EXISTS requests_timestamp_session_id_failed_idx ON events_common.requests (timestamp, session_id) WHERE success = FALSE;
COMMIT;

View file

@ -709,6 +709,7 @@ $$
THEN 8
ELSE 0 END))
gin_trgm_ops);
CREATE INDEX requests_timestamp_session_id_failed_idx ON events_common.requests (timestamp, session_id) WHERE success = FALSE;
-- --- events.sql ---
CREATE SCHEMA IF NOT EXISTS events;

View file

@ -12,8 +12,9 @@ ALTER TABLE sessions
ADD COLUMN utm_medium text NULL DEFAULT NULL,
ADD COLUMN utm_campaign text NULL DEFAULT NULL;
CREATE INDEX sessions_utm_source_gin_idx ON public.sessions USING GIN (utm_source gin_trgm_ops);
CREATE INDEX sessions_utm_medium_gin_idx ON public.sessions USING GIN (utm_medium gin_trgm_ops);
CREATE INDEX sessions_utm_campaign_gin_idx ON public.sessions USING GIN (utm_campaign gin_trgm_ops);
CREATE INDEX IF NOT EXISTS sessions_utm_source_gin_idx ON public.sessions USING GIN (utm_source gin_trgm_ops);
CREATE INDEX IF NOT EXISTS sessions_utm_medium_gin_idx ON public.sessions USING GIN (utm_medium gin_trgm_ops);
CREATE INDEX IF NOT EXISTS sessions_utm_campaign_gin_idx ON public.sessions USING GIN (utm_campaign gin_trgm_ops);
CREATE INDEX IF NOT EXISTS requests_timestamp_session_id_failed_idx ON events_common.requests (timestamp, session_id) WHERE success = FALSE;
COMMIT;

View file

@ -672,7 +672,7 @@ $$
THEN 8
ELSE 0 END))
gin_trgm_ops);
CREATE INDEX requests_timestamp_session_id_failed_idx ON events_common.requests (timestamp, session_id) WHERE success = FALSE;
-- --- events.sql ---
CREATE SCHEMA IF NOT EXISTS events;