Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
9be0244b
Commit
9be0244b
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
1bc77bc1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/api/common/throttle.clj
+10
-7
10 additions, 7 deletions
src/metabase/api/common/throttle.clj
with
10 additions
and
7 deletions
src/metabase/api/common/throttle.clj
+
10
−
7
View file @
9be0244b
...
...
@@ -49,21 +49,23 @@
(
declare
calculate-delay
remove-old-attempts
)
(
defrecord
Throttler
[
;; Name of the API field/value being checked. Used to generate appropriate API error messages, so
they'll be displayed in the
;; right part of the screen
(
defrecord
Throttler
[
;; Name of the API field/value being checked. Used to generate appropriate API error messages, so
;;
they'll be displayed on the
right part of the screen
^
Keyword
exception-field-key
;; [Internal] List of attempt entries. These are pairs of [key timestamp (ms)], e.g. ["cam@metabase.com" 1438045261132]
;; [Internal] List of attempt entries. These are pairs of [key timestamp (ms)],
;; e.g. ["cam@metabase.com" 1438045261132]
^
Atom
attempts
;; Amount of time to keep an entry in ATTEMPTS before dropping it.
^
Integer
attempt-ttl-ms
;; Number of attempts allowed with a given key before throttling is applied.
^
Integer
attempts-threshold
;; Once throttling is in effect, initial delay before allowing another attempt. This grows according to DELAY-EXPONENT.
;; Once throttling is in effect, initial delay before allowing another attempt. This grows
;; according to DELAY-EXPONENT.
^
Integer
initial-delay-ms
;; For each subsequent failure past ATTEMPTS-THRESHOLD, increase the delay by
;; (num-attempts-over-theshold ^ DELAY-EXPONENT). e.g. if `initial-delay-ms` is 15 and
;; `delay-exponent` is 2, the first attempt past attempts-threshold will require the user to wait
15 seconds (15 * 1^2),
;; the next attempt after that 60 seconds (15 * 2^2), then 135, and so on.
;; `delay-exponent` is 2, the first attempt past attempts-threshold will require the user to wait
;;
15 seconds (15 * 1^2),
the next attempt after that 60 seconds (15 * 2^2), then 135, and so on.
^
Integer
delay-exponent
])
;; These are made private because you should use `make-throttler` instead.
...
...
@@ -109,7 +111,8 @@
(
println
"RECENT ATTEMPTS:\n"
(
metabase.util/pprint-to-str
'cyan
@
(
:attempts
throttler
)))
;; TODO - remove debug logging
(
remove-old-attempts
throttler
)
(
when-let
[
delay-ms
(
calculate-delay
throttler
keyy
)]
(
let
[
message
(
format
"Too many attempts! You must wait %d seconds before trying again."
(
int
(
math/round
(
/
delay-ms
1000
))))]
(
let
[
message
(
format
"Too many attempts! You must wait %d seconds before trying again."
(
int
(
math/round
(
/
delay-ms
1000
))))]
(
throw
(
ex-info
message
{
:status-code
400
:errors
{
exception-field-key
message
}}))))
(
swap!
attempts
conj
[
keyy
(
System/currentTimeMillis
)]))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment