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
4 changes: 2 additions & 2 deletions apps/api/src/pkg/testutil/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export abstract class Harness {
const unkeyWorkspace: Workspace = {
id: newId("test"),
name: "unkey",
slug: "unkey-workspace",
slug: newId("test"),
orgId: newId("test"),
plan: "enterprise",
tier: "Enterprise",
Expand All @@ -273,7 +273,7 @@ export abstract class Harness {
const userWorkspace: Workspace = {
id: newId("test"),
name: "user",
slug: "user-workspace",
slug: newId("test"),
orgId: newId("test"),
plan: "pro",
tier: "Pro Max",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const RatelimitLogsTable = () => {
key: "region",
header: "Region",
width: "10%",
render: (log) => <div className="font-mono">{log.colo}</div>,
render: (log) => <div className="font-mono">{log.region}</div>,
},
{
key: "actions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export async function getAllKeys({
const tagQuery = clickhouse.querier.query({
query: `
SELECT DISTINCT key_id
FROM verifications.raw_key_verifications_v1
FROM default.key_verifications_raw_v2
WHERE workspace_id = {workspaceId: String}
AND key_space_id = {keyspaceId: String}
AND (${tagQueries.map(({ condition }) => condition).join(" OR ")})
Expand Down
123 changes: 0 additions & 123 deletions internal/clickhouse/src/active_keys.ts

This file was deleted.

4 changes: 2 additions & 2 deletions internal/clickhouse/src/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getBillableRatelimits(ch: Querier) {
query: `
SELECT
sum(count) as count
FROM billing.billable_ratelimits_per_month_v1
FROM default.billable_ratelimits_per_month_v2
WHERE workspace_id = {workspaceId: String}
AND year = {year: Int64}
AND month = {month: Int64}
Expand Down Expand Up @@ -48,7 +48,7 @@ export function getBillableVerifications(ch: Querier) {
query: `
SELECT
sum(count) as count
FROM billing.billable_verifications_per_month_v2
FROM default.billable_verifications_per_month_v2
WHERE workspace_id = {workspaceId: String}
AND year = {year: Int64}
AND month = {month: Int64}
Expand Down
28 changes: 14 additions & 14 deletions internal/clickhouse/src/keys/active_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,75 +62,75 @@ type TimeInterval = {
const ACTIVE_KEYS_INTERVALS: Record<string, TimeInterval> = {
// Minute-based intervals
minute: {
table: "verifications.key_verifications_per_minute_v1",
table: "default.key_verifications_per_minute_v2",
step: "MINUTE",
stepSize: 1,
},
fiveMinutes: {
table: "verifications.key_verifications_per_minute_v1",
table: "default.key_verifications_per_minute_v2",
step: "MINUTE",
stepSize: 5,
},
thirtyMinutes: {
table: "verifications.key_verifications_per_minute_v1",
table: "default.key_verifications_per_minute_v2",
step: "MINUTE",
stepSize: 30,
},
// Hour-based intervals
hour: {
table: "verifications.key_verifications_per_hour_v3",
table: "default.key_verifications_per_hour_v2",
step: "HOUR",
stepSize: 1,
},
twoHours: {
table: "verifications.key_verifications_per_hour_v3",
table: "default.key_verifications_per_hour_v2",
step: "HOUR",
stepSize: 2,
},
fourHours: {
table: "verifications.key_verifications_per_hour_v3",
table: "default.key_verifications_per_hour_v2",
step: "HOUR",
stepSize: 4,
},
sixHours: {
table: "verifications.key_verifications_per_hour_v3",
table: "default.key_verifications_per_hour_v2",
step: "HOUR",
stepSize: 6,
},
twelveHours: {
table: "verifications.key_verifications_per_hour_v3",
table: "default.key_verifications_per_hour_v2",
step: "HOUR",
stepSize: 12,
},
// Day-based intervals
day: {
table: "verifications.key_verifications_per_day_v3",
table: "default.key_verifications_per_day_v2",
step: "DAY",
stepSize: 1,
},
threeDays: {
table: "verifications.key_verifications_per_day_v3",
table: "default.key_verifications_per_day_v2",
step: "DAY",
stepSize: 3,
},
week: {
table: "verifications.key_verifications_per_day_v3",
table: "default.key_verifications_per_day_v2",
step: "DAY",
stepSize: 7,
},
twoWeeks: {
table: "verifications.key_verifications_per_day_v3",
table: "default.key_verifications_per_day_v2",
step: "DAY",
stepSize: 14,
},
// Monthly-based intervals
month: {
table: "verifications.key_verifications_per_month_v3",
table: "default.key_verifications_per_month_v2",
step: "MONTH",
stepSize: 1,
},
quarter: {
table: "verifications.key_verifications_per_month_v3",
table: "default.key_verifications_per_month_v2",
step: "MONTH",
stepSize: 3,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/clickhouse/src/keys/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ WITH
key_id,
tags,
outcome
FROM verifications.raw_key_verifications_v1
FROM default.key_verifications_raw_v2
WHERE workspace_id = {workspaceId: String}
AND key_space_id = {keyspaceId: String}
AND time BETWEEN {startTime: UInt64} AND {endTime: UInt64}
Expand Down
2 changes: 1 addition & 1 deletion internal/clickhouse/src/latest_verifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getLatestVerifications(ch: Querier) {
outcome,
region,
tags
FROM verifications.raw_key_verifications_v1
FROM default.key_verifications_raw_v2
WHERE workspace_id = {workspaceId: String}
AND key_space_id = {keySpaceId: String}
AND key_id = {keyId: String}
Expand Down
34 changes: 17 additions & 17 deletions internal/clickhouse/src/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,37 @@ export function getLogs(ch: Querier) {
const filterConditions = `
workspace_id = {workspaceId: String}
AND time BETWEEN {startTime: UInt64} AND {endTime: UInt64}

---------- Apply request ID filter if present (highest priority)
AND (
CASE
WHEN length({requestIds: Array(String)}) > 0 THEN
WHEN length({requestIds: Array(String)}) > 0 THEN
request_id IN {requestIds: Array(String)}
ELSE TRUE
END
)

---------- Apply host filter
AND (
CASE
WHEN length({hosts: Array(String)}) > 0 THEN
WHEN length({hosts: Array(String)}) > 0 THEN
host IN {hosts: Array(String)}
ELSE TRUE
END
)

---------- Apply method filter
AND (
CASE
WHEN length({methods: Array(String)}) > 0 THEN
WHEN length({methods: Array(String)}) > 0 THEN
method IN {methods: Array(String)}
ELSE TRUE
END
)

---------- Apply path filter using pre-generated conditions
AND (${pathConditions})

---------- Apply status code filter
AND (
CASE
Expand Down Expand Up @@ -133,7 +133,7 @@ export function getLogs(ch: Querier) {
query: `
SELECT
count(request_id) as total_count
FROM metrics.raw_api_requests_v1
FROM default.api_requests_raw_v2
WHERE ${filterConditions}`,
params: extendedParamsSchema,
schema: z.object({
Expand All @@ -157,7 +157,7 @@ export function getLogs(ch: Querier) {
response_body,
error,
service_latency
FROM metrics.raw_api_requests_v1
FROM default.api_requests_raw_v2
WHERE ${filterConditions} AND ({cursorTime: Nullable(UInt64)} IS NULL OR time < {cursorTime: Nullable(UInt64)})
ORDER BY time DESC
LIMIT {limit: Int}`,
Expand Down Expand Up @@ -310,34 +310,34 @@ function getLogsTimeseriesWhereClause(
"workspace_id = {workspaceId: String}",
// Host filter
`(CASE
WHEN length({hosts: Array(String)}) > 0 THEN
WHEN length({hosts: Array(String)}) > 0 THEN
host IN {hosts: Array(String)}
ELSE TRUE
END)`,
// Method filter
`(CASE
WHEN length({methods: Array(String)}) > 0 THEN
WHEN length({methods: Array(String)}) > 0 THEN
method IN {methods: Array(String)}
ELSE TRUE
END)`,
// Status code filter
`(CASE
`(CASE
WHEN length({statusCodes: Array(UInt16)}) > 0 THEN
response_status IN (
SELECT status
SELECT status
FROM (
SELECT multiIf(
code = 200, arrayJoin(range(200, 300)),
code = 400, arrayJoin(range(400, 500)),
code = 500, arrayJoin(range(500, 600)),
code
) as status
) as status
FROM (
SELECT arrayJoin({statusCodes: Array(UInt16)}) as code
)
)
)
ELSE TRUE
)
ELSE TRUE
END)`,
...additionalConditions,
];
Expand Down
Loading