diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-07-17 15:50:04 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-07-17 15:50:04 +0300 |
commit | 416076610e7b1674669ad33bae604155f55a3d02 (patch) | |
tree | 5ad144007a1e6ca54b344d5a43ab582e676ef7e4 /lib/gitlab/auth | |
parent | 7f0431dd8550ac9d229d1383c03386c1634d015f (diff) |
Implement scaffold of authentication activity metrics
Diffstat (limited to 'lib/gitlab/auth')
-rw-r--r-- | lib/gitlab/auth/activity.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/gitlab/auth/activity.rb b/lib/gitlab/auth/activity.rb new file mode 100644 index 00000000000..c0254ca81cd --- /dev/null +++ b/lib/gitlab/auth/activity.rb @@ -0,0 +1,69 @@ +module Gitlab + module Auth + ## + # Metrics and logging for user authentication activity. + # + class Activity + extend Gitlab::Utils::StrongMemoize + + COUNTERS = { + user_authenticated: 'Counter of total successful authentication events', + user_unauthenticated: 'Counter of total authentication failures', + user_not_found: 'Counter of total failed log-ins when user is unknown', + user_password_invalid: 'Counter of failed log-ins with invalid password', + user_session_fetched: 'Counter of total sessions fetched', + user_session_override: 'Counter of manual log-ins and sessions overrides', + user_signed_out: 'Counter of total user sign out events' + }.freeze + + def initialize(opts) + @opts = opts + end + + def user_authentication_failed! + self.class.user_unauthenticated_counter.increment + + case @opts[:message] + when :not_found_in_database + self.class.user_not_found_counter.increment + when :invalid + self.class.user_password_invalid_counter.increment + end + end + + def user_authenticated! + self.class.user_authenticated_counter.increment + end + + def user_session_fetched! + self.class.user_session_fetched_counter.increment + end + + def user_set_manually! + self.class.user_session_override_counter.increment + end + + def user_logout! + self.class.user_signed_out_counter.increment + end + + class StubCounter + def initialize(metric) + Rails.logger.warn("METRIC #{metric}") + end + + def increment + end + end + + COUNTERS.each_pair do |metric, description| + define_singleton_method("#{metric}_counter") do + strong_memoize(metric) do + StubCounter.new(metric) + # Gitlab::Metrics.counter("gitlab_auth_#{metric}_total", description) + end + end + end + end + end +end |