Skip to content

feat: data volume analytics#31

Merged
TerrifiedBug merged 11 commits intomainfrom
feat/data-analytics
Mar 7, 2026
Merged

feat: data volume analytics#31
TerrifiedBug merged 11 commits intomainfrom
feat/data-analytics

Conversation

@TerrifiedBug
Copy link
Copy Markdown
Owner

Summary

  • Add volumeAnalytics tRPC procedure to the dashboard router that computes current/previous period aggregates, per-pipeline breakdowns, and bucketed time series for data volume
  • Add /analytics page with KPI cards (Total In, Total Out, Reduction %), an area chart for volume over time, and a sortable per-pipeline breakdown table
  • Add "Analytics" sidebar nav item with BarChart3 icon after "Alerts"
  • Update docs/public/user-guide/dashboard.md with Data Volume Analytics documentation

Test plan

  • Navigate to /analytics and verify page loads with environment selected
  • Toggle time range selector (1h, 6h, 1d, 7d, 30d) and verify data updates
  • Verify KPI cards show correct bytes formatting and trend arrows
  • Verify area chart renders bytesIn/bytesOut with correct colors
  • Verify per-pipeline table is sortable by all columns
  • Verify reduction % bar colors: green (>=50%), amber (20-50%), red (<20%)
  • Verify sidebar shows "Analytics" item between "Alerts" and "Settings"
  • Verify page shows placeholder when no environment is selected

Add a new tRPC query that computes data volume analytics for the
selected environment and time range: current/previous period
aggregates for trend comparison, per-pipeline breakdown, and
bucketed time series for charts.
Build the /analytics page with KPI cards (Total In, Total Out,
Reduction %), a volume-over-time area chart using Recharts, and
a sortable per-pipeline breakdown table with colored reduction bars.
Place Analytics with BarChart3 icon after Alerts in the sidebar
navigation.
Document the new Analytics page including KPI cards, volume chart,
per-pipeline breakdown table, and time range selector.
Annotate PipelineRow interface and lambda parameters to satisfy
strict implicit-any checks.
@github-actions github-actions bot added documentation Improvements or additions to documentation feature labels Mar 7, 2026
Replace useMemo with direct computation to avoid
preserve-manual-memoization lint errors from the React Compiler.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR adds a Data Volume Analytics page (/analytics) backed by a new volumeAnalytics tRPC query, surfacing aggregate KPI cards, a bucketed area chart, and a sortable per-pipeline breakdown table. The issues raised in the previous review round have all been addressed: formatBytes now covers the TB range, formatTimeAxis now uses date labels for both 7d and 30d, the KPI reduction card has a correct three-way green/amber/red color scheme matching the table's >= 20 amber threshold, the time-series findMany is capped at 50,000 rows with desc ordering (preserving the most-recent data), and the comment accurately documents the drop-oldest behaviour when the cap is hit.

Key changes:

  • src/lib/format.ts — TB tier added to formatBytes; 30d grouped with 7d in formatTimeAxis for date-based labels
  • src/server/routers/dashboard.tsvolumeAnalytics query with withTeamAccess("VIEWER"), three unbounded aggregate()/groupBy() calls for KPI accuracy, and a take: 50_000 + orderBy: desc guard for the chart time-series
  • src/app/(dashboard)/analytics/page.tsx — new client page: range selector, three KPI cards, Recharts AreaChart, and a client-side sorted per-pipeline table
  • src/components/app-sidebar.tsx — "Analytics" nav item added between Alerts and Settings
  • src/app/(dashboard)/pipelines/[id]/page.tsxuseMemo(() => …, [])useState(() => …) cleanup

Confidence Score: 4/5

  • This PR is safe to merge; the functionality is well-scoped, authorization is correctly applied, and the critical issues from the previous review round have all been resolved.
  • All previously flagged correctness issues (color-threshold mismatch, missing red state, missing TB range, unbounded OOM query, misleading comment, unreadable 30d axis labels) are addressed in this revision. No new critical or important bugs were found. The aggregate() queries used for KPI totals are unbounded by design and correct. The take: 50_000 guard with desc ordering is a reasonable trade-off documented accurately in the comment. Authorization uses the standard withTeamAccess("VIEWER") middleware pattern consistent with the rest of the dashboard router.
  • No files require special attention.

Important Files Changed

Filename Overview
src/app/(dashboard)/analytics/page.tsx New analytics page with KPI cards, area chart, and sortable per-pipeline table; previous review issues (color thresholds, missing red state, formatBytes TB range) are now addressed.
src/server/routers/dashboard.ts New volumeAnalytics tRPC query with proper withTeamAccess("VIEWER") middleware, take: 50_000 OOM guard with desc ordering to preserve recent data, and accurate comment describing the cap behavior.
src/lib/format.ts Added TB tier to formatBytes and extended formatTimeAxis to use date labels for 30d range (same as 7d), resolving both previously flagged issues.

Sequence Diagram

sequenceDiagram
    participant Browser as Analytics Page
    participant tRPC as tRPC / Next.js
    participant MW as withTeamAccess("VIEWER")
    participant DB as PostgreSQL (Prisma)

    Browser->>tRPC: volumeAnalytics({ environmentId, range })
    tRPC->>MW: verify team membership via environmentId
    MW-->>tRPC: authorized (or throws FORBIDDEN)
    tRPC->>DB: aggregate() — current period _sum
    tRPC->>DB: aggregate() — previous period _sum
    tRPC->>DB: groupBy(pipelineId) — per-pipeline _sum
    tRPC->>DB: findMany(pipelineIds) — fetch names
    tRPC->>DB: findMany(take:50000, orderBy:desc) — raw metrics for chart
    DB-->>tRPC: rawMetrics (≤50k rows, most-recent first)
    Note over tRPC: JS bucketing into time buckets
    tRPC-->>Browser: { current, previous, perPipeline, timeSeries }
    Browser->>Browser: render KPI cards, AreaChart, sortable table
Loading

Last reviewed commit: bd8bddb

- Inline timeSeries/perPipeline data access to fix React Compiler memoization errors
- Replace useMemo with useState for Date.now() to fix impure function call
- Remove unused useMemo import
- Remove unused componentKey destructuring in detail panel
- Cap raw metrics query to 50k rows to prevent OOM on large 30d windows
- Make reduction % color thresholds consistent (>=50% green, >=20% amber)
  between KPI card and per-pipeline table
- Handle 30d range in formatTimeAxis to show date labels instead of
  time-only labels
Add TB threshold to shared formatBytes utility and remove duplicate
formatVolumeBytes function from analytics page, ensuring consistent
byte formatting across the application.
@TerrifiedBug TerrifiedBug merged commit 28ef059 into main Mar 7, 2026
12 checks passed
@TerrifiedBug TerrifiedBug deleted the feat/data-analytics branch March 7, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant