Files
zeekay bc4ddf332b chore: rebase the tree onto upstream master fa1a9a60
Mechanically re-derived: bin/debrand runs over a fresh import of
posthog/posthog@fa1a9a60d4 (2026-08-06).
The pipeline (.hanzo/workflows), the Dockerfiles and bin/docker*
entrypoints, compose files, LLM.md and the squashed initial migration
are restored from the shipped tree, same as the previous import.

The prune's import-closure guard kept 21 products the new core now
imports; dropping them is a refactor now, recorded rather than forced.
2026-08-06 01:25:36 -07:00

731 lines
21 KiB
Terraform

# =============================================================================
# Insights Insights Configuration
# =============================================================================
#
# This file demonstrates how to manage Insights insights using Terraform.
# Insights can be linked to dashboards via dashboard_ids.
#
# For more information, see:
# https://registry.terraform.io/providers/Insights/insights/latest/docs/resources/insight
# =============================================================================
locals {
export_insight_regions = {
us = {
table_name = "postgres.insights_exportedasset"
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id, 633001, 567706]
unknown_result_sql = "https://metabase.prod-us.insights.dev/question/1838-analyse-unknown-exportedasset-exceptions"
}
eu = {
table_name = "eu_insights_exportedasset"
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id]
unknown_result_sql = "https://metabase.prod-eu.insights.dev/question/565-analyse-unknown-exportedasset-exceptions"
}
}
# Base query with placeholder - replace() substitutes the table name per region
export_insight_base_query = jsonencode({
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"id": "{{TABLE_NAME}}",
"kind": "DataWarehouseNode",
"math": "total",
"name": "{{TABLE_NAME}}",
"id_field": "id",
"table_name": "{{TABLE_NAME}}",
"custom_name": "Starts",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
},
{
"id": "{{TABLE_NAME}}",
"kind": "DataWarehouseNode",
"math": "total",
"name": "{{TABLE_NAME}}",
"id_field": "id",
"properties": [
{
"key": "export_context is not null or content_location is not null",
"type": "insightsql",
"value": null
}
],
"table_name": "{{TABLE_NAME}}",
"custom_name": "Success",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
},
{
"id": "{{TABLE_NAME}}",
"kind": "DataWarehouseNode",
"math": "total",
"name": "{{TABLE_NAME}}",
"id_field": "id",
"properties": [
{
"key": "exception is not null",
"type": "insightsql",
"value": null
}
],
"table_name": "{{TABLE_NAME}}",
"custom_name": "Caught Exceptions",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
},
{
"id": "{{TABLE_NAME}}",
"kind": "DataWarehouseNode",
"math": "total",
"name": "{{TABLE_NAME}}",
"id_field": "id",
"properties": [
{
"key": "failure_type = 'user'",
"type": "insightsql",
"value": null
}
],
"table_name": "{{TABLE_NAME}}",
"custom_name": "User failures",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
},
{
"id": "{{TABLE_NAME}}",
"kind": "DataWarehouseNode",
"math": "total",
"name": "{{TABLE_NAME}}",
"id_field": "id",
"properties": [
{
"key": "failure_type = 'system'",
"type": "insightsql",
"value": null
}
],
"table_name": "{{TABLE_NAME}}",
"custom_name": "System failures",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
},
{
"id": "{{TABLE_NAME}}",
"kind": "DataWarehouseNode",
"math": "total",
"name": "{{TABLE_NAME}}",
"id_field": "id",
"properties": [
{
"key": "failure_type = 'timeout_generation'",
"type": "insightsql",
"value": null
}
],
"table_name": "{{TABLE_NAME}}",
"custom_name": "Timeout failures",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
},
{
"id": "{{TABLE_NAME}}",
"kind": "DataWarehouseNode",
"math": "total",
"name": "{{TABLE_NAME}}",
"id_field": "id",
"properties": [
{
"key": "failure_type = 'unknown'",
"type": "insightsql",
"value": null
}
],
"table_name": "{{TABLE_NAME}}",
"custom_name": "Unknown failures",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
},
{
"id": "{{TABLE_NAME}}",
"kind": "DataWarehouseNode",
"math": "total",
"name": "{{TABLE_NAME}}",
"id_field": "id",
"properties": [
{
"key": "exception is null and export_context is null and content_location is null and timestamp < now() - interval 10 minute",
"type": "insightsql",
"value": null
}
],
"table_name": "{{TABLE_NAME}}",
"custom_name": "Uncaught Exceptions",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
}
],
"version": 2,
"properties": [],
"trendsFilter": {
"display": "ActionsLineGraph",
"formulaNodes": [
{ "formula": "B/A", "custom_name": "Success" },
{ "formula": "C/A", "custom_name": "Caught" },
{ "formula": "H/A", "custom_name": "Uncaught" },
{ "formula": "D/A", "custom_name": "User Errors" },
{ "formula": "E/A", "custom_name": "System Errors" },
{ "formula": "F/A", "custom_name": "Timeout Errors" },
{ "formula": "G/A", "custom_name": "Unknown Errors" }
],
"decimalPlaces": 4,
"yAxisScaleType": "log10",
"showMultipleYAxes": false,
"showValuesOnSeries": true,
"aggregationAxisFormat": "percentage_scaled",
"showAlertThresholdLines": true
},
"breakdownFilter": null
}
})
}
# Terraform configuration for Insights insight
# Compatible with insights provider v1.0
# Source insight ID: 5089102
# Short ID: tycwiOT1
import {
to = insights_insight.shared_dashboard_stats
id = "5089102"
}
resource "insights_insight" "shared_dashboard_stats" {
name = "Shared Dashboard Stats"
query_json = jsonencode({
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"math": "total",
"event": "viewed dashboard",
"properties": [
{
"key": "is_shared",
"type": "event",
"value": "true",
"operator": "exact"
}
],
"math_property": null,
"math_property_type": null,
"math_group_type_index": null
},
{
"kind": "EventsNode",
"math": "total",
"name": "dashboard share toggled",
"event": "dashboard share toggled",
"properties": [
{
"key": "is_shared",
"type": "event",
"value": [
"true"
],
"operator": "exact"
}
]
}
],
"version": 2,
"interval": "day",
"dateRange": {
"date_to": null,
"date_from": "-30d"
},
"properties": [],
"trendsFilter": {
"display": "ActionsLineGraph",
"formulas": null,
"showLegend": false,
"decimalPlaces": null,
"yAxisScaleType": "linear",
"showValuesOnSeries": false,
"showPercentStackView": false,
"aggregationAxisFormat": "numeric",
"aggregationAxisPrefix": null,
"aggregationAxisPostfix": null
},
"compareFilter": null,
"samplingFactor": null,
"breakdownFilter": null,
"filterTestAccounts": true
},
"showHeader": true
})
tags = ["managed-by:terraform"]
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id]
}
# Terraform configuration for Insights insight
# Compatible with insights provider v1.0
# Source insight ID: 5088513
# Short ID: DeafU0xe
import {
to = insights_insight.dashboards_created_from_template_unique_users
id = "5088513"
}
resource "insights_insight" "dashboards_created_from_template_unique_users" {
name = "Dashboards created from template (unique users)"
query_json = jsonencode({
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"math": "dau",
"event": "dashboard created",
"properties": [
{
"key": "from_template",
"type": "event",
"value": "true",
"operator": "exact"
}
],
"custom_name": "Dashboard created from template (unique users)"
},
{
"kind": "EventsNode",
"math": "dau",
"event": "dashboard created",
"custom_name": "Dashboard created (unique users)"
}
],
"version": 2,
"interval": "day",
"dateRange": {
"date_from": "-30d"
},
"properties": [],
"trendsFilter": {
"display": "ActionsLineGraph",
"showLegend": true,
"formulaNodes": [
{
"formula": "(A/B) * 100"
}
],
"yAxisScaleType": "linear",
"showValuesOnSeries": false,
"showPercentStackView": false,
"aggregationAxisFormat": "percentage"
},
"filterTestAccounts": false
}
})
tags = ["managed-by:terraform"]
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id, 778670]
}
# Terraform configuration for Insights insight
# Compatible with insights provider v1.0
# Source insight ID: 5089292
# Short ID: lvR7dwxH
import {
to = insights_insight.created_subscriptions
id = "5089292"
}
resource "insights_insight" "created_subscriptions" {
name = "Created subscriptions"
query_json = jsonencode({
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"math": "total",
"name": "dashboard subscription created",
"event": "dashboard subscription created"
},
{
"kind": "EventsNode",
"math": "total",
"name": "insight subscription created",
"event": "insight subscription created"
}
],
"version": 2,
"trendsFilter": {
"showLegend": true
}
}
})
tags = ["managed-by:terraform"]
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id]
}
resource "insights_insight" "export_successes_and_failures" {
for_each = local.export_insight_regions
name = "Export Successes and Failures (${upper(each.key)})"
query_json = replace(local.export_insight_base_query, "{{TABLE_NAME}}", each.value.table_name)
tags = ["managed-by:terraform"]
dashboard_ids = each.value.dashboard_ids
description = "More details about the unknown errors can be found here: ${each.value.unknown_result_sql}"
}
# Terraform configuration for Insights insight
# Compatible with insights provider v1.0
# Source insight ID: 3901616
# Short ID: KUvN6RsQ
import {
to = insights_insight.usage_by_role
id = "3901616"
}
resource "insights_insight" "usage_by_role" {
name = "Usage by role"
query_json = jsonencode({
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"id": "214129",
"kind": "ActionsNode",
"math": "total",
"name": "[team-analytics-platform] Clicked New action in data management"
}
],
"version": 2,
"interval": "week",
"dateRange": {
"date_to": null,
"date_from": "-90d",
"explicitDate": false
},
"trendsFilter": {
"display": "ActionsAreaGraph"
},
"breakdownFilter": {
"breakdowns": [
{
"type": "person",
"property": "role_at_organization"
}
]
},
"filterTestAccounts": true
}
})
tags = ["managed-by:terraform"]
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id]
}
# Terraform configuration for Insights insight
# Compatible with insights provider v1.0
# Source insight ID: 5088924
# Short ID: GhRIGhBU
import {
to = insights_insight.alert_creation
id = "5088924"
}
resource "insights_insight" "alert_creation" {
name = "Alert creation"
query_json = jsonencode({
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"id": "postgres.insights_alertconfiguration",
"kind": "DataWarehouseNode",
"math": "dau",
"name": "postgres.insights_alertconfiguration",
"id_field": "id",
"table_name": "postgres.insights_alertconfiguration",
"custom_name": "Unique users",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
},
{
"id": "postgres.insights_alertconfiguration",
"kind": "DataWarehouseNode",
"math": "total",
"name": "postgres.insights_alertconfiguration",
"id_field": "id",
"table_name": "postgres.insights_alertconfiguration",
"custom_name": "Total count",
"timestamp_field": "created_at",
"distinct_id_field": "created_by_id"
}
],
"version": 2,
"interval": "day",
"dateRange": {
"date_to": null,
"date_from": "-30d",
"explicitDate": false
},
"properties": [],
"trendsFilter": {
"showLegend": true
},
"breakdownFilter": null
}
})
tags = ["managed-by:terraform"]
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id]
}
# Terraform configuration for Insights insight
# Compatible with insights provider v1.0
# Source insight ID: 5512297
# Short ID: pfwTATaa
import {
to = insights_insight.api_calls_originating_from_our_terraform_provider
id = "5512297"
}
resource "insights_insight" "api_calls_originating_from_our_terraform_provider" {
name = "API calls originating from our Terraform Provider"
query_json = jsonencode({
"kind": "DataVisualizationNode",
"source": {
"kind": "InsightsQLQuery",
"query": "SELECT \n extract(properties.$user_agent, 'version: ([0-9\\\\.\\\\-a-zA-Z]+)') as version,\n person.properties.email as email,\n person.properties.org__name as organization,\n count() as api_calls,\n min(timestamp) as first_call,\n max(timestamp) as last_call\nFROM events\nWHERE \n properties.$user_agent LIKE '%terraform-provider%'\n AND timestamp >= now() - INTERVAL 7 DAY\nGROUP BY version, email, organization\nORDER BY api_calls DESC"
},
"display": "ActionsTable",
"chartSettings": {
"xAxis": {
"column": "first_call"
},
"yAxis": [
{
"column": "api_calls",
"settings": {
"formatting": {
"prefix": "",
"suffix": ""
}
}
}
]
},
"tableSettings": {
"columns": [
{
"column": "version",
"settings": {
"formatting": {
"prefix": "",
"suffix": ""
}
}
},
{
"column": "email",
"settings": {
"formatting": {
"prefix": "",
"suffix": ""
}
}
},
{
"column": "organization",
"settings": {
"formatting": {
"prefix": "",
"suffix": ""
}
}
},
{
"column": "api_calls",
"settings": {
"formatting": {
"prefix": "",
"suffix": ""
}
}
},
{
"column": "first_call",
"settings": {
"formatting": {
"prefix": "",
"suffix": ""
}
}
},
{
"column": "last_call",
"settings": {
"formatting": {
"prefix": "",
"suffix": ""
}
}
}
]
}
})
tags = ["managed-by:terraform"]
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id, 821321]
}
# Terraform configuration for Insights insight
# Compatible with insights provider v1.0.6
# Source insight ID: 7067184
# Short ID: a5XEngMW
import {
to = insights_insight.dashboard_created_unique_users_by_event_s_source
id = "2/7067184"
}
resource "insights_insight" "dashboard_created_unique_users_by_event_s_source" {
derived_name = "dashboard created unique users by event's source"
query_json = jsonencode({
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"math": "dau",
"name": "dashboard created",
"event": "dashboard created"
}
],
"version": 2,
"trendsFilter": {
"display": "ActionsAreaGraph"
},
"breakdownFilter": {
"breakdowns": [
{
"type": "event",
"property": "source"
}
]
},
"filterTestAccounts": true
}
})
tags = ["managed-by:terraform"]
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id]
}
# Terraform configuration for Insights insight
# Compatible with insights provider v1.0.6
# Source insight ID: 6984945
# Short ID: US61ntVv
import {
to = insights_insight.alert_failures_by_exception_type_aggregated
id = "2/6984945"
}
resource "insights_insight" "subscription_delivery_success_rate" {
for_each = toset(["US", "EU"])
name = "Subscription delivery success rate (${each.key})"
query_json = jsonencode({
"kind": "InsightVizNode",
"source": {
"kind": "TrendsQuery",
"series": [
{
"kind": "EventsNode",
"math": "total",
"event": "slo_operation_started",
"custom_name": "Started",
"properties": [
{
"key": "operation",
"type": "event",
"value": ["subscription_delivery"],
"operator": "exact"
},
{
"key": "region",
"type": "event",
"value": [each.key],
"operator": "exact"
}
]
},
{
"kind": "EventsNode",
"math": "total",
"event": "slo_operation_completed",
"custom_name": "Succeeded",
"properties": [
{
"key": "operation",
"type": "event",
"value": ["subscription_delivery"],
"operator": "exact"
},
{
"key": "outcome",
"type": "event",
"value": ["success"],
"operator": "exact"
},
{
"key": "region",
"type": "event",
"value": [each.key],
"operator": "exact"
}
]
}
],
"version": 2,
"interval": "day",
"dateRange": {
"date_from": "-30d"
},
"trendsFilter": {
"display": "ActionsLineGraph",
"showLegend": true,
"showValuesOnSeries": true,
"formulaNodes": [
{ "formula": "B/A", "custom_name": "Success rate" }
],
"aggregationAxisFormat": "percentage_scaled"
},
"filterTestAccounts": false
}
})
tags = ["managed-by:terraform"]
dashboard_ids = [insights_dashboard.team_analytics_platform_key_metrics.id]
}
resource "insights_insight" "alert_failures_by_exception_type_aggregated" {
name = "Alert failures by exception type (aggregated)"
description = "Failures grouped by exception type with alert IDs normalized, showing the core issues affecting alerts"
query_json = jsonencode({
"kind": "DataTableNode",
"source": {
"kind": "InsightsQLQuery",
"query": "SELECT\n coalesce(\n properties.error_type,\n if(properties.alert_state = 'Errored', 'Alert configuration error', 'Unknown error')\n ) AS exception_type,\n count() AS failure_count,\n count() * 100.0 / sum(count()) OVER () AS percentage_of_failures,\n uniq(properties.resource_id) AS unique_alerts_affected,\n uniq(properties.team_id) AS unique_teams_affected,\n min(timestamp) AS first_occurrence,\n max(timestamp) AS last_occurrence\nFROM events\nWHERE event = 'slo_operation_completed'\n AND properties.operation = 'alert_check'\n AND (properties.outcome = 'failure' OR properties.alert_state = 'Errored')\n AND timestamp >= now() - INTERVAL 30 DAY\n AND timestamp < now()\nGROUP BY exception_type\nORDER BY failure_count DESC\nLIMIT 100"
}
})
tags = ["managed-by:terraform"]
dashboard_ids = [1142938, 821321, insights_dashboard.team_analytics_platform_key_metrics.id, 1294240]
}