Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default async function AuditPage(props: Props) {
{namespace.name}
</Navbar.Breadcrumbs.Link>
<Navbar.Breadcrumbs.Link href={`/ratelimits/${props.params.namespaceId}/logs`} active>
Logs{" "}
Logs
</Navbar.Breadcrumbs.Link>
</Navbar.Breadcrumbs>
<Navbar.Actions>
Expand Down Expand Up @@ -150,7 +150,7 @@ const AuditLogTable: React.FC<{
country: selected.country.length > 0 ? selected.country : undefined,
ipAddress: selected.ipAddress.length > 0 ? selected.ipAddress : undefined,

success: selected.success ?? undefined,
passed: selected.success ?? undefined,
};
const logs = await clickhouse.ratelimits.logs(query).then((res) => res.val!);

Expand Down
39 changes: 19 additions & 20 deletions internal/clickhouse/src/ratelimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,33 +168,32 @@ const getRatelimitLogsParameters = z.object({

export function getRatelimitLogs(ch: Querier) {
return async (args: z.input<typeof getRatelimitLogsParameters>) => {
const query = ch.query({
query: `
SELECT
request_id,
time,
identifier,
passed
FROM ratelimits.raw_ratelimits_v1
WHERE workspace_id = {workspaceId: String}
AND namespace_id = {namespaceId: String}
${args.identifier ? "AND multiSearchAny(identifier, {identifier: Array(String)}) > 0" : ""}
AND time >= {start: Int64}
AND time <= {end: Int64}
${typeof args.passed !== "undefined" ? "passed = {passed:Boolean}" : ""}
ORDER BY time DESC
LIMIT {limit: Int64}
;`,
const query = `
SELECT
request_id,
time,
identifier,
passed
FROM ratelimits.raw_ratelimits_v1
WHERE workspace_id = {workspaceId: String}
AND namespace_id = {namespaceId: String}
${args.identifier ? "AND multiSearchAny(identifier, {identifier: Array(String)}) > 0" : ""}
AND time >= {start: Int64}
AND time <= {end: Int64}
${typeof args.passed !== "undefined" ? "AND passed = {passed:Boolean}" : ""}
ORDER BY time DESC
LIMIT {limit: Int64}
;`;
return ch.query({
query: query,
params: getRatelimitLogsParameters,
schema: z.object({
request_id: z.string(),
time: z.number(),
identifier: z.string(),
passed: z.boolean(),
}),
});

return query(args);
})(args);
};
}
const getRatelimitLastUsedParameters = z.object({
Expand Down