Skip to content

Commit

Permalink
[new] Support per-id rate limits
Browse files Browse the repository at this point in the history
Introduced `:rate-limit-id` option to all signals. When present,
this'll cause limits to be per id.
  • Loading branch information
ptaoussanis committed Sep 19, 2024
1 parent 9a91f4a commit 1810352
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Signal options (shared by all signal creators):
`:sample-rate` - ?rate ∈ℝ[0,1] for signal sampling (0.75 => allow 75% of signals, nil => allow all)
`:when` -------- Arb ?form; when present, form must return truthy to allow signal
`:rate-limit` -- ?spec as given to `taoensso.telemere/rate-limiter`, see its docstring for details
`:limit-req-id`- When present, rate limits will be enforced independently for each id (any Clojure value!)
`:middleware` -- Optional (fn [signal]) => ?modified-signal to apply when signal is created
`:trace?` ------ Should tracing be enabled for `:run` form?

Expand Down
20 changes: 10 additions & 10 deletions projects/main/src/taoensso/telemere/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@
'([{:as opts :keys
[#_defaults #_elide? #_allow? #_expansion-id, ; Undocumented
elidable? location #_location* inst uid middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit limit-req-id,
ctx parent root trace?, do let data msg error run & kvs]}])

:signal-allowed?
'([{:as opts :keys
[#_defaults #_elide? #_allow? #_expansion-id, ; Undocumented
elidable? location #_location* #_inst #_uid #_middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit limit-req-id,
#_ctx #_parent #_root #_trace?, #_do #_let #_data #_msg #_error #_run #_& #_kvs]}])

:event! ; [id] [id level-or-opts] => allowed?
Expand All @@ -395,7 +395,7 @@
{:as opts :keys
[#_defaults #_elide? #_allow? #_expansion-id,
elidable? location #_location* inst uid middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit limit-req-id,
ctx parent root trace?, do let data msg error #_run & kvs]}])

:log! ; [msg] [level-or-opts msg] => allowed?
Expand All @@ -404,7 +404,7 @@
[{:as opts :keys
[#_defaults #_elide? #_allow? #_expansion-id,
elidable? location #_location* inst uid middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit limit-req-id,
ctx parent root trace?, do let data msg error #_run & kvs]}
msg])

Expand All @@ -414,7 +414,7 @@
[{:as opts :keys
[#_defaults #_elide? #_allow? #_expansion-id,
elidable? location #_location* inst uid middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit limit-req-id,
ctx parent root trace?, do let data msg error #_run & kvs]}
error])

Expand All @@ -424,7 +424,7 @@
[{:as opts :keys
[#_defaults #_elide? #_allow? #_expansion-id,
elidable? location #_location* inst uid middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit limit-req-id,
ctx parent root trace?, do let data msg error run & kvs]}
form])

Expand All @@ -434,7 +434,7 @@
[{:as opts :keys
[#_defaults #_elide? #_allow? #_expansion-id,
elidable? location #_location* inst uid middleware,
sample-rate kind ns id level when rate-limit rate-limit-id,
sample-rate kind ns id level when rate-limit limit-req-id,
ctx parent root trace?, do let data msg error run & kvs]}
form])

Expand All @@ -444,7 +444,7 @@
[{:as opts :keys
[#_defaults #_elide? #_allow? #_expansion-id, rethrow? catch-val,
elidable? location #_location* inst uid middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit limit-req-id,
ctx parent root trace?, do let data msg error #_run & kvs]}
form])

Expand All @@ -454,7 +454,7 @@
[{:as opts :keys
[#_defaults #_elide? #_allow? #_expansion-id,
elidable? location #_location* inst uid middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit limit-req-id,
ctx parent root trace?, do let data msg error #_run & kvs]}])

(enc/unexpected-arg! macro-id))))
Expand Down Expand Up @@ -626,7 +626,7 @@
(not-empty
(dissoc opts
:elidable? :location :location* :inst :uid :middleware,
:sample-rate :ns :kind :id :level :filter :when #_:rate-limit,
:sample-rate :ns :kind :id :level :filter :when #_:rate-limit #_:limit-req-id,
:ctx :parent #_:trace?, :do :let :data :msg :error :run,
:elide? :allow? #_:expansion-id :otel/context))

Expand Down
4 changes: 2 additions & 2 deletions projects/shell/src/taoensso/telemere/shell.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
[fallback, ; Unique to shell
#_defaults #_elide? #_allow? #_expansion-id, ; Undocumented
elidable? location #_location* inst uid middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit rate-limit-id,
ctx parent root trace?, do let data msg error run & kvs]}])}

[opts]
Expand Down Expand Up @@ -172,7 +172,7 @@
[#_fallback, ; Unique to shell
#_defaults #_elide? #_allow? #_expansion-id, ; Undocumented
elidable? location #_location* #_inst #_uid #_middleware,
sample-rate kind ns id level when rate-limit,
sample-rate kind ns id level when rate-limit limit-req-id,
#_ctx #_parent #_root #_trace?, #_do #_let #_data #_msg #_error #_run #_& #_kvs]}])}

[opts]
Expand Down

0 comments on commit 1810352

Please sign in to comment.