Commit 4ca0e4ab authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Integrate rack attack instrumentation into structured logs

parent c4e11db3
...@@ -15,7 +15,8 @@ module Gitlab ...@@ -15,7 +15,8 @@ module Gitlab
:elasticsearch_duration_s, :elasticsearch_duration_s,
*::Gitlab::Instrumentation::Redis.known_payload_keys, *::Gitlab::Instrumentation::Redis.known_payload_keys,
*::Gitlab::Metrics::Subscribers::ActiveRecord::DB_COUNTERS, *::Gitlab::Metrics::Subscribers::ActiveRecord::DB_COUNTERS,
*::Gitlab::Metrics::Subscribers::ExternalHttp::KNOWN_PAYLOAD_KEYS] *::Gitlab::Metrics::Subscribers::ExternalHttp::KNOWN_PAYLOAD_KEYS,
*::Gitlab::Metrics::Subscribers::RackAttack::PAYLOAD_KEYS]
end end
def add_instrumentation_data(payload) def add_instrumentation_data(payload)
...@@ -26,6 +27,7 @@ module Gitlab ...@@ -26,6 +27,7 @@ module Gitlab
instrument_throttle(payload) instrument_throttle(payload)
instrument_active_record(payload) instrument_active_record(payload)
instrument_external_http(payload) instrument_external_http(payload)
instrument_rack_attack(payload)
end end
def instrument_gitaly(payload) def instrument_gitaly(payload)
...@@ -80,6 +82,13 @@ module Gitlab ...@@ -80,6 +82,13 @@ module Gitlab
payload.merge!(db_counters) payload.merge!(db_counters)
end end
def instrument_rack_attack(payload)
rack_attack_redis_count = ::Gitlab::Metrics::Subscribers::RackAttack.payload[:rack_attack_redis_count]
return if rack_attack_redis_count == 0
payload.merge!(::Gitlab::Metrics::Subscribers::RackAttack.payload)
end
# Returns the queuing duration for a Sidekiq job in seconds, as a float, if the # Returns the queuing duration for a Sidekiq job in seconds, as a float, if the
# `enqueued_at` field or `created_at` field is available. # `enqueued_at` field or `created_at` field is available.
# #
......
...@@ -39,7 +39,9 @@ RSpec.describe Gitlab::InstrumentationHelper do ...@@ -39,7 +39,9 @@ RSpec.describe Gitlab::InstrumentationHelper do
:db_write_count, :db_write_count,
:db_cached_count, :db_cached_count,
:external_http_count, :external_http_count,
:external_http_duration_s :external_http_duration_s,
:rack_attack_redis_count,
:rack_attack_redis_duration_s
] ]
expect(described_class.keys).to eq(expected_keys) expect(described_class.keys).to eq(expected_keys)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment