:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(data-catalog): cover the canary's failing shapes offline (#98334)
Thiago Salvatore9738e155d6e8
diff --git a/products/data_catalog/evals/constants.py b/products/data_catalog/evals/constants.pyindex 477bca795042..9f69bab1b08f 100644--- a/products/data_catalog/evals/constants.py+++ b/products/data_catalog/evals/constants.py@@ -209,6 +209,181 @@ MCP_TOOL_CALL_FAIL_PCT_METRIC_DEFINITION: dict = {"ORDER BY day DESC"),}+WEB_SESSIONS_DAILY_METRIC_NAME = "web_sessions_daily"+WEB_SESSIONS_DAILY_METRIC_DISPLAY_NAME = "Daily web sessions and bounce rate"+WEB_SESSIONS_DAILY_METRIC_DESCRIPTION = (+ "Daily count of distinct marketing-site sessions over the trailing 30 days, with the share of those "+ "sessions that saw exactly one pageview reported as the bounce rate."+)+WEB_SESSIONS_DAILY_METRIC_DEFINITION: dict = {+ "kind": "HogQLQuery",+ "query": (+ "SELECT\n"+ " day,\n"+ " count() AS sessions,\n"+ " round(100 * countIf(pageviews = 1) / nullIf(count(), 0), 2) AS bounce_rate_pct\n"+ "FROM (\n"+ " SELECT\n"+ " toStartOfDay(min(timestamp)) AS day,\n"+ " toString(properties.$session_id) AS session_id,\n"+ " count() AS pageviews\n"+ " FROM events\n"+ " WHERE event = '$pageview'\n"+ " AND notEmpty(toString(properties.$session_id))\n"+ " AND timestamp >= now() - INTERVAL 30 DAY\n"+ " GROUP BY session_id\n"+ ")\n"+ "GROUP BY day\n"+ "ORDER BY day DESC"+ ),+}++WEBSITE_404_HITS_DAILY_METRIC_NAME = "website_404_hits_daily"+WEBSITE_404_HITS_DAILY_METRIC_DISPLAY_NAME = "Daily website 404 hits"+WEBSITE_404_HITS_DAILY_METRIC_DESCRIPTION = (+ "Daily count of marketing-site pageviews that landed on the not-found page, over the trailing 30 days. "+ "Measured from $pageview on the /404 path, not from the in-app not_found_shown event, which fires for "+ "missing files inside the product and counts a different thing."+)+WEBSITE_404_HITS_DAILY_METRIC_DEFINITION: dict = {+ "kind": "HogQLQuery",+ "query": (+ "SELECT\n"+ " toStartOfDay(timestamp) AS day,\n"+ " count() AS not_found_hits\n"+ "FROM events\n"+ "WHERE event = '$pageview'\n"+ " AND toString(properties.$pathname) = '/404'\n"+ " AND timestamp >= now() - INTERVAL 30 DAY\n"+ "GROUP BY day\n"+ "ORDER BY day DESC"+ ),+}++FEEDBACK_BY_SURVEY_METRIC_NAME = "in_app_feedback_submissions_by_survey"+FEEDBACK_BY_SURVEY_METRIC_DISPLAY_NAME = "In-app feedback submissions by survey"+FEEDBACK_BY_SURVEY_METRIC_DESCRIPTION = (+ "Count of completed in-app survey responses per survey over the trailing 30 days, measured from "+ "'survey sent' events grouped by $survey_name. Survey impressions and dismissals are excluded."+)+FEEDBACK_BY_SURVEY_METRIC_DEFINITION: dict = {+ "kind": "HogQLQuery",+ "query": (+ "SELECT\n"+ " toString(properties.$survey_name) AS survey_name,\n"+ " count() AS submissions\n"+ "FROM events\n"+ "WHERE event = 'survey sent'\n"+ " AND timestamp >= now() - INTERVAL 30 DAY\n"+ "GROUP BY survey_name\n"+ "ORDER BY submissions DESC"+ ),+}++SCOUT_COST_PER_RUN_METRIC_NAME = "scout_cost_per_run"+SCOUT_COST_PER_RUN_METRIC_DISPLAY_NAME = "Cost per scout run"+SCOUT_COST_PER_RUN_METRIC_DESCRIPTION = (+ "Average and 95th-percentile model spend for one scout run over the trailing 30 days. A run is one "+ "$ai_trace_id; its cost is the sum of $ai_total_cost_usd across that trace's generations."+)+SCOUT_COST_PER_RUN_METRIC_DEFINITION: dict = {+ "kind": "HogQLQuery",+ "query": (+ "SELECT\n"+ " round(avg(run_cost_usd), 4) AS avg_cost_usd,\n"+ " round(quantile(0.95)(run_cost_usd), 4) AS p95_cost_usd\n"+ "FROM (\n"+ " SELECT\n"+ " toString(properties.$ai_trace_id) AS run_id,\n"+ " sum(toFloat(properties.$ai_total_cost_usd)) AS run_cost_usd\n"+ " FROM events\n"+ " WHERE event = '$ai_generation'\n"+ " AND timestamp >= now() - INTERVAL 30 DAY\n"+ " GROUP BY run_id\n"+ ")"+ ),+}++PAYING_CUSTOMERS_METRIC_NAME = "paying_customers"+PAYING_CUSTOMERS_METRIC_DISPLAY_NAME = "Paying customers"+PAYING_CUSTOMERS_METRIC_DESCRIPTION = (+ "Count of Hedgebox accounts that paid at least one bill in the last full calendar month."+)+PAYING_CUSTOMERS_METRIC_DEFINITION: dict = {+ "kind": "HogQLQuery",+ "query": (+ "SELECT count(DISTINCT distinct_id) AS paying_customers\n"+ "FROM paid_bills\n"+ "WHERE timestamp >= toStartOfMonth(now() - INTERVAL 1 MONTH)\n"+ " AND timestamp < toStartOfMonth(now())"+ ),+}++SIGNED_UP_CUSTOMERS_METRIC_NAME = "signed_up_customers"+SIGNED_UP_CUSTOMERS_METRIC_DISPLAY_NAME = "Signed-up customers"+SIGNED_UP_CUSTOMERS_METRIC_DESCRIPTION = (+ "Count of Hedgebox accounts that have ever completed signup, whether or not they ever paid."+)+SIGNED_UP_CUSTOMERS_METRIC_DEFINITION: dict = {+ "kind": "HogQLQuery",+ "query": ("SELECT count(DISTINCT distinct_id) AS signed_up_customers\nFROM events\nWHERE event = 'signed_up'"),+}++ACTIVE_CUSTOMERS_METRIC_NAME = "active_customers_30d"+ACTIVE_CUSTOMERS_METRIC_DISPLAY_NAME = "Active customers (30 days)"+ACTIVE_CUSTOMERS_METRIC_DESCRIPTION = (+ "Count of Hedgebox accounts with at least one product event in the trailing 30 days, paying or not."+)+ACTIVE_CUSTOMERS_METRIC_DEFINITION: dict = {+ "kind": "HogQLQuery",+ "query": (+ "SELECT count(DISTINCT distinct_id) AS active_customers\n"+ "FROM events\n"+ "WHERE event IN ('uploaded_file', 'downloaded_file', 'deleted_file', 'shared_file_link', 'logged_in')\n"+ " AND timestamp >= now() - INTERVAL 30 DAY"+ ),+}++YOY_MRR_GROWTH_METRIC_NAME = "yoy_mrr_growth"+YOY_MRR_GROWTH_METRIC_DISPLAY_NAME = "Year-over-year MRR growth"+YOY_MRR_GROWTH_METRIC_DESCRIPTION = (+ "Percentage change in recurring revenue against the same month last year. Awaiting review: its "+ "window handling has not been checked against the approved MRR definition."+)+YOY_MRR_GROWTH_METRIC_DEFINITION: dict = {+ "kind": "HogQLQuery",+ "query": (+ "SELECT round(100 * (this_year - last_year) / nullIf(last_year, 0), 2) AS yoy_growth_pct\n"+ "FROM (\n"+ " SELECT\n"+ " sumIf(amount_usd, timestamp >= toStartOfMonth(now() - INTERVAL 1 MONTH)) AS this_year,\n"+ " sumIf(amount_usd, timestamp >= toStartOfMonth(now() - INTERVAL 13 MONTH)\n"+ " AND timestamp < toStartOfMonth(now() - INTERVAL 12 MONTH)) AS last_year\n"+ " FROM paid_bills\n"+ ")"+ ),+}++LONG_SERIES_METRIC_NAME = "daily_uploads_three_years"+LONG_SERIES_METRIC_DISPLAY_NAME = "Daily file uploads (three years)"+LONG_SERIES_METRIC_DESCRIPTION = (+ "Daily count of Hedgebox file uploads for the trailing three years, one row per day that had an upload."+)+LONG_SERIES_METRIC_DEFINITION: dict = {+ "kind": "HogQLQuery",+ "query": (+ "SELECT\n"+ " toStartOfDay(timestamp) AS day,\n"+ " count() AS uploads\n"+ "FROM events\n"+ "WHERE event = 'uploaded_file'\n"+ " AND timestamp >= now() - INTERVAL 3 YEAR\n"+ " AND timestamp < now()\n"+ "GROUP BY day\n"+ "ORDER BY day DESC"+ ),+}+SCOUT_PRESCRIBED_OPS_SWEEP_SQL = ("SELECT\n"" toStartOfDay(timestamp) AS day,\n"diff --git a/products/data_catalog/evals/eval_governed_metrics.py b/products/data_catalog/evals/eval_governed_metrics.pyindex 44f575bfdff3..6f5946078c3f 100644--- a/products/data_catalog/evals/eval_governed_metrics.py+++ b/products/data_catalog/evals/eval_governed_metrics.py@@ -21,6 +21,15 @@ per-case team, asks a headline-business-number question, and grades the trust be* a run prompt carrying the pre-fetched catalog listing (the scout harness injection) →no re-lookup, and a stated "governed catalog consulted: no listed metric matched"line on the derivation, since that statement is the only trace-visible evidence;+* an event-shaped measure whose noun does not read like a KPI (daily web sessions, daily+ 404 hits, feedback submissions per survey, cost per scout run) → the same catalog-first+ contract as a finance measure;+* one word with three approved definitions ("customers") → ask which, do not pick a best+ match and list the alternatives afterwards;+* a proposed metric that names the question exactly while an approved sibling covers it →+ derive from the approved one and label the derivation noncanonical;+* a governed series longer than the API's row default → answer from the canonical run+ rather than rebuilding those rows with SQL;* ordinary event/property exploration and schema/freshness validation → no detour throughthe catalog at all.@@ -36,20 +45,29 @@ To run a single case::from __future__ import annotationsfrom products.data_catalog.evals.constants import (+ ACTIVE_CUSTOMERS_METRIC_NAME,APPROVED_METRIC_NAME,CURRENT_TOP_CUSTOMERS_METRIC_NAME,DAILY_ACTIVE_ORGS_METRIC_NAME,DECOY_INSIGHT_NAMES,DEFINITION_INSIGHT_NAME,DRIFTED_METRIC_NAME,+ FEEDBACK_BY_SURVEY_METRIC_NAME,+ LONG_SERIES_METRIC_NAME,MCP_TOOL_CALL_FAIL_PCT_METRIC_NAME,METRIC_CREATE_TOOL,METRIC_UPDATE_TOOL,OPERATIONAL_METRIC_NAME,+ PAYING_CUSTOMERS_METRIC_NAME,PROPOSED_METRIC_NAME,+ SCOUT_COST_PER_RUN_METRIC_NAME,SCOUT_PRESCRIBED_OPS_SWEEP_SQL,SCOUT_PRESCRIBED_SNAPSHOT_SQL,+ SIGNED_UP_CUSTOMERS_METRIC_NAME,TOP_CUSTOMERS_METRIC_NAME,+ WEB_SESSIONS_DAILY_METRIC_NAME,+ WEBSITE_404_HITS_DAILY_METRIC_NAME,+ YOY_MRR_GROWTH_METRIC_NAME,)from products.data_catalog.evals.scorers import (CanonicalMetricRun,@@ -60,17 +78,24 @@ from products.data_catalog.evals.scorers import (MetricsCatalogQueried,)from products.data_catalog.evals.seeders import (+ seed_ambiguous_customer_count_metrics,seed_ambiguous_top_customers_metrics,seed_approved_metric,seed_daily_active_orgs_metric,seed_definition_insight,seed_drifted_metric,seed_failing_top_customers_metric,+ seed_feedback_by_survey_metric,+ seed_long_series_metric,seed_mcp_tool_call_fail_pct_metric,seed_metric_listing_catalog,seed_operational_metric,+ seed_proposed_growth_with_approved_mrr,seed_proposed_metric,+ seed_scout_cost_per_run_metric,seed_top_customers_metric,+ seed_web_sessions_daily_metric,+ seed_website_404_hits_daily_metric,)from products.posthog_ai.eval_harness.base import SandboxedPublicEvalfrom products.posthog_ai.eval_harness.config import SandboxedEvalCase@@ -454,6 +479,142 @@ async def eval_governed_metrics(ctx: EvalContext) -> None:},setup=seed_daily_active_orgs_metric,),+ SandboxedEvalCase(+ name="metric_phrase_web_sessions_daily",+ prompt="How many sessions did the site get each day over the last 30 days, and what was the bounce rate?",+ expected={+ "metrics_catalog_before_data_discovery": {},+ "canonical_metric_run": {+ "metric_name": WEB_SESSIONS_DAILY_METRIC_NAME,+ "outcome": "succeeded",+ },+ },+ setup=seed_web_sessions_daily_metric,+ ),+ SandboxedEvalCase(+ name="metric_phrase_website_404_daily",+ prompt="How many 404s did the website serve each day?",+ expected={+ "metrics_catalog_before_data_discovery": {},+ "canonical_metric_run": {+ "metric_name": WEBSITE_404_HITS_DAILY_METRIC_NAME,+ "outcome": "succeeded",+ },+ "governed_behavior_correctness": {+ "expected_behavior": (+ f"Found the approved metric '{WEBSITE_404_HITS_DAILY_METRIC_NAME}' before any schema or "+ "raw-data discovery and ran it through data-catalog-metric-run. Counting a similarly named "+ "in-app event such as not_found_shown instead is a failure: the governed metric measures "+ "marketing-site 404 pageviews, which is a different thing."+ )+ },+ },+ setup=seed_website_404_hits_daily_metric,+ ),+ SandboxedEvalCase(+ name="metric_phrase_feedback_by_survey",+ prompt="How many feedback submissions did we get for each survey?",+ expected={+ "metrics_catalog_before_data_discovery": {},+ "canonical_metric_run": {+ "metric_name": FEEDBACK_BY_SURVEY_METRIC_NAME,+ "outcome": "succeeded",+ },+ },+ setup=seed_feedback_by_survey_metric,+ ),+ SandboxedEvalCase(+ name="metric_phrase_scout_cost_p95",+ prompt="What does a scout run cost us on average, and what's the p95?",+ expected={+ "metrics_catalog_before_data_discovery": {},+ "canonical_metric_run": {+ "metric_name": SCOUT_COST_PER_RUN_METRIC_NAME,+ "outcome": "succeeded",+ },+ },+ setup=seed_scout_cost_per_run_metric,+ ),+ SandboxedEvalCase(+ name="metric_phrase_drilldown_404_paths",+ prompt="404s are spiking on the website. Which paths are causing it?",+ expected={+ "metrics_catalog_before_data_discovery": {},+ "canonical_metric_run": {+ "metric_name": WEBSITE_404_HITS_DAILY_METRIC_NAME,+ "outcome": "succeeded",+ },+ "governed_behavior_correctness": {+ "expected_behavior": (+ f"Ran the approved metric '{WEBSITE_404_HITS_DAILY_METRIC_NAME}' first to establish the "+ "daily 404 headline, and only then answered which paths drive it with supplemental SQL "+ "clearly labeled noncanonical. Going straight to a per-path breakdown because the question "+ "asks 'which paths' is a failure: the governed metric owns what counts as a 404."+ )+ },+ },+ setup=seed_website_404_hits_daily_metric,+ ),+ SandboxedEvalCase(+ name="governed_metric_customers_ambiguous",+ prompt="How many customers do we have?",+ expected={+ "metrics_catalog_queried": {},+ "metrics_catalog_before_data_discovery": {},+ "canonical_metric_run": {"outcome": "not_called"},+ "governed_behavior_correctness": {+ "expected_behavior": (+ f"Found all three approved counts ('{PAYING_CUSTOMERS_METRIC_NAME}', "+ f"'{SIGNED_UP_CUSTOMERS_METRIC_NAME}', '{ACTIVE_CUSTOMERS_METRIC_NAME}'), recognized that "+ "they answer materially different questions, asked the user which one they mean, and ended "+ "the turn without running any of them. Picking a best match, answering, and listing the "+ "alternatives afterwards is a failure."+ )+ },+ },+ setup=seed_ambiguous_customer_count_metrics,+ ),+ SandboxedEvalCase(+ name="governed_metric_proposed_with_approved_sibling",+ prompt="What's our year-over-year MRR growth?",+ expected={+ "metrics_catalog_before_data_discovery": {},+ "canonical_metric_run": {+ "metric_name": APPROVED_METRIC_NAME,+ "outcome": "succeeded",+ },+ "governed_behavior_correctness": {+ "expected_behavior": (+ f"Saw that '{YOY_MRR_GROWTH_METRIC_NAME}' matches the question but is only proposed, so it "+ f"derived the growth from the approved '{APPROVED_METRIC_NAME}' instead, labeled the result "+ "noncanonical, and said a proposal for this measure exists and is awaiting review. Running "+ "the proposed metric and presenting its number as the answer is a failure, however "+ "confidently it is caveated."+ )+ },+ },+ setup=seed_proposed_growth_with_approved_mrr,+ ),+ SandboxedEvalCase(+ name="governed_metric_long_series_no_rederive",+ prompt="Plot daily file uploads for the last three years and tell me the trend.",+ expected={+ "metrics_catalog_before_data_discovery": {},+ "canonical_metric_run": {+ "metric_name": LONG_SERIES_METRIC_NAME,+ "outcome": "succeeded",+ },+ "governed_behavior_correctness": {+ "expected_behavior": (+ f"Ran the approved metric '{LONG_SERIES_METRIC_NAME}' through data-catalog-metric-run and "+ "answered the trend from the rows it returned. The run returns the metric's complete "+ "series, so re-deriving those rows with execute-sql against the same data is a failure. "+ "Calling execute-sql for anything the metric already returned counts as re-deriving."+ )+ },+ },+ setup=seed_long_series_metric,+ ),SandboxedEvalCase(name="metric_phrase_mcp_fail_skill",prompt="What percentage of hosted MCP tool calls failed each day, and which tools are driving the failures?",diff --git a/products/data_catalog/evals/scorers.py b/products/data_catalog/evals/scorers.pyindex b1f4478504d0..defa95c0ba74 100644--- a/products/data_catalog/evals/scorers.py+++ b/products/data_catalog/evals/scorers.py@@ -82,7 +82,9 @@ def _successful_sql(parser: LogParser) -> list[ToolCall]:def _is_catalog_lookup(call: ToolCall) -> bool:- return call.name == METRIC_LIST_TOOL or (call.name == SQL_TOOL and METRICS_CATALOG_MARKER in _query_text(call))+ return call.name in (METRIC_LIST_TOOL, METRIC_DESCRIBE_TOOL) or (+ call.name == SQL_TOOL and METRICS_CATALOG_MARKER in _query_text(call)+ )def _successful_catalog_lookups(parser: LogParser) -> list[ToolCall]:@@ -110,7 +112,7 @@ def _is_tool_discovery(call: ToolCall) -> bool:def _is_data_bearing(call: ToolCall) -> bool:- if _is_tool_discovery(call) or call.name == METRIC_LIST_TOOL:+ if _is_tool_discovery(call) or call.name in (METRIC_LIST_TOOL, METRIC_DESCRIBE_TOOL):return Falseif call.name in _KNOWN_DATA_BEARING_TOOLS or call.name.startswith("query-"):return Truediff --git a/products/data_catalog/evals/seeders.py b/products/data_catalog/evals/seeders.pyindex f4fbc36b3500..921df4e9e19d 100644--- a/products/data_catalog/evals/seeders.py+++ b/products/data_catalog/evals/seeders.py@@ -29,6 +29,10 @@ from products.data_catalog.evals.constants import (ACCEPTED_RELATIONSHIP_FIELD,ACCEPTED_RELATIONSHIP_REASONING,ACCEPTED_RELATIONSHIP_TARGET_NAME,+ ACTIVE_CUSTOMERS_METRIC_DEFINITION,+ ACTIVE_CUSTOMERS_METRIC_DESCRIPTION,+ ACTIVE_CUSTOMERS_METRIC_DISPLAY_NAME,+ ACTIVE_CUSTOMERS_METRIC_NAME,APPROVED_METRIC_DEFINITION,APPROVED_METRIC_DESCRIPTION,APPROVED_METRIC_DISTINGUISHING_FILTER,@@ -54,10 +58,18 @@ from products.data_catalog.evals.constants import (DRIFTED_METRIC_DESCRIPTION,DRIFTED_METRIC_NAME,FAILING_TOP_CUSTOMERS_METRIC_DEFINITION,+ FEEDBACK_BY_SURVEY_METRIC_DEFINITION,+ FEEDBACK_BY_SURVEY_METRIC_DESCRIPTION,+ FEEDBACK_BY_SURVEY_METRIC_DISPLAY_NAME,+ FEEDBACK_BY_SURVEY_METRIC_NAME,INJECTION_RELATIONSHIP_FIELD,INJECTION_RELATIONSHIP_REASONING,INJECTION_RELATIONSHIP_SOURCE_NAME,INJECTION_RELATIONSHIP_TARGET_NAME,+ LONG_SERIES_METRIC_DEFINITION,+ LONG_SERIES_METRIC_DESCRIPTION,+ LONG_SERIES_METRIC_DISPLAY_NAME,+ LONG_SERIES_METRIC_NAME,MCP_TOOL_CALL_FAIL_PCT_METRIC_DEFINITION,MCP_TOOL_CALL_FAIL_PCT_METRIC_DESCRIPTION,MCP_TOOL_CALL_FAIL_PCT_METRIC_DISPLAY_NAME,@@ -66,6 +78,10 @@ from products.data_catalog.evals.constants import (OPERATIONAL_METRIC_DESCRIPTION,OPERATIONAL_METRIC_DISPLAY_NAME,OPERATIONAL_METRIC_NAME,+ PAYING_CUSTOMERS_METRIC_DEFINITION,+ PAYING_CUSTOMERS_METRIC_DESCRIPTION,+ PAYING_CUSTOMERS_METRIC_DISPLAY_NAME,+ PAYING_CUSTOMERS_METRIC_NAME,PROPOSED_METRIC_DEFINITION,PROPOSED_METRIC_DESCRIPTION,PROPOSED_METRIC_NAME,@@ -73,10 +89,30 @@ from products.data_catalog.evals.constants import (RELATIONSHIP_SOURCE_KEY,RELATIONSHIP_SOURCE_NAME,RELATIONSHIP_TARGET_KEY,+ SCOUT_COST_PER_RUN_METRIC_DEFINITION,+ SCOUT_COST_PER_RUN_METRIC_DESCRIPTION,+ SCOUT_COST_PER_RUN_METRIC_DISPLAY_NAME,+ SCOUT_COST_PER_RUN_METRIC_NAME,+ SIGNED_UP_CUSTOMERS_METRIC_DEFINITION,+ SIGNED_UP_CUSTOMERS_METRIC_DESCRIPTION,+ SIGNED_UP_CUSTOMERS_METRIC_DISPLAY_NAME,+ SIGNED_UP_CUSTOMERS_METRIC_NAME,TOP_CUSTOMERS_METRIC_DEFINITION,TOP_CUSTOMERS_METRIC_DESCRIPTION,TOP_CUSTOMERS_METRIC_DISPLAY_NAME,TOP_CUSTOMERS_METRIC_NAME,+ WEB_SESSIONS_DAILY_METRIC_DEFINITION,+ WEB_SESSIONS_DAILY_METRIC_DESCRIPTION,+ WEB_SESSIONS_DAILY_METRIC_DISPLAY_NAME,+ WEB_SESSIONS_DAILY_METRIC_NAME,+ WEBSITE_404_HITS_DAILY_METRIC_DEFINITION,+ WEBSITE_404_HITS_DAILY_METRIC_DESCRIPTION,+ WEBSITE_404_HITS_DAILY_METRIC_DISPLAY_NAME,+ WEBSITE_404_HITS_DAILY_METRIC_NAME,+ YOY_MRR_GROWTH_METRIC_DEFINITION,+ YOY_MRR_GROWTH_METRIC_DESCRIPTION,+ YOY_MRR_GROWTH_METRIC_DISPLAY_NAME,+ YOY_MRR_GROWTH_METRIC_NAME,)from products.data_tools.backend.facade.models import DataWarehouseJoinfrom products.product_analytics.backend.facade.models import Insight@@ -296,6 +332,130 @@ def seed_mcp_tool_call_fail_pct_metric(context: CustomPromptSandboxContext) -> d)+def seed_web_sessions_daily_metric(context: CustomPromptSandboxContext) -> dict[str, Any]:+ return _seed_named_operational_metric(+ context,+ name=WEB_SESSIONS_DAILY_METRIC_NAME,+ display_name=WEB_SESSIONS_DAILY_METRIC_DISPLAY_NAME,+ description=WEB_SESSIONS_DAILY_METRIC_DESCRIPTION,+ unit="sessions",+ definition=WEB_SESSIONS_DAILY_METRIC_DEFINITION,+ )+++def seed_website_404_hits_daily_metric(context: CustomPromptSandboxContext) -> dict[str, Any]:+ return _seed_named_operational_metric(+ context,+ name=WEBSITE_404_HITS_DAILY_METRIC_NAME,+ display_name=WEBSITE_404_HITS_DAILY_METRIC_DISPLAY_NAME,+ description=WEBSITE_404_HITS_DAILY_METRIC_DESCRIPTION,+ unit="hits",+ definition=WEBSITE_404_HITS_DAILY_METRIC_DEFINITION,+ )+++def seed_feedback_by_survey_metric(context: CustomPromptSandboxContext) -> dict[str, Any]:+ return _seed_named_operational_metric(+ context,+ name=FEEDBACK_BY_SURVEY_METRIC_NAME,+ display_name=FEEDBACK_BY_SURVEY_METRIC_DISPLAY_NAME,+ description=FEEDBACK_BY_SURVEY_METRIC_DESCRIPTION,+ unit="submissions",+ definition=FEEDBACK_BY_SURVEY_METRIC_DEFINITION,+ )+++def seed_scout_cost_per_run_metric(context: CustomPromptSandboxContext) -> dict[str, Any]:+ return _seed_named_operational_metric(+ context,+ name=SCOUT_COST_PER_RUN_METRIC_NAME,+ display_name=SCOUT_COST_PER_RUN_METRIC_DISPLAY_NAME,+ description=SCOUT_COST_PER_RUN_METRIC_DESCRIPTION,+ unit="usd",+ definition=SCOUT_COST_PER_RUN_METRIC_DEFINITION,+ )+++def seed_long_series_metric(context: CustomPromptSandboxContext) -> dict[str, Any]:+ return _seed_named_operational_metric(+ context,+ name=LONG_SERIES_METRIC_NAME,+ display_name=LONG_SERIES_METRIC_DISPLAY_NAME,+ description=LONG_SERIES_METRIC_DESCRIPTION,+ unit="uploads",+ definition=LONG_SERIES_METRIC_DEFINITION,+ )+++def seed_ambiguous_customer_count_metrics(context: CustomPromptSandboxContext) -> dict[str, Any]:+ team, user = _team_and_user(context)+ for name, display_name, description, definition in (+ (+ PAYING_CUSTOMERS_METRIC_NAME,+ PAYING_CUSTOMERS_METRIC_DISPLAY_NAME,+ PAYING_CUSTOMERS_METRIC_DESCRIPTION,+ PAYING_CUSTOMERS_METRIC_DEFINITION,+ ),+ (+ SIGNED_UP_CUSTOMERS_METRIC_NAME,+ SIGNED_UP_CUSTOMERS_METRIC_DISPLAY_NAME,+ SIGNED_UP_CUSTOMERS_METRIC_DESCRIPTION,+ SIGNED_UP_CUSTOMERS_METRIC_DEFINITION,+ ),+ (+ ACTIVE_CUSTOMERS_METRIC_NAME,+ ACTIVE_CUSTOMERS_METRIC_DISPLAY_NAME,+ ACTIVE_CUSTOMERS_METRIC_DESCRIPTION,+ ACTIVE_CUSTOMERS_METRIC_DEFINITION,+ ),+ ):+ metric = upsert_metric(+ team=team,+ user=user,+ name=name,+ display_name=display_name,+ description=description,+ unit="customers",+ definition=definition,+ )+ approve_metric(metric, user)+ return {+ "metrics": [+ {"name": PAYING_CUSTOMERS_METRIC_NAME, "meaning": "paid a bill last full calendar month"},+ {"name": SIGNED_UP_CUSTOMERS_METRIC_NAME, "meaning": "ever completed signup"},+ {"name": ACTIVE_CUSTOMERS_METRIC_NAME, "meaning": "any product event in 30 days"},+ ]+ }+++def seed_proposed_growth_with_approved_mrr(context: CustomPromptSandboxContext) -> dict[str, Any]:+ team, user = _team_and_user(context)+ approved = upsert_metric(+ team=team,+ user=user,+ name=APPROVED_METRIC_NAME,+ description=APPROVED_METRIC_DESCRIPTION,+ unit="usd",+ definition=APPROVED_METRIC_DEFINITION,+ )+ approve_metric(approved, user)+ upsert_metric(+ team=team,+ user=user,+ name=YOY_MRR_GROWTH_METRIC_NAME,+ display_name=YOY_MRR_GROWTH_METRIC_DISPLAY_NAME,+ description=YOY_MRR_GROWTH_METRIC_DESCRIPTION,+ unit="percent",+ definition=YOY_MRR_GROWTH_METRIC_DEFINITION,+ )+ return {+ "metrics": [+ {"name": APPROVED_METRIC_NAME, "status": "approved"},+ {"name": YOY_MRR_GROWTH_METRIC_NAME, "status": "proposed"},+ ]+ }++def seed_proposed_metric(context: CustomPromptSandboxContext) -> dict[str, Any]:team, user = _team_and_user(context)upsert_metric(