-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
95 additions
and
53 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...gent/pkg/clickhouse/schema/009_create_verifications_key_verifications_per_month_mv_v1.sql
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
16 changes: 16 additions & 0 deletions
16
...agent/pkg/clickhouse/schema/013_create_billing_billable_verifications_per_month_mv_v1.sql
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,16 @@ | ||
-- +goose up | ||
CREATE MATERIALIZED VIEW billing.billable_verifications_per_month_mv_v1 | ||
TO billing.billable_verifications_per_month_v1 | ||
AS | ||
SELECT | ||
workspace_id, | ||
count(*) AS count, | ||
toYear(time) AS year, | ||
toMonth(time) AS month | ||
FROM verifications.key_verifications_per_month_v1 | ||
WHERE outcome = 'VALID' | ||
GROUP BY | ||
workspace_id, | ||
year, | ||
month | ||
; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { z } from "zod"; | ||
import { clickhouse } from "./client"; | ||
|
||
// get the billable verifications for a workspace in a specific month. | ||
// month is not zero-indexed -> January = 1 | ||
export async function getBillableVerifications(args: { | ||
workspaceId: string; | ||
year: number; | ||
month: number; | ||
}): Promise<number> { | ||
const query = clickhouse.query({ | ||
query: ` | ||
SELECT | ||
sum(count) as count | ||
FROM billing.billable_verifications_per_month_v1 | ||
WHERE workspace_id = {workspaceId: String} | ||
AND year = {year: Int64} | ||
AND month = {month: Int64} | ||
GROUP BY workspace_id, year, month | ||
`, | ||
params: z.object({ | ||
workspaceId: z.string(), | ||
year: z.number().int(), | ||
month: z.number().int().min(1).max(12), | ||
}), | ||
schema: z.object({ | ||
count: z.number().int(), | ||
}), | ||
}); | ||
|
||
const res = await query(args); | ||
if (!res) { | ||
return 0; | ||
} | ||
return res.at(0)?.count ?? 0; | ||
} |
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
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