Skip to content

Commit baf95b9

Browse files
committed
Fix RPC usage graphs and improve rate limit visualization (#6737)
# Improve RPC Usage Graphs This PR enhances the RPC usage graphs in the dashboard: - Only show rate limited requests in the legend when there are actually rate limited requests - Fix data processing by removing the `.slice(1, -1)` which was incorrectly trimming data points - Ensure numeric values by explicitly converting to Number - Move data slicing to the parent component for better control - Add a type assertion comment to handle the TypeScript warning - Add a check to conditionally display relevant chart configuration These changes improve the accuracy and presentation of the RPC usage data visualization. <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the `CountGraph` component by improving the handling of rate-limited data and formatting the `currentRateLimit` value for better readability. ### Detailed summary - Updated the `currentRateLimit` display to use `toLocaleString()`. - Added a check for `hasAnyRateLimited` to conditionally configure the chart. - Modified the `config` object to include `rateLimitedCount` only if there are any rate-limited requests. - Converted `includedCount` and `rateLimitedCount` to `Number` type during data mapping. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent e29f749 commit baf95b9

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

apps/dashboard/src/app/team/[team_slug]/(team)/~/usage/rpc/components/count-graph.tsx

+24-14
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,34 @@ export function CountGraph(props: {
1313
rateLimitedCount: number;
1414
}[];
1515
}) {
16+
const hasAnyRateLimited = props.data.some((v) => v.rateLimitedCount > 0);
1617
return (
1718
<ThirdwebAreaChart
1819
chartClassName="aspect-[1.5] lg:aspect-[4]"
1920
header={{
2021
title: "Requests Over Time",
2122
description: "Requests over the last 24 hours. All times in UTC.",
2223
}}
23-
config={{
24-
includedCount: {
25-
label: "Successful Requests",
26-
color: "hsl(var(--chart-1))",
27-
},
28-
rateLimitedCount: {
29-
label: "Rate Limited Requests",
30-
color: "hsl(var(--chart-4))",
31-
},
32-
}}
33-
showLegend
24+
config={
25+
hasAnyRateLimited
26+
? {
27+
includedCount: {
28+
label: "Successful Requests",
29+
color: "hsl(var(--chart-1))",
30+
},
31+
rateLimitedCount: {
32+
label: "Rate Limited Requests",
33+
color: "hsl(var(--chart-4))",
34+
},
35+
}
36+
: {
37+
includedCount: {
38+
label: "Successful Requests",
39+
color: "hsl(var(--chart-1))",
40+
},
41+
}
42+
}
43+
showLegend={hasAnyRateLimited}
3444
yAxis
3545
xAxis={{
3646
sameDay: true,
@@ -39,13 +49,13 @@ export function CountGraph(props: {
3949
toolTipLabelFormatter={(label) => {
4050
return formatDate(new Date(label), "MMM dd, HH:mm");
4151
}}
52+
// @ts-expect-error - sending MORE data than expected is ok
4253
data={props.data
43-
.slice(1, -1)
4454
.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime())
4555
.map((v) => ({
4656
time: v.date,
47-
includedCount: v.includedCount + v.overageCount,
48-
rateLimitedCount: v.rateLimitedCount,
57+
includedCount: Number(v.includedCount) + Number(v.overageCount),
58+
rateLimitedCount: Number(v.rateLimitedCount),
4959
}))}
5060
isPending={false}
5161
/>

apps/dashboard/src/app/team/[team_slug]/(team)/~/usage/rpc/components/rate-graph.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export function RateGraph(props: {
3535
},
3636
}}
3737
data={props.data
38-
.slice(1, -1)
3938
.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime())
4039
.map((v) => ({
4140
time: v.date,

apps/dashboard/src/app/team/[team_slug]/(team)/~/usage/rpc/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default async function RPCUsage(props: {
8484
<CardContent>
8585
<div className="flex items-center justify-between">
8686
<div className="font-bold text-2xl capitalize">
87-
{currentRateLimit} RPS
87+
{currentRateLimit.toLocaleString()} RPS
8888
</div>
8989
<TeamPlanBadge plan={currentPlan} />
9090
</div>

0 commit comments

Comments
 (0)