Skip to content

feat(dashboard): add billing usage metrics - #4888

Merged
dbm03 merged 2 commits into
mainfrom
feat/billing-metrics
Nov 20, 2026
Merged

dbm03 merged 2 commits into
mainfrom
feat/billing-metrics

Conversation

@dbm03

@dbm03 dbm03 commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

Checklist

  • No breaking changes
  • Tests pass
  • New features have new tests
  • Documentation is updated (if applicable)
  • Title of the PR is in the correct format (see below)
  • Show appID with label "(deleted)"

Goal

Give administrators of paid Nhost organizations visibility into what drives their bill before the invoice arrives. The existing billing page provides plan management and a cost estimate, but no per-project usage history or inventory of tracked billable resources. This adds a Usage page alongside Plan, plus an Invoices action opening the Stripe customer portal, while preserving the existing plan and payment-details flows.

Type: Enhancement

Changes

  • Separate billing routes. /orgs/[orgSlug]/billing remains the Plan page; /orgs/[orgSlug]/billing/usage shows Usage. Both use a shared frame with route navigation, an Invoices button, and independently scrolling content. Usage and Invoices are disabled for free organizations, and a direct visit to Usage on a free plan explains that an upgrade is required. The existing organization scope supplies loading and access protection.
  • Shared customer portal flow. useCustomerPortal serves both Invoices and the existing payment-details action. It requests a portal URL for the current organization, retains the loading/success/error toasts, and navigates the current window if opening a new window is blocked.
  • Admin-only billing data. useBillingMetrics queries reports from the last 96 days, newest first, alongside billingResources and dedicated-compute billingTimeBasedUsages. It gets the current cycle from billingGetNextInvoice.PeriodEnd, subtracting one UTC calendar month for the start; without an invoice it falls back to the current UTC calendar month. Both queries are skipped for non-admins. The page handles restricted, error/retry, initial loading, and loaded states; refreshes keep existing data visible.
  • Per-project daily and cycle-to-date charts. Reports are associated with project names from the organization, normalized to their four-hour billing run when that run has occurred, and converted from millicore-minutes to vCPU-minutes for compute. The chart retains up to 95 day buckets in the selected time zone. Its bounds follow the buckets containing the earliest and latest reports, including reports moved to an adjacent day's bucket by a renewal boundary. Reports are summed into per-project daily series; cumulative series reset at each billing cycle before the selected range is applied. The period summary always sums daily values, with approximate whole-vCPU-minute compute totals.
  • Shareable ranges and persistent chart view. usageRange stores current/previous-cycle or rolling 7/30/60-day presets; usageFrom/usageTo store absolute days. Browser time is the default, with usageTz=utc selecting UTC. A popover offers presets, a range calendar, and time-zone selection; date edits apply only on Apply. Invalid or expired URL ranges fall back to the current cycle. Dragging writes a clipped absolute range, but selections containing no retained reports leave the URL unchanged. Double-click widens the range within retained bounds. Daily versus Month to date is saved in browser storage; changing meter or view resets chart interaction state.
  • Invoice and included-usage context. The current-cycle axis extends beyond the next invoice marker. Cumulative charts show reference lines for 50,000 MB egress, 36,000 seconds of function duration, and 12,500 vCPU-minutes (approximately the $15 compute credit); tooltips show the total's share of the included amount. Enterprise plans hide these Pro/Team references and resource-pricing hints. A notice explains that usage figures are estimates and links to pricing and billing documentation.
  • Deleted projects and tracked resources. Deleted projects keep recognizable shortened IDs with full-ID tooltips and muted colors. More than five visible deleted projects are combined into one summed series; those with no values in the displayed chart are omitted. The resources table lists compute millicores, deployed functions, custom-domain status, persistent volume, and PITR per project, with optional Pro/Team pricing explanations.
  • Shared metrics behavior. Legend filtering ignores departed series and restores visibility if all remaining series would otherwise be hidden. Stacked bars pad multi-row data across the time domain; tooltips fade zero-value rows, show reference-line shares, and suppress their entry animation. The serverless-functions metrics refresh action becomes a labeled button. Regression tests cover renewal-adjacent reports, fixed-date chart fixtures, range clipping, view persistence, and legend behavior.
  • Command palette. A billing-usage entry opens the new Usage route and matches usage, metrics, egress, function duration, and compute. The existing Billing entry also matches invoices.

Flow

flowchart LR
  Q[getBillingMetrics and next invoice] --> M[Admin-only data mapping and cycle]
  M --> B[Time-zone day buckets]
  B --> D[Daily project totals]
  D --> C[Cycle-to-date totals]
  D --> S[Selected-period summary]
  C --> V[Range selection and deleted-project grouping]
  D --> V
  V --> K[Stacked usage chart]
  U[URL range and time zone] --> V
  K -- zoom --> U
  M --> T[Current tracked resources]
Loading

Key files

  • dashboard/src/pages/orgs/[orgSlug]/billing/ (+43/-12; 2 routes) and dashboard/src/features/orgs/components/billing/layout/ (+153; 4 files including tests) — Plan/Usage routing, shared frame, and Invoices action.
  • dashboard/src/features/orgs/components/billing/BillingUsage/ (+4,089; 111 files including tests) — data loading, charts, resources table, time-range controls, cycle/bucket arithmetic, and regression coverage.
  • dashboard/src/features/orgs/components/billing/hooks/useCustomerPortal/ and SubscriptionPlan/SubscriptionPlan.tsx (+52/-33; 3 files) — shared Stripe portal flow.
  • dashboard/src/features/orgs/projects/common/metrics/ (+198/-20; 12 files including tests) — legend visibility, stacked-chart padding, tooltip behavior, and formatting.
  • dashboard/src/features/command-palette/{catalog.tsx,catalog.test.ts,tree.tsx} (+12/-1) — Usage route registration and search metadata.
  • dashboard/src/utils/__generated__/graphql.ts (+66; generated) — billing operation types and hooks.

@dbm03 dbm03 self-assigned this Aug 27, 2026
@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Deployment Info - dashboard

@dbm03
dbm03 force-pushed the feat/billing-metrics branch 3 times, most recently from 994290e to 52c1017 Compare October 1, 2026 16:25
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from 52c1017 to 3fb4066 Compare October 5, 2026 08:48
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from 05d6580 to 3b62d7c Compare October 20, 2026 09:07
@dbm03
dbm03 changed the base branch from main to fix/metrics-chart-legend-tooltips October 20, 2026 09:08
@dbm03
dbm03 added this pull request to stack #5211 October 20, 2026 09:29
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from 3b62d7c to c7757a8 Compare October 20, 2026 10:34
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from c7757a8 to e224b62 Compare October 20, 2026 13:50
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from e224b62 to 4238782 Compare October 20, 2026 13:59
@dbm03 dbm03 changed the title feat(dashboard): add billing metrics feat(dashboard): add billing usage metrics Oct 20, 2026
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from 4238782 to af8f6dc Compare October 21, 2026 07:48
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from af8f6dc to 3e8b23c Compare October 21, 2026 13:23
@dbm03
dbm03 force-pushed the feat/billing-metrics branch 2 times, most recently from 9416865 to 428419e Compare October 21, 2026 15:24
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from 428419e to 2aab7b5 Compare October 21, 2026 15:41
@dbm03
dbm03 removed this pull request from stack #5211 October 21, 2026 15:48
@dbm03
dbm03 changed the base branch from fix/metrics-chart-legend-tooltips to feat/stacked-bar-metric-chart October 21, 2026 15:48
dbm03 added a commit that referenced this pull request Oct 21, 2026
StackedBarMetricChart draws metric series as stacked bars and reuses the
legend, pinned tooltip and drag-to-zoom hooks of MetricChart. The billing
usage chart (#4888) is its first user.

- The value axis counts in whole numbers with headroom above the tallest
  stack, and grows to show a reference line once the bars reach half of
  it (buildValueTicks, buildStackedValueTicks).
- The shared tooltip gains a label formatter, a footer, an option to list
  rows top to bottom like the stacked bars, and a cap that sums the
  smallest rows into one "+N more" row, so the footer stays visible with
  many series.
- The legend can render an addon next to each item, such as an info
  tooltip, kept apart from the chart's click, double-click and keyboard
  handlers. The stacked chart's legend lists items in the order of the
  bars instead of letting Recharts sort them by series key.
- MetricTable column labels accept any React node.

MetricChart renders and behaves as before. The dashboard notes mention
the new chart.
@dbm03
dbm03 force-pushed the feat/billing-metrics branch 2 times, most recently from b909a70 to 32243df Compare October 22, 2026 09:08
@dbm03
dbm03 marked this pull request as ready for review October 22, 2026 10:33
@dbm03
dbm03 force-pushed the feat/billing-metrics branch 2 times, most recently from 7be7c30 to 78368cb Compare October 22, 2026 10:41
@dbm03
dbm03 requested a review from robertkasza October 22, 2026 10:50
@dbm03
dbm03 force-pushed the feat/billing-metrics branch 2 times, most recently from c076378 to 198d739 Compare October 27, 2026 16:29
Base automatically changed from feat/stacked-bar-metric-chart to main October 27, 2026 16:36
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from 198d739 to 44b6c01 Compare October 27, 2026 16:36
@dbm03
dbm03 marked this pull request as draft November 11, 2026 21:11
@dbm03
dbm03 force-pushed the feat/billing-metrics branch 2 times, most recently from 9c5cc3f to cc12240 Compare November 11, 2026 22:51
@dbm03
dbm03 marked this pull request as ready for review November 11, 2026 23:02
@dbm03
dbm03 marked this pull request as draft November 12, 2026 08:29
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from cc12240 to 50da661 Compare November 12, 2026 10:13
@dbm03
dbm03 marked this pull request as ready for review November 12, 2026 10:15

@robertkasza robertkasza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just had the one comment about the alert in the billing page. But I am fine if you want to leave it.

Administrators of paid organizations can now see what drives their bill
before the invoice arrives.

- Organization billing is split into Plan and Usage tabs, plus an
  Invoices button that opens the Stripe customer portal. Usage and
  Invoices are for paid organizations, and usage data for org admins.
  The active tab is kept in the URL.
- The Usage tab charts the last 60 days of per-project usage (egress,
  function duration, compute) as stacked month-to-date bars with
  StackedBarMetricChart. It has a time range filter (billing cycle and
  rolling presets, an absolute range, drag-to-zoom and double-click to
  zoom out), summary cards and a table of the resources tracked now.
- Deleted projects are labelled by a shortened ID with a tooltip, and
  more than five of them are grouped into one "Deleted projects" series.
- Enterprise plans hide the included-usage lines and pricing hints.
- "Update payment details" and Invoices share the customer portal logic
  through useCustomerPortal.
- useSeriesVisibility ignores hidden series that are no longer in the
  chart, and shows every series when all of the remaining ones would be
  hidden, so a legend filter can't leave a chart empty after a range
  change.
- The command palette finds the billing page by "usage" and "invoices".

Checked with Biome, tsc and the billing, metrics and serverless
functions tests.
@dbm03
dbm03 force-pushed the feat/billing-metrics branch from 50da661 to 555e4c7 Compare November 20, 2026 07:59
@dbm03
dbm03 enabled stacked auto-merge (squash) November 20, 2026 08:11
@dbm03
dbm03 disabled stacked auto-merge November 20, 2026 08:11
@dbm03
dbm03 enabled stacked auto-merge (squash) November 20, 2026 08:13
@dbm03
dbm03 merged commit 05fea77 into main Nov 20, 2026
13 checks passed
@dbm03
dbm03 deleted the feat/billing-metrics branch November 20, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants