Phase 3: cost-vs-revenue dashboard
ArcadiaCloud.Analytics — the operator margin view. Revenue (tenant
invoices, ex-GST) vs COGS (DO cost lines), margin = revenue - COGS.
- margin_summary/1 — overall P&L + per-tenant + per-deployment margin
for a month.
- by_kind/1 — revenue and COGS broken down by resource kind (separate
axes; billing kinds and DO kinds don't 1:1).
- live_accrual/0 — current-month unbilled: runs the quote engine with
partial metered usage per active subscription. "What tenants are
racking up right now before the rollup."
COGS-to-tenant attribution uses COALESCE(deployment.tenant_id,
resource.tenant_id) — a resource in a deployment bills to the
deployment's tenant; standalone resources fall back to their own
tenant_id (skyai-internal infra).
API (platform_admin only):
- GET /api/v1/dashboard/margin?period=YYYY-MM-DD
- GET /api/v1/dashboard/accrual
Schema fix: cloud_resources.tenant_id and cloud_projects.tenant_id were
binary_id (UUID) while cloud_deployments / tenant_invoices use string.
Migrated both to text — a UUID is a valid string, arcadia also uses
non-UUID tenant slugs ("platform-admin"), and the type alignment lets
the analytics COALESCE join work. Side benefit: kills the phase-1 bug
where a non-UUID tenant_id claim crashed the inventory query.
Smoke verified against real ingested April DO COGS: pilot deployment on
Studio with 5 droplets, metered + rolled up — by_tenant shows
dashboard-pilot rev $71.12 / COGS $30.53 / margin $40.59 (57.1%);
overall P&L revenue $71.12 vs all-April COGS $86.92 = -$15.80 (the
pilot's revenue doesn't cover Sky AI's full April infra — correct, the
rest is internal/unattributed).
Phase 3 complete: catalog, deployments+subscriptions, quote engine,
metering, invoice rollup, cost-vs-revenue dashboard.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
19
priv/repo/migrations/20260520180000_tenant_id_to_string.exs
Normal file
19
priv/repo/migrations/20260520180000_tenant_id_to_string.exs
Normal file
@@ -0,0 +1,19 @@
|
||||
defmodule ArcadiaCloud.Repo.Migrations.TenantIdToString do
|
||||
use Ecto.Migration
|
||||
|
||||
# tenant_id is string-typed everywhere else (cloud_deployments,
|
||||
# tenant_invoices) and arcadia uses non-UUID tenant slugs like
|
||||
# "platform-admin". cloud_resources/cloud_projects were binary_id —
|
||||
# align them so cross-table joins (analytics COALESCE) work and
|
||||
# non-UUID tenant ids don't blow up Ecto casts.
|
||||
|
||||
def up do
|
||||
execute "ALTER TABLE cloud_resources ALTER COLUMN tenant_id TYPE text USING tenant_id::text"
|
||||
execute "ALTER TABLE cloud_projects ALTER COLUMN tenant_id TYPE text USING tenant_id::text"
|
||||
end
|
||||
|
||||
def down do
|
||||
execute "ALTER TABLE cloud_resources ALTER COLUMN tenant_id TYPE uuid USING tenant_id::uuid"
|
||||
execute "ALTER TABLE cloud_projects ALTER COLUMN tenant_id TYPE uuid USING tenant_id::uuid"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user