mirror of
https://github.com/taoensso/telemere.git
synced 2025-12-16 17:41:12 +00:00
[new] Add :rate-limit-by option to all signal creators
When present, will cause limits to be per [expansion, by-value]
This commit is contained in:
parent
f703630914
commit
d9c3583631
5 changed files with 24 additions and 21 deletions
11
README.md
11
README.md
|
|
@ -74,11 +74,12 @@ It enables you to write code that is **information-verbose by default**.
|
|||
|
||||
;; Getting fancy (all costs are conditional!)
|
||||
(t/log!
|
||||
{:level :debug
|
||||
:sample-rate 0.75 ; 75% sampling (noop 25% of the time)
|
||||
:when (my-conditional)
|
||||
:rate-limit {"1 per sec" [1 1000]
|
||||
"5 per min" [5 60000]}
|
||||
{:level :debug
|
||||
:sample-rate 0.75 ; 75% sampling (noop 25% of the time)
|
||||
:when (my-conditional)
|
||||
:rate-limit {"1 per sec" [1 1000]
|
||||
"5 per min" [5 60000]}
|
||||
:rate-limit-by my-user-ip-address ; Optional rate-limit scope
|
||||
|
||||
:do (inc-my-metric!)
|
||||
:let
|
||||
|
|
|
|||
|
|
@ -34,11 +34,12 @@
|
|||
|
||||
;; Getting fancy (all costs are conditional!)
|
||||
(t/log!
|
||||
{:level :debug
|
||||
:sample-rate 0.75 ; 75% sampling (noop 25% of the time)
|
||||
:when (my-conditional)
|
||||
:rate-limit {"1 per sec" [1 1000]
|
||||
"5 per min" [5 60000]}
|
||||
{:level :debug
|
||||
:sample-rate 0.75 ; 75% sampling (noop 25% of the time)
|
||||
:when (my-conditional)
|
||||
:rate-limit {"1 per sec" [1 1000]
|
||||
"5 per min" [5 60000]}
|
||||
:rate-limit-by my-user-ip-address ; Optional rate-limit scope
|
||||
|
||||
:do (inc-my-metric!)
|
||||
:let
|
||||
|
|
|
|||
|
|
@ -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
|
||||
`:rate-limit-by` 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?
|
||||
|
||||
|
|
|
|||
|
|
@ -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 rate-limit-by,
|
||||
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 rate-limit-by,
|
||||
#_ctx #_parent #_root #_trace?, #_do #_let #_data #_msg #_error #_run #_& #_kvs]}])
|
||||
|
||||
:event! ; [id] [id level-or-opts] => allowed?
|
||||
|
|
@ -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 rate-limit-by,
|
||||
ctx parent root trace?, do let data msg error #_run & kvs]}])
|
||||
|
||||
:log! ; [msg] [level-or-opts msg] => allowed?
|
||||
|
|
@ -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 rate-limit-by,
|
||||
ctx parent root trace?, do let data msg error #_run & kvs]}
|
||||
msg])
|
||||
|
||||
|
|
@ -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 rate-limit-by,
|
||||
ctx parent root trace?, do let data msg error #_run & kvs]}
|
||||
error])
|
||||
|
||||
|
|
@ -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 rate-limit-by,
|
||||
ctx parent root trace?, do let data msg error run & kvs]}
|
||||
form])
|
||||
|
||||
|
|
@ -434,7 +434,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 rate-limit-by,
|
||||
ctx parent root trace?, do let data msg error #_run & kvs]}
|
||||
form])
|
||||
|
||||
|
|
@ -444,7 +444,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 rate-limit-by,
|
||||
ctx parent root trace?, do let data msg error #_run & kvs]}])
|
||||
|
||||
(enc/unexpected-arg! macro-id))))
|
||||
|
|
@ -616,7 +616,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 #_:rate-limit-by,
|
||||
:ctx :parent #_:trace?, :do :let :data :msg :error :run,
|
||||
:elide? :allow? #_:expansion-id :otel/context))
|
||||
|
||||
|
|
|
|||
|
|
@ -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-by,
|
||||
ctx parent root trace?, do let data msg error run & kvs]}])}
|
||||
|
||||
[opts]
|
||||
|
|
@ -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 rate-limit-by,
|
||||
#_ctx #_parent #_root #_trace?, #_do #_let #_data #_msg #_error #_run #_& #_kvs]}])}
|
||||
|
||||
[opts]
|
||||
|
|
|
|||
Loading…
Reference in a new issue