Skip to content

Commit

Permalink
fix: Ensure last ratelimit usage is shown (#2721)
Browse files Browse the repository at this point in the history
* fix: order by time and add limit

* chore: go mod tidy

* fix: remove file that is not in use anymore

* fix: add missing limit...

---------

Co-authored-by: Andreas Thomas <[email protected]>
  • Loading branch information
Flo4604 and chronark authored Dec 10, 2024
1 parent f4fc984 commit c6dfe2d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 64 deletions.
9 changes: 0 additions & 9 deletions apps/chproxy/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
module github.com/unkeyed/unkey/apps/chproxy

go 1.23.2

require (
github.com/influxdata/tdigest v0.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/tsenart/vegeta v12.7.0+incompatible // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/text v0.20.0 // indirect
)
17 changes: 0 additions & 17 deletions apps/chproxy/go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/influxdata/tdigest v0.0.1 h1:XpFptwYmnEKUqmkcDjrzffswZ3nvNeevbUSLPP/ZzIY=
github.com/influxdata/tdigest v0.0.1/go.mod h1:Z0kXnxzbTC2qrx4NaIzYkE1k66+6oEDQTvL95hQFh5Y=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/tsenart/vegeta v12.7.0+incompatible h1:sGlrv11EMxQoKOlDuMWR23UdL90LE5VlhKw/6PWkZmU=
github.com/tsenart/vegeta v12.7.0+incompatible/go.mod h1:Smz/ZWfhKRcyDDChZkG3CyTHdj87lHzio/HOCkbndXM=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const LastUsed: React.FC<{
workspaceId,
namespaceId,
identifier: [identifier],
limit: 1,
});

const unixMilli = lastUsed.val?.at(0)?.time;
Expand Down
6 changes: 5 additions & 1 deletion apps/dashboard/app/(app)/ratelimits/[namespaceId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export default async function RatelimitNamespacePage(props: {
end: billingCycleEnd,
}).then((res) => res.val!),
clickhouse.ratelimits
.latest({ workspaceId: namespace.workspaceId, namespaceId: namespace.id })
.latest({
workspaceId: namespace.workspaceId,
namespaceId: namespace.id,
limit: 1,
})
.then((res) => res.val?.at(0)?.time),
]);

Expand Down
6 changes: 5 additions & 1 deletion apps/dashboard/app/(app)/ratelimits/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export const RatelimitCard: React.FC<Props> = async ({ workspace, namespace }) =
})
.then((res) => res.val!),
clickhouse.ratelimits
.latest({ workspaceId: workspace.id, namespaceId: namespace.id })
.latest({
workspaceId: workspace.id,
namespaceId: namespace.id,
limit: 1,
})
.then((res) => res.val?.at(0)?.time),
]);

Expand Down
36 changes: 0 additions & 36 deletions internal/clickhouse/src/last_used.ts

This file was deleted.

3 changes: 3 additions & 0 deletions internal/clickhouse/src/ratelimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const getRatelimitLastUsedParameters = z.object({
workspaceId: z.string(),
namespaceId: z.string(),
identifier: z.array(z.string()).optional(),
limit: z.number().int(),
});

export function getRatelimitLastUsed(ch: Querier) {
Expand All @@ -213,6 +214,8 @@ export function getRatelimitLastUsed(ch: Querier) {
AND namespace_id = {namespaceId: String}
${args.identifier ? "AND multiSearchAny(identifier, {identifier: Array(String)}) > 0" : ""}
GROUP BY identifier
ORDER BY time DESC
LIMIT {limit: Int}
;`,
params: getRatelimitLastUsedParameters,
schema: z.object({
Expand Down

0 comments on commit c6dfe2d

Please sign in to comment.