Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[D1] add rows read/written to wrangler d1 info output #4621

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/four-students-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

feat: add rows written/read in the last 24 hours to `wrangler d1 info` output
20 changes: 18 additions & 2 deletions packages/wrangler/src/d1/info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
sum {
readQueries
writeQueries
rowsRead
rowsWritten
}
dimensions {
datetimeHour
Expand Down Expand Up @@ -90,16 +92,25 @@
},
});

const metrics = { readQueries: 0, writeQueries: 0 };
const metrics = {

Check warning on line 95 in packages/wrangler/src/d1/info.tsx

View check run for this annotation

Codecov / codecov/patch

packages/wrangler/src/d1/info.tsx#L95

Added line #L95 was not covered by tests
readQueries: 0,
writeQueries: 0,
rowsRead: 0,
rowsWritten: 0,
};
if (graphqlResult) {
graphqlResult.data?.viewer?.accounts[0]?.d1AnalyticsAdaptiveGroups?.forEach(
(row) => {
metrics.readQueries += row?.sum?.readQueries ?? 0;
metrics.writeQueries += row?.sum?.writeQueries ?? 0;
metrics.rowsRead += row?.sum?.rowsRead ?? 0;
metrics.rowsWritten += row?.sum?.rowsWritten ?? 0;
}
);
output.read_queries_24h = metrics.readQueries;
output.write_queries_24h = metrics.writeQueries;
output.rows_read_24h = metrics.rowsRead;
output.rows_written_24h = metrics.rowsWritten;

Check warning on line 113 in packages/wrangler/src/d1/info.tsx

View check run for this annotation

Codecov / codecov/patch

packages/wrangler/src/d1/info.tsx#L112-L113

Added lines #L112 - L113 were not covered by tests
}
}

Expand All @@ -113,7 +124,12 @@
let value;
if (k === "database_size") {
value = prettyBytes(Number(v));
} else if (k === "read_queries_24h" || k === "write_queries_24h") {
} else if (
k === "read_queries_24h" ||
k === "write_queries_24h" ||
k === "rows_read_24h" ||
k === "rows_written_24h"

Check warning on line 131 in packages/wrangler/src/d1/info.tsx

View check run for this annotation

Codecov / codecov/patch

packages/wrangler/src/d1/info.tsx#L128-L131

Added lines #L128 - L131 were not covered by tests
) {
value = v.toLocaleString();
} else {
value = v;
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/d1/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface D1Metrics {
sum?: {
readQueries?: number;
writeQueries?: number;
rowsRead?: number;
rowsWritten?: number;
queryBatchResponseBytes?: number;
};
quantiles?: {
Expand Down