Skip to content

Conversation

@jnsdls
Copy link
Member

@jnsdls jnsdls commented Apr 14, 2025

closes: TOOL-4079

TL;DR

Added RPC usage chart to the team usage overview page.

What changed?

  • Created a new API endpoint fetchRPCUsage to retrieve RPC usage data from the analytics service
  • Added a stacked bar chart to visualize RPC usage in the team usage overview page
  • The chart displays both regular RPC requests and rate-limited requests
  • Replaced the static "Unlimited Requests" display with an interactive visualization

How to test?

  1. Navigate to a team's usage overview page
  2. Verify that the RPC Requests section now shows a stacked bar chart
  3. Confirm that the chart displays data for the past 7 days
  4. Check that the chart properly differentiates between regular RPC requests and rate-limited requests

Why make this change?

This change provides teams with better visibility into their RPC usage patterns over time, allowing them to monitor both successful requests and rate-limited requests. This visualization helps teams understand their API consumption patterns and make informed decisions about their plan requirements.


PR-Codex overview

This PR introduces functionality to fetch and display RPC usage data for teams, enhancing the dashboard's analytics capabilities.

Detailed summary

  • Added RPCUsageDataItem type and fetchRPCUsage function in rpc.ts.
  • Integrated fetchRPCUsage in the usage page to retrieve RPC data.
  • Updated Usage component to accept and process rpcUsage data.
  • Replaced RPC metrics display with a ThirdwebBarChart for visual representation of RPC requests.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@changeset-bot
Copy link

changeset-bot bot commented Apr 14, 2025

⚠️ No Changeset found

Latest commit: 3f42f52

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Apr 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 14, 2025 8:33pm
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Skipped (Inspect) Apr 14, 2025 8:33pm
login ⬜️ Skipped (Inspect) Apr 14, 2025 8:33pm
thirdweb_playground ⬜️ Skipped (Inspect) Apr 14, 2025 8:33pm
wallet-ui ⬜️ Skipped (Inspect) Apr 14, 2025 8:33pm

@vercel vercel bot temporarily deployed to Preview – login April 14, 2025 15:17 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui April 14, 2025 15:17 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 April 14, 2025 15:17 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground April 14, 2025 15:17 Inactive
@github-actions github-actions bot added the Dashboard Involves changes to the Dashboard. label Apr 14, 2025
@jnsdls jnsdls marked this pull request as ready for review April 14, 2025 15:17
@jnsdls jnsdls requested review from a team as code owners April 14, 2025 15:17
Copy link
Member Author

jnsdls commented Apr 14, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@linear
Copy link

linear bot commented Apr 14, 2025

@codecov
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.93%. Comparing base (bb29e1f) to head (3f42f52).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6719   +/-   ##
=======================================
  Coverage   54.93%   54.93%           
=======================================
  Files         890      890           
  Lines       56002    56002           
  Branches     3820     3820           
=======================================
  Hits        30762    30762           
  Misses      25145    25145           
  Partials       95       95           
Flag Coverage Δ
packages 54.93% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 14, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 47.67 KB (0%) 954 ms (0%) 229 ms (+303.01% 🔺) 1.2 s
thirdweb (cjs) 130.06 KB (0%) 2.7 s (0%) 342 ms (+113.74% 🔺) 3 s
thirdweb (minimal + tree-shaking) 5.62 KB (0%) 113 ms (0%) 117 ms (+1378.68% 🔺) 229 ms
thirdweb/chains (tree-shaking) 514 B (0%) 11 ms (0%) 72 ms (+4019.85% 🔺) 82 ms
thirdweb/react (minimal + tree-shaking) 19.36 KB (0%) 388 ms (0%) 93 ms (+670.16% 🔺) 480 ms

name="RPC Requests"
description={`Your plan allows for ${usageData.rateLimits.rpc} requests per second.`}
>
<ThirdwebBarChart
Copy link
Member

Choose a reason for hiding this comment

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

Just pass the title and description to ThirdwebBarChart instead of putting it inside another card component

Copy link
Member

Choose a reason for hiding this comment

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

let me push this change

@MananTank MananTank force-pushed the Add_RPC_usage_chart_to_dashboard branch from 74aa063 to e4f6c00 Compare April 14, 2025 20:11
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground April 14, 2025 20:11 Inactive
@vercel vercel bot temporarily deployed to Preview – login April 14, 2025 20:11 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui April 14, 2025 20:11 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 April 14, 2025 20:11 Inactive
@MananTank MananTank force-pushed the Add_RPC_usage_chart_to_dashboard branch from e4f6c00 to 132a790 Compare April 14, 2025 20:12
@vercel vercel bot temporarily deployed to Preview – docs-v2 April 14, 2025 20:12 Inactive
@vercel vercel bot temporarily deployed to Preview – login April 14, 2025 20:12 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground April 14, 2025 20:12 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui April 14, 2025 20:12 Inactive
Comment on lines +81 to +99
const rpcUsageData = useMemo(() => {
const mappedRPCUsage = rpcUsage.reduce(
(acc, curr) => {
switch (curr.usageType) {
case "rate-limit":
acc[curr.date] = {
...(acc[curr.date] || {}),
"rate-limit":
(acc[curr.date]?.["rate-limit"] || 0) + Number(curr.count),
included: acc[curr.date]?.included || 0,
};
break;
default:
acc[curr.date] = {
...(acc[curr.date] || {}),
"rate-limit": acc[curr.date]?.["rate-limit"] || 0,
included: (acc[curr.date]?.included || 0) + Number(curr.count),
};
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a potential issue in the reduce function's switch statement. When processing multiple records for the same date with different usageType values, the current implementation might not correctly accumulate values.

In both switch cases, the code should add to existing values rather than potentially overwriting them. Consider refactoring to ensure proper accumulation:

acc[curr.date] = {
  ...(acc[curr.date] || {}),
  "rate-limit": (acc[curr.date]?.["rate-limit"] || 0) + (curr.usageType === "rate-limit" ? Number(curr.count) : 0),
  included: (acc[curr.date]?.included || 0) + (curr.usageType !== "rate-limit" ? Number(curr.count) : 0)
};

This approach would handle all usageType values in a single consistent pattern, ensuring values are properly accumulated regardless of processing order.

Suggested change
const rpcUsageData = useMemo(() => {
const mappedRPCUsage = rpcUsage.reduce(
(acc, curr) => {
switch (curr.usageType) {
case "rate-limit":
acc[curr.date] = {
...(acc[curr.date] || {}),
"rate-limit":
(acc[curr.date]?.["rate-limit"] || 0) + Number(curr.count),
included: acc[curr.date]?.included || 0,
};
break;
default:
acc[curr.date] = {
...(acc[curr.date] || {}),
"rate-limit": acc[curr.date]?.["rate-limit"] || 0,
included: (acc[curr.date]?.included || 0) + Number(curr.count),
};
break;
const rpcUsageData = useMemo(() => {
const mappedRPCUsage = rpcUsage.reduce(
(acc, curr) => {
acc[curr.date] = {
...(acc[curr.date] || {}),
"rate-limit": (acc[curr.date]?.["rate-limit"] || 0) + (curr.usageType === "rate-limit" ? Number(curr.count) : 0),
included: (acc[curr.date]?.included || 0) + (curr.usageType !== "rate-limit" ? Number(curr.count) : 0)
};
return acc;
},

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@graphite-app
Copy link
Contributor

graphite-app bot commented Apr 14, 2025

Merge activity

closes: TOOL-4079

### TL;DR

Added RPC usage chart to the team usage overview page.

### What changed?

- Created a new API endpoint `fetchRPCUsage` to retrieve RPC usage data from the analytics service
- Added a stacked bar chart to visualize RPC usage in the team usage overview page
- The chart displays both regular RPC requests and rate-limited requests
- Replaced the static "Unlimited Requests" display with an interactive visualization

### How to test?

1. Navigate to a team's usage overview page
2. Verify that the RPC Requests section now shows a stacked bar chart
3. Confirm that the chart displays data for the past 7 days
4. Check that the chart properly differentiates between regular RPC requests and rate-limited requests

### Why make this change?

This change provides teams with better visibility into their RPC usage patterns over time, allowing them to monitor both successful requests and rate-limited requests. This visualization helps teams understand their API consumption patterns and make informed decisions about their plan requirements.

<!-- start pr-codex -->

---

## PR-Codex overview
This PR introduces a new feature to fetch and display RPC usage data in the dashboard. It enhances the usage overview by integrating RPC metrics, providing insights into included and rate-limited requests.

### Detailed summary
- Added `RPCUsageDataItem` type and `fetchRPCUsage` function in `rpc.ts`.
- Updated `page.tsx` to fetch RPC usage data alongside account usage and subscriptions.
- Passed `rpcUsage` data to the `Usage` component.
- Modified `Usage` component to process and display RPC usage data using `ThirdwebBarChart`.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
@graphite-app graphite-app bot force-pushed the Add_RPC_usage_chart_to_dashboard branch from 132a790 to 3f42f52 Compare April 14, 2025 20:27
@vercel vercel bot temporarily deployed to Preview – docs-v2 April 14, 2025 20:27 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground April 14, 2025 20:27 Inactive
@vercel vercel bot temporarily deployed to Preview – login April 14, 2025 20:27 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui April 14, 2025 20:27 Inactive
@graphite-app graphite-app bot merged commit 3f42f52 into main Apr 14, 2025
32 checks passed
@graphite-app graphite-app bot deleted the Add_RPC_usage_chart_to_dashboard branch April 14, 2025 20:34
@vercel vercel bot temporarily deployed to Production – wallet-ui April 14, 2025 20:34 Inactive
@vercel vercel bot temporarily deployed to Production – thirdweb_playground April 14, 2025 20:34 Inactive
@vercel vercel bot temporarily deployed to Production – docs-v2 April 14, 2025 20:34 Inactive
@vercel vercel bot temporarily deployed to Production – login April 14, 2025 20:34 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dashboard Involves changes to the Dashboard.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants