Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions server/src/instant/admin/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
[instant.model.app-user-refresh-token :as app-user-refresh-token-model]
[instant.model.rule :as rule-model]
[instant.model.instant-user :as instant-user-model]
[instant.rate-limit :as rate-limit]
[instant.reactive.receive-queue :as receive-queue]
[instant.reactive.session :as session]
[instant.reactive.sse :as sse]
Expand Down Expand Up @@ -144,6 +145,12 @@
(let [query (ex/get-param! req [:body :query] #(when (map? %) %))
inference? (-> req :body :inference? boolean)
{:keys [app-id] :as perms} (get-perms! req :data/read)
_ (when-let [rate-limit-config (flags/app-admin-rate-limit-config app-id)]
(rate-limit/consume-user-rate-limit (eph/get-rate-limit)
{:app-id app-id
:bucket-key app-id
:bucket-name "__instant-admin-query"
:config rate-limit-config}))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
attrs (attr-model/get-by-app-id app-id)
ctx (merge {:db {:conn-pool (aurora/conn-pool :read)}
:app-id app-id
Expand Down Expand Up @@ -269,6 +276,12 @@
req
[:body :throw-on-missing-attrs?] boolean)
{:keys [app-id] :as perms} (get-perms! req :data/write)
_ (when-let [rate-limit-config (flags/app-admin-rate-limit-config app-id)]
(rate-limit/consume-user-rate-limit (eph/get-rate-limit)
{:app-id app-id
:bucket-key app-id
:bucket-name "__instant-admin-transact"
:config rate-limit-config}))
attrs (attr-model/get-by-app-id app-id)
ctx (merge {:db {:conn-pool (aurora/conn-pool :write)}
:app-id app-id
Expand Down
14 changes: 14 additions & 0 deletions server/src/instant/flags.clj
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,17 @@
users keep team access after we cancel their Stripe subscriptions."
[]
(sunset-stage-at-least? :signups-closed))

(defn app-admin-rate-limit-config
"Config for rate-limiting admin transact and query.
The config should look like:
{\"limits\": [
{\"capacity\": 10,
\"refill\": {
\"period\": \"1 hour\",
\"amount\": 10,
\"type\": \"interval\" // or \"greedy\"}}]}
Make sure to key by app_id for admin-rate-limit-for-app"
[app-id]
(or (get (flag :admin-rate-limit-for-app) (str app-id))
(flag :global-admin-rate-limit)))
Loading