Skip to content

Commit d74d78a

Browse files
committed
Fix RPC usage graphs and improve rate limit visualization
1 parent e29f749 commit d74d78a

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

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

Lines changed: 24 additions & 14 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ export default async function RPCUsage(props: {
196196
<RateGraph
197197
peakPercentage={peakPercentage}
198198
currentRateLimit={currentRateLimit}
199-
data={apiData.data.averageRate}
199+
data={apiData.data.averageRate.slice(1)}
200200
/>
201201

202202
<CountGraph
203203
peakPercentage={peakPercentage}
204204
currentRateLimit={currentRateLimit}
205-
data={apiData.data.averageRate}
205+
data={apiData.data.averageRate.slice(1)}
206206
/>
207207
</div>
208208
);

0 commit comments

Comments
 (0)