Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
7376ffc3
Commit
7376ffc3
authored
Jun 21, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Prometheus metrics to track reCAPTCHA success/failures
parent
cd578941
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletion
+34
-1
app/controllers/sessions_controller.rb
app/controllers/sessions_controller.rb
+19
-1
doc/administration/monitoring/prometheus/gitlab_metrics.md
doc/administration/monitoring/prometheus/gitlab_metrics.md
+2
-0
spec/controllers/sessions_controller_spec.rb
spec/controllers/sessions_controller_spec.rb
+13
-0
No files found.
app/controllers/sessions_controller.rb
View file @
7376ffc3
...
@@ -62,7 +62,11 @@ class SessionsController < Devise::SessionsController
...
@@ -62,7 +62,11 @@ class SessionsController < Devise::SessionsController
return
unless
captcha_enabled?
return
unless
captcha_enabled?
return
unless
Gitlab
::
Recaptcha
.
load_configurations!
return
unless
Gitlab
::
Recaptcha
.
load_configurations!
unless
verify_recaptcha
if
verify_recaptcha
increment_successful_login_captcha_counter
else
increment_failed_login_captcha_counter
self
.
resource
=
resource_class
.
new
self
.
resource
=
resource_class
.
new
flash
[
:alert
]
=
'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'
flash
[
:alert
]
=
'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'
flash
.
delete
:recaptcha_error
flash
.
delete
:recaptcha_error
...
@@ -71,6 +75,20 @@ class SessionsController < Devise::SessionsController
...
@@ -71,6 +75,20 @@ class SessionsController < Devise::SessionsController
end
end
end
end
def
increment_failed_login_captcha_counter
Gitlab
::
Metrics
.
counter
(
:failed_login_captcha_total
,
'Number of failed CAPTCHA attempts for logins'
.
freeze
).
increment
end
def
increment_successful_login_captcha_counter
Gitlab
::
Metrics
.
counter
(
:successful_login_captcha_total
,
'Number of successful CAPTCHA attempts for logins'
.
freeze
).
increment
end
def
log_failed_login
def
log_failed_login
Gitlab
::
AppLogger
.
info
(
"Failed Login: username=
#{
user_params
[
:login
]
}
ip=
#{
request
.
remote_ip
}
"
)
Gitlab
::
AppLogger
.
info
(
"Failed Login: username=
#{
user_params
[
:login
]
}
ip=
#{
request
.
remote_ip
}
"
)
end
end
...
...
doc/administration/monitoring/prometheus/gitlab_metrics.md
View file @
7376ffc3
...
@@ -48,6 +48,8 @@ The following metrics are available:
...
@@ -48,6 +48,8 @@ The following metrics are available:
| filesystem_circuitbreaker_latency_seconds | Gauge | 9.5 | Time spent validating if a storage is accessible |
| filesystem_circuitbreaker_latency_seconds | Gauge | 9.5 | Time spent validating if a storage is accessible |
| filesystem_circuitbreaker | Gauge | 9.5 | Whether or not the circuit for a certain shard is broken or not |
| filesystem_circuitbreaker | Gauge | 9.5 | Whether or not the circuit for a certain shard is broken or not |
| circuitbreaker_storage_check_duration_seconds | Histogram | 10.3 | Time a single storage probe took |
| circuitbreaker_storage_check_duration_seconds | Histogram | 10.3 | Time a single storage probe took |
| failed_login_captcha_total | Gauge | 11.0 | Counter of failed CAPTCHA attempts during login |
| successful_login_captcha_total | Gauge | 11.0 | Counter of successful CAPTCHA attempts during login |
### Ruby metrics
### Ruby metrics
...
...
spec/controllers/sessions_controller_spec.rb
View file @
7376ffc3
...
@@ -93,6 +93,12 @@ describe SessionsController do
...
@@ -93,6 +93,12 @@ describe SessionsController do
it
'displays an error when the reCAPTCHA is not solved'
do
it
'displays an error when the reCAPTCHA is not solved'
do
# Without this, `verify_recaptcha` arbitraily returns true in test env
# Without this, `verify_recaptcha` arbitraily returns true in test env
Recaptcha
.
configuration
.
skip_verify_env
.
delete
(
'test'
)
Recaptcha
.
configuration
.
skip_verify_env
.
delete
(
'test'
)
counter
=
double
(
:counter
)
expect
(
counter
).
to
receive
(
:increment
)
expect
(
Gitlab
::
Metrics
).
to
receive
(
:counter
)
.
with
(
:failed_login_captcha_total
,
anything
)
.
and_return
(
counter
)
post
(
:create
,
user:
user_params
)
post
(
:create
,
user:
user_params
)
...
@@ -104,6 +110,13 @@ describe SessionsController do
...
@@ -104,6 +110,13 @@ describe SessionsController do
it
'successfully logs in a user when reCAPTCHA is solved'
do
it
'successfully logs in a user when reCAPTCHA is solved'
do
# Avoid test ordering issue and ensure `verify_recaptcha` returns true
# Avoid test ordering issue and ensure `verify_recaptcha` returns true
Recaptcha
.
configuration
.
skip_verify_env
<<
'test'
Recaptcha
.
configuration
.
skip_verify_env
<<
'test'
counter
=
double
(
:counter
)
expect
(
counter
).
to
receive
(
:increment
)
expect
(
Gitlab
::
Metrics
).
to
receive
(
:counter
)
.
with
(
:successful_login_captcha_total
,
anything
)
.
and_return
(
counter
)
expect
(
Gitlab
::
Metrics
).
to
receive
(
:counter
).
and_call_original
post
(
:create
,
user:
user_params
)
post
(
:create
,
user:
user_params
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment