mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:49:06 +08:00
FEATURE: group warnings about IP level rate limiting
This commit is contained in:
parent
d10c9d7d75
commit
168ffd8384
|
@ -184,7 +184,7 @@ GEM
|
|||
logstash-event (1.2.02)
|
||||
logstash-logger (0.26.1)
|
||||
logstash-event (~> 1.2)
|
||||
logster (1.2.9)
|
||||
logster (1.2.11)
|
||||
loofah (2.2.2)
|
||||
crass (~> 1.0.2)
|
||||
nokogiri (>= 1.5.9)
|
||||
|
|
|
@ -489,6 +489,41 @@ module Discourse
|
|||
nil
|
||||
end
|
||||
|
||||
# you can use Discourse.warn when you want to report custom environment
|
||||
# with the error, this helps with grouping
|
||||
def self.warn(message, env = nil)
|
||||
append = env ? (+" ") << env.map { |k, v|"#{k}: #{v}" }.join(" ") : ""
|
||||
|
||||
if !(Logster::Logger === Rails.logger)
|
||||
Rails.logger.warn("#{message}#{append}")
|
||||
return
|
||||
end
|
||||
|
||||
loggers = [Rails.logger]
|
||||
if Rails.logger.chained
|
||||
loggers.concat(Rails.logger.chained)
|
||||
end
|
||||
|
||||
if old_env = Thread.current[Logster::Logger::LOGSTER_ENV]
|
||||
env = env.merge(old_env)
|
||||
end
|
||||
|
||||
loggers.each do |logger|
|
||||
|
||||
if !(Logster::Logger === logger)
|
||||
logger.warn("#{message} #{append}")
|
||||
next
|
||||
end
|
||||
|
||||
logger.store.report(
|
||||
::Logger::Severity::WARN,
|
||||
"discourse",
|
||||
message,
|
||||
env: env
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# report a warning maintaining backtrack for logster
|
||||
def self.warn_exception(e, message: "", env: nil)
|
||||
if Rails.logger.respond_to? :add_with_opts
|
||||
|
|
|
@ -258,7 +258,7 @@ class Middleware::RequestTracker
|
|||
|
||||
if !limiter_assets10.can_perform?
|
||||
if warn
|
||||
Rails.logger.warn("Global asset IP rate limit exceeded for #{ip}: 10 second rate limit, uri: #{request.env["REQUEST_URI"]}")
|
||||
Discourse.warn("Global asset IP rate limit exceeded for #{ip}: 10 second rate limit", uri: request.env["REQUEST_URI"])
|
||||
end
|
||||
|
||||
return !(GlobalSetting.max_reqs_per_ip_mode == "warn")
|
||||
|
@ -272,7 +272,7 @@ class Middleware::RequestTracker
|
|||
false
|
||||
rescue RateLimiter::LimitExceeded
|
||||
if warn
|
||||
Rails.logger.warn("Global IP rate limit exceeded for #{ip}: #{type} second rate limit, uri: #{request.env["REQUEST_URI"]}")
|
||||
Discourse.warn("Global IP rate limit exceeded for #{ip}: #{type} second rate limit", uri: request.env["REQUEST_URI"])
|
||||
!(GlobalSetting.max_reqs_per_ip_mode == "warn")
|
||||
else
|
||||
true
|
||||
|
|
Loading…
Reference in New Issue
Block a user