diff --git a/api/chalicelib/core/custom_metrics.py b/api/chalicelib/core/custom_metrics.py index 0ea0aeca6..6933fed76 100644 --- a/api/chalicelib/core/custom_metrics.py +++ b/api/chalicelib/core/custom_metrics.py @@ -48,7 +48,7 @@ def __get_funnel_chart(project_id: int, data: schemas.CardFunnel, user_id: int = return funnels.get_top_insights_on_the_fly_widget(project_id=project_id, data=data.series[0].filter, - metric_of=data.metric_of) + metric_format=data.metric_format) def __get_errors_list(project_id, user_id, data: schemas.CardSchema): diff --git a/api/chalicelib/core/funnels.py b/api/chalicelib/core/funnels.py index 39400ed08..427bc996b 100644 --- a/api/chalicelib/core/funnels.py +++ b/api/chalicelib/core/funnels.py @@ -37,20 +37,20 @@ def __fix_stages(f_events: List[schemas.SessionSearchEventSchema2]): # def get_top_insights_on_the_fly_widget(project_id, data: schemas.FunnelInsightsPayloadSchema): def get_top_insights_on_the_fly_widget(project_id, data: schemas.CardSeriesFilterSchema, - metric_of: schemas.MetricOfFunnels): + metric_format: schemas.MetricExtendedFormatType): data.events = filter_stages(__parse_events(data.events)) data.events = __fix_stages(data.events) if len(data.events) == 0: return {"stages": [], "totalDropDueToIssues": 0} insights, total_drop_due_to_issues = significance.get_top_insights(filter_d=data, project_id=project_id, - metric_of=metric_of) + metric_format=metric_format) insights = helper.list_to_camel_case(insights) if len(insights) > 0: - if metric_of == schemas.MetricOfFunnels.SESSION_COUNT and total_drop_due_to_issues > ( + if metric_format == schemas.MetricFormatType.SESSION_COUNT and total_drop_due_to_issues > ( insights[0]["sessionsCount"] - insights[-1]["sessionsCount"]): total_drop_due_to_issues = insights[0]["sessionsCount"] - insights[-1]["sessionsCount"] - elif metric_of == schemas.MetricOfFunnels.USER_COUNT and total_drop_due_to_issues > ( + elif metric_format == schemas.MetricExtendedFormatType.USER_COUNT and total_drop_due_to_issues > ( insights[0]["usersCount"] - insights[-1]["usersCount"]): total_drop_due_to_issues = insights[0]["usersCount"] - insights[-1]["usersCount"] insights[-1]["dropDueToIssues"] = total_drop_due_to_issues diff --git a/api/chalicelib/core/significance.py b/api/chalicelib/core/significance.py index 42da350ae..93520e410 100644 --- a/api/chalicelib/core/significance.py +++ b/api/chalicelib/core/significance.py @@ -431,9 +431,10 @@ def count_users(rows, n_stages, user_key="user_uuid"): return users_count -def get_stages(stages, rows, metric_of=schemas.MetricOfFunnels.SESSION_COUNT): +def get_stages(stages, rows, + metric_format: schemas.MetricExtendedFormatType = schemas.MetricExtendedFormatType.SESSION_COUNT): n_stages = len(stages) - if metric_of == "sessionCount": + if metric_format == schemas.MetricExtendedFormatType.SESSION_COUNT: base_counts = count_sessions(rows, n_stages) else: base_counts = count_users(rows, n_stages, user_key="user_id") @@ -456,7 +457,7 @@ def get_stages(stages, rows, metric_of=schemas.MetricOfFunnels.SESSION_COUNT): "dropDueToIssues": 0 } ) - if metric_of == "sessionCount": + if metric_format == schemas.MetricExtendedFormatType.SESSION_COUNT: stages_list[-1]["sessionsCount"] = base_counts[i + 1] else: stages_list[-1]["usersCount"] = base_counts[i + 1] @@ -543,7 +544,8 @@ def get_issues(stages, rows, first_stage=None, last_stage=None, drop_only=False) return n_critical_issues, issues_dict, total_drop_due_to_issues -def get_top_insights(filter_d: schemas.CardSeriesFilterSchema, project_id, metric_of: schemas.MetricOfFunnels): +def get_top_insights(filter_d: schemas.CardSeriesFilterSchema, project_id, + metric_format: schemas.MetricExtendedFormatType): output = [] stages = filter_d.events @@ -554,7 +556,7 @@ def get_top_insights(filter_d: schemas.CardSeriesFilterSchema, project_id, metri # The result of the multi-stage query rows = get_stages_and_events(filter_d=filter_d, project_id=project_id) # Obtain the first part of the output - stages_list = get_stages(stages, rows, metric_of=metric_of) + stages_list = get_stages(stages, rows, metric_format=metric_format) if len(rows) == 0: return stages_list, 0 diff --git a/api/env.default b/api/env.default index 7351d6352..9866fe334 100644 --- a/api/env.default +++ b/api/env.default @@ -33,7 +33,7 @@ JWT_REFRESH_SECRET="SET A RANDOM STRING HERE" JWT_SPOT_REFRESH_EXPIRATION=604800 JWT_SPOT_REFRESH_SECRET="SET A RANDOM STRING HERE" JWT_SPOT_SECRET=SECRET -JWT_SPOT_EXPIRATION=300 +JWT_SPOT_EXPIRATION=3600 jwt_secret="SET A RANDOM STRING HERE" pg_dbname=postgres pg_host=postgresql.db.svc.cluster.local diff --git a/api/schemas/schemas.py b/api/schemas/schemas.py index af213f97e..ef9bd8df6 100644 --- a/api/schemas/schemas.py +++ b/api/schemas/schemas.py @@ -998,7 +998,7 @@ class MetricOfWebVitals(str, Enum): AVG_VISITED_PAGES = "avgVisitedPages" COUNT_REQUESTS = "countRequests" COUNT_SESSIONS = "countSessions" - COUNT_USERS = "countUsers" + COUNT_USERS = "userCount" class MetricOfTable(str, Enum): @@ -1024,7 +1024,6 @@ class MetricOfTimeseries(str, Enum): class MetricOfFunnels(str, Enum): SESSION_COUNT = MetricOfTimeseries.SESSION_COUNT.value - USER_COUNT = MetricOfTimeseries.USER_COUNT.value class MetricOfHeatMap(str, Enum): @@ -1179,7 +1178,8 @@ class CardTable(__CardSchema): def __validator(self): if self.metric_of not in (MetricOfTable.ISSUES, MetricOfTable.USER_BROWSER, MetricOfTable.USER_DEVICE, MetricOfTable.USER_COUNTRY, - MetricOfTable.VISITED_URL): + MetricOfTable.VISITED_URL, MetricOfTable.REFERRER, + MetricOfTable.FETCH): assert self.metric_format == MetricExtendedFormatType.SESSION_COUNT, \ f'metricFormat:{MetricExtendedFormatType.USER_COUNT.value} is not supported for this metricOf' return self @@ -1189,6 +1189,7 @@ class CardFunnel(__CardSchema): metric_type: Literal[MetricType.FUNNEL] metric_of: MetricOfFunnels = Field(default=MetricOfFunnels.SESSION_COUNT) view_type: MetricOtherViewType = Field(...) + metric_format: MetricExtendedFormatType = Field(default=MetricExtendedFormatType.SESSION_COUNT) @model_validator(mode="before") @classmethod diff --git a/ee/api/chalicelib/core/custom_metrics.py b/ee/api/chalicelib/core/custom_metrics.py index a41d4fd9b..bc39458d6 100644 --- a/ee/api/chalicelib/core/custom_metrics.py +++ b/ee/api/chalicelib/core/custom_metrics.py @@ -59,7 +59,7 @@ def __get_funnel_chart(project_id: int, data: schemas.CardFunnel, user_id: int = return funnels.get_top_insights_on_the_fly_widget(project_id=project_id, data=data.series[0].filter, - metric_of=data.metric_of) + metric_format=data.metric_format) def __get_errors_list(project_id, user_id, data: schemas.CardSchema): diff --git a/ee/api/chalicelib/core/sessions_exp.py b/ee/api/chalicelib/core/sessions_exp.py index 2c870be49..8798d67f1 100644 --- a/ee/api/chalicelib/core/sessions_exp.py +++ b/ee/api/chalicelib/core/sessions_exp.py @@ -469,8 +469,7 @@ def search2_table(data: schemas.SessionsSearchPayloadSchema, project_id: int, de main_query = f"""SELECT COUNT(DISTINCT {main_col}) OVER () AS main_count, {main_col} AS name, count(DISTINCT user_id) AS user_count - FROM (SELECT s.user_id AS user_id, - {extra_col} + FROM (SELECT s.user_id AS user_id {extra_col} {query_part} WHERE isNotNull(user_id) AND user_id != '') AS filtred_sessions diff --git a/ee/api/env.default b/ee/api/env.default index baad697cd..a42af2955 100644 --- a/ee/api/env.default +++ b/ee/api/env.default @@ -51,7 +51,7 @@ JWT_REFRESH_SECRET="SET A RANDOM STRING HERE" JWT_SPOT_REFRESH_EXPIRATION=604800 JWT_SPOT_REFRESH_SECRET="SET A RANDOM STRING HERE" JWT_SPOT_SECRET=SECRET -JWT_SPOT_EXPIRATION=300 +JWT_SPOT_EXPIRATION=3600 jwt_secret="SET A RANDOM STRING HERE" KAFKA_SERVERS=kafka.db.svc.cluster.local:9092 KAFKA_USE_SSL=false