feat/smarter-mrr
needs attentionviewing older commit4d95793 · fullpre-PRreviewed 2026-08-07 19:28 UTC0H · 0M · 4L · 6I- Purpose
- Add MRR visibility for Smarter (Energía Real), an off-platform client paying $20 USD per report (calculated bill). Smarter pays by bank transfer; this insight does not touch the billing pipeline.
- Goal
- Measure Smarter MRR natively in USD (measure-not-charge pattern, matching Neto/Pilgrim's) and surface it on the Revenue & MRR dashboard for finance reconciliation.
- Sub-goals
- Add mrr_smarter_usd insight: count(calculated bills)/month × $20 USD + display-only MXN approximation
- Add tile to Revenue & MRR dashboard at y=36
- Document Phase 2 discrepancy (per-report ~$62k MXN vs finance Billing $69k MXN — bundle difference) for future Stripe/USD plan work
- What
- Added one Terraform locals block (2 constants) and one posthog_insight resource in insights.tf (+52 lines); added one dashboard tile entry in dashboards.tf (+5 lines). No app code, no DB schema, no billing path.
- Why
- Smarter is paying off-platform; leadership needs MRR visibility without a full Stripe integration. Phase 1 = measure; Phase 2 (multi-plan-per-org / USD plan / Stripe) is a separate effort.
- Areas
- infra/posthog/insights.tf+52−0infra/posthog/dashboards.tf+5−0
- Blast
- 57 lines added across 2 files in infra/posthog/ only. Zero app code, zero DB migrations, zero billing path changes. Confined to PostHog analytics IaC.
Findings · 10
correctness2
round() returns Float64 in ClickHouse/HogQL — mrr_mxn_aprox displays as e.g. 3360.0 not 3360
infra/posthog/insights.tf
round(count() * 20 * 18.5, 0) returns Float64 in ClickHouse semantics, so the column displays with a trailing .0. Column is display-only/approximate so not a bug, but toInt64(round(...)) would give a cleaner integer if desired.
FX constant baked into Terraform-rendered SQL — stale-value risk on re-apply
infra/posthog/insights.tf
Terraform interpolates usd_mxn_fx = 18.5 into the heredoc string at plan/apply time, so the literal 18.5 is sent to PostHog. This is intentional and documented, but a future re-apply with an unchanged local will silently keep the stale rate. The comment instructs manual refresh — confirm this is visible to whoever owns infra applies.
conventions3
locals block placed mid-file — prefer top of file or locals.tf
infra/posthog/insights.tf
Terraform convention is to declare locals{} near the top of the file or in a dedicated locals.tf. Placing it inline just before the resource that uses it makes constants harder to discover. Terraform is ordering-indifferent so this is not a bug.
FX refresh cadence: informal comment, no structured traceability
infra/posthog/insights.tf
The inline comment 'refresh manually alongside the D3 finance constants' is reasonable but informal. A more explicit marker (e.g., last-updated date or a Linear issue link) would make the update obligation traceable.
Dashboard tile comment separator is longer than existing separators
infra/posthog/dashboards.tf
The # ── Smarter (ER) MRR ... ────── line is noticeably longer than adjacent separators. Minor visual inconsistency.
tests1
No bill-status filter beyond source='calculated' — confirm all counted records are valid delivered reports
infra/posthog/insights.tf
The query counts every bill WHERE source='calculated' with no status guard. If the bills table can hold source='calculated' rows in errored, voided, or pending states, the count may overstate reportable MRR. The commit verifies live numbers match expectation (Jul 210, Jun 168), which is a strong signal all such bills are valid — but worth an explicit comment confirming whether a status filter is needed or ruled out.
improvement4
Hardcoded start date '2026-01' will age silently
infra/posthog/insights.tf
WHERE year_month >= '2026-01' is reasonable today but will exclude any backfilled or pilot rows before that date, and the bound may become confusing as the product matures. LIMIT 24 ORDER BY year_month DESC already caps the lookback — dropping the WHERE clause makes the query self-maintaining.
Manual FX rate has no enforcement mechanism — risk of stale data on revenue dashboard
infra/posthog/insights.tf
usd_mxn_fx = 18.5 is marked 'display-only; refresh manually'. A stale FX rate drifting >10% could quietly mislead the MXN column, especially given the known discrepancy between derived MRR and the finance Billing line. Consider (a) a Terraform variable with a description that surfaces the refresh obligation in plan output, or (b) removing the MXN column until a live FX source is available.
Triple count() — CTE would express the mrr derivation more clearly
infra/posthog/insights.tf
count() appears three times in SELECT. No performance issue (ClickHouse evaluates once per group), but a WITH base AS (SELECT year_month, count() AS reportes ...) CTE would make the derivation intent explicit. Minor readability improvement.
Dashboard tile leaves x=6..11 at y=36 empty
infra/posthog/dashboards.tf
Tile placed at x=0, y=36, w=6 — right half of the row is unused. If no companion tile is planned, widening to w=12 would use the space better. Purely cosmetic.