🐛 Fix incorrect warning on climit initialization when disabled

This commit is contained in:
Andrey Antukh 2024-02-14 15:16:37 +01:00
parent a89f16e594
commit 757291644b

View file

@ -197,40 +197,41 @@
config (::config climit) config (::config climit)
label (::sv/name mdata)] label (::sv/name mdata)]
(reduce (fn [handler [limit-id key-fn]] (if climit
(if-let [config (get config limit-id)] (reduce (fn [handler [limit-id key-fn]]
(let [key-fn (or key-fn noop-fn)] (if-let [config (get config limit-id)]
(l/dbg :hint "instrumenting method" (let [key-fn (or key-fn noop-fn)]
:method label (l/dbg :hint "instrumenting method"
:limit (id->str limit-id) :method label
:timeout (:timeout config) :limit (id->str limit-id)
:permits (:permits config) :timeout (:timeout config)
:queue (:queue config) :permits (:permits config)
:keyed (not= key-fn noop-fn)) :queue (:queue config)
:keyed (not= key-fn noop-fn))
(if (and (= key-fn ::rpc/profile-id)
(false? (::rpc/auth mdata true)))
(if (and (= key-fn ::rpc/profile-id) ;; We don't enforce by-profile limit on methods that does
(false? (::rpc/auth mdata true))) ;; not require authentication
handler
;; We don't enforce by-profile limit on methods that does (fn [cfg params]
;; not require authentication (let [limit-key (key-fn params)
handler cache-key [limit-id limit-key]
limiter (cache/get cache cache-key (partial create-limiter config))
profile-id (if (= key-fn ::rpc/profile-id)
limit-key
(get params ::rpc/profile-id))]
(invoke limiter metrics limit-id limit-key label profile-id handler [cfg params])))))
(fn [cfg params] (do
(let [limit-key (key-fn params) (l/wrn :hint "no config found for specified queue" :id (id->str limit-id))
cache-key [limit-id limit-key] handler)))
limiter (cache/get cache cache-key (partial create-limiter config))
profile-id (if (= key-fn ::rpc/profile-id)
limit-key
(get params ::rpc/profile-id))]
(invoke limiter metrics limit-id limit-key label profile-id handler [cfg params])))))
(do handler
(l/wrn :hint "no config found for specified queue" :id (id->str limit-id)) (concat global-limits (get-limits mdata)))
handler))) handler)))
handler
(concat global-limits (get-limits mdata)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PUBLIC API ;; PUBLIC API