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
Léo-Paul Géneau
gitlab-ce
Commits
6b9a091c
Commit
6b9a091c
authored
May 16, 2017
by
Kevin Lyda
Committed by
Pawel Chojnacki
Jun 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add trailing newline to response.
Prometheus requires a trailing newline in its response. + cleanup
parent
5bc099c2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
19 deletions
+20
-19
app/controllers/health_controller.rb
app/controllers/health_controller.rb
+15
-3
app/controllers/sessions_controller.rb
app/controllers/sessions_controller.rb
+5
-1
app/services/prom_service.rb
app/services/prom_service.rb
+0
-15
No files found.
app/controllers/health_controller.rb
View file @
6b9a091c
...
...
@@ -23,15 +23,27 @@ class HealthController < ActionController::Base
end
def
metrics
results
=
CHECKS
.
flat_map
(
&
:metrics
)
response
=
health_metrics_text
+
"
\n
"
if
Gitlab
::
Metrics
.
prometheus_metrics_enabled?
response
+=
Prometheus
::
Client
::
Formats
::
Text
.
marshal_multiprocess
(
ENV
[
'prometheus_multiproc_dir'
])
end
response
=
results
.
map
(
&
method
(
:metric_to_prom_line
)).
join
(
"
\n
"
)
response
=
::
Prometheus
::
Client
::
Formats
::
Text
.
marshal_multiprocess
render
text:
response
,
content_type:
'text/plain; version=0.0.4'
end
private
def
health_metrics_text
results
=
CHECKS
.
flat_map
(
&
:metrics
)
types
=
results
.
map
(
&
:name
)
.
uniq
.
map
{
|
metric_name
|
"# TYPE
#{
metric_name
}
gauge"
}
metrics
=
results
.
map
(
&
method
(
:metric_to_prom_line
))
types
.
concat
(
metrics
).
join
(
"
\n
"
)
end
def
metric_to_prom_line
(
metric
)
labels
=
metric
.
labels
&
.
map
{
|
key
,
value
|
"
#{
key
}
=
\"
#{
value
}
\"
"
}
&
.
join
(
','
)
||
''
if
labels
.
empty?
...
...
app/controllers/sessions_controller.rb
View file @
6b9a091c
...
...
@@ -34,7 +34,6 @@ class SessionsController < Devise::SessionsController
end
# hide the signed-in notification
flash
[
:notice
]
=
nil
PromService
.
instance
.
login
.
increment
log_audit_event
(
current_user
,
with:
authentication_method
)
log_user_activity
(
current_user
)
end
...
...
@@ -48,6 +47,10 @@ class SessionsController < Devise::SessionsController
private
def
self
.
login_counter
@login_counter
||=
Gitlab
::
Metrics
.
counter
(
:user_session_logins
,
'User logins count'
)
end
# Handle an "initial setup" state, where there's only one user, it's an admin,
# and they require a password change.
def
check_initial_setup
...
...
@@ -126,6 +129,7 @@ class SessionsController < Devise::SessionsController
end
def
log_user_activity
(
user
)
SessionsController
.
login_counter
.
increment
Users
::
ActivityService
.
new
(
user
,
'login'
).
execute
end
...
...
app/services/prom_service.rb
deleted
100644 → 0
View file @
5bc099c2
require
'prometheus/client'
require
'singleton'
class
PromService
include
Singleton
attr_reader
:login
def
initialize
@prometheus
=
Prometheus
::
Client
.
registry
@login
=
Prometheus
::
Client
::
Counter
.
new
(
:login
,
'Login counter'
)
@prometheus
.
register
(
@login
)
end
end
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