-
Notifications
You must be signed in to change notification settings - Fork 777
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add 24h read/write metrics to d1 info (#3434)
* fix: add 24h read/write metrics to d1 info * add test * add test * filter by db.uuid * fix: we can only fetch metrics for new dbs * fix: use toLocaleString to get human-readable numbers for now * fix: don't prettify json output * file_size -> database_size * remove date-fns, fix up some logic
- Loading branch information
Showing
6 changed files
with
230 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: add the number of read queries and write queries in the last 24 hours to the `d1 info` command |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
packages/wrangler/src/__tests__/fetch-graphql-result.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { rest } from "msw"; | ||
import { fetchGraphqlResult } from "../cfetch"; | ||
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id"; | ||
import { mockOAuthFlow } from "./helpers/mock-oauth-flow"; | ||
import { msw } from "./helpers/msw"; | ||
|
||
describe("fetchGraphqlResult", () => { | ||
mockAccountId({ accountId: null }); | ||
mockApiToken(); | ||
const { mockOAuthServerCallback } = mockOAuthFlow(); | ||
|
||
it("should make a request against the graphql endpoint by default", async () => { | ||
mockOAuthServerCallback(); | ||
msw.use( | ||
rest.post("*/graphql", async (req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
data: { | ||
viewer: { | ||
__typename: "viewer", | ||
}, | ||
}, | ||
errors: null, | ||
}) | ||
); | ||
}) | ||
); | ||
expect( | ||
await fetchGraphqlResult({ | ||
body: JSON.stringify({ | ||
query: `{ | ||
viewer { | ||
__typename | ||
} | ||
}`, | ||
}), | ||
}) | ||
).toEqual({ data: { viewer: { __typename: "viewer" } }, errors: null }); | ||
}); | ||
|
||
it("should accept a request with no init, but return no data", async () => { | ||
mockOAuthServerCallback(); | ||
const now = new Date().toISOString(); | ||
msw.use( | ||
rest.post("*/graphql", async (req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
data: null, | ||
errors: [ | ||
{ | ||
message: "failed to recognize JSON request: 'EOF'", | ||
path: null, | ||
extensions: { | ||
timestamp: now, | ||
}, | ||
}, | ||
], | ||
}) | ||
); | ||
}) | ||
); | ||
expect(await fetchGraphqlResult()).toEqual({ | ||
data: null, | ||
errors: [ | ||
{ | ||
message: "failed to recognize JSON request: 'EOF'", | ||
path: null, | ||
extensions: { | ||
timestamp: now, | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters