BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ae8f7666
Commit
ae8f7666
authored
May 29, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add prometheus text formatter
+ rename controler method to #index from #metrics + remove assertion from nullMetric
parent
c134a72c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
19 deletions
+54
-19
metrics_service.rb
app/services/metrics_service.rb
+2
-2
routes.rb
config/routes.rb
+1
-1
prometheus_text_format.rb
lib/gitlab/health_checks/prometheus_text_format.rb
+1
-1
null_metric.rb
lib/gitlab/metrics/null_metric.rb
+0
-9
metrics_controller_spec.rb
spec/controllers/metrics_controller_spec.rb
+6
-6
prometheus_text_format_spec.rb
spec/lib/gitlab/health_checks/prometheus_text_format_spec.rb
+44
-0
No files found.
app/services/metrics_service.rb
View file @
ae8f7666
...
...
@@ -24,11 +24,11 @@ class MetricsService
private
def
formatter
@formatter
||=
PrometheusTex
t
.
new
@formatter
||=
Gitlab
::
HealthChecks
::
PrometheusTextForma
t
.
new
end
def
multiprocess_metrics_path
@multiprocess_metrics_path
||=
Rails
.
root
.
join
(
ENV
[
'prometheus_multiproc_dir'
])
@multiprocess_metrics_path
||=
Rails
.
root
.
join
(
ENV
[
'prometheus_multiproc_dir'
])
.
freeze
end
def
metric_to_prom_line
(
metric
)
...
...
config/routes.rb
View file @
ae8f7666
...
...
@@ -41,7 +41,7 @@ Rails.application.routes.draw do
scope
path:
'-'
do
get
'liveness'
=>
'health#liveness'
get
'readiness'
=>
'health#readiness'
get
'metrics'
=>
'metrics#metrics'
resources
:metrics
,
only:
[
:index
]
end
# Koding route
...
...
lib/gitlab/health_checks/prometheus_text.rb
→
lib/gitlab/health_checks/prometheus_text
_format
.rb
View file @
ae8f7666
module
Gitlab::HealthChecks
class
PrometheusText
class
PrometheusText
Format
def
marshal
(
metrics
)
metrics_with_type_declarations
(
metrics
).
join
(
"
\n
"
)
end
...
...
lib/gitlab/metrics/null_metric.rb
View file @
ae8f7666
...
...
@@ -5,15 +5,6 @@ module Gitlab
def
method_missing
(
name
,
*
args
,
&
block
)
nil
end
# these methods shouldn't be called when metrics are disabled
def
get
(
*
args
)
raise
NotImplementedError
end
def
values
(
*
args
)
raise
NotImplementedError
end
end
end
end
spec/controllers/metrics_controller_spec.rb
View file @
ae8f7666
...
...
@@ -19,14 +19,14 @@ describe MetricsController do
allow
(
Gitlab
::
Metrics
).
to
receive
(
:prometheus_metrics_enabled?
).
and_return
(
true
)
end
describe
'#
metrics
'
do
describe
'#
index
'
do
context
'authorization token provided'
do
before
do
request
.
headers
[
'TOKEN'
]
=
token
end
it
'returns DB ping metrics'
do
get
:
metrics
get
:
index
expect
(
response
.
body
).
to
match
(
/^db_ping_timeout 0$/
)
expect
(
response
.
body
).
to
match
(
/^db_ping_success 1$/
)
...
...
@@ -34,7 +34,7 @@ describe MetricsController do
end
it
'returns Redis ping metrics'
do
get
:
metrics
get
:
index
expect
(
response
.
body
).
to
match
(
/^redis_ping_timeout 0$/
)
expect
(
response
.
body
).
to
match
(
/^redis_ping_success 1$/
)
...
...
@@ -42,7 +42,7 @@ describe MetricsController do
end
it
'returns file system check metrics'
do
get
:
metrics
get
:
index
expect
(
response
.
body
).
to
match
(
/^filesystem_access_latency{shard="default"} [0-9\.]+$/
)
expect
(
response
.
body
).
to
match
(
/^filesystem_accessible{shard="default"} 1$/
)
...
...
@@ -58,7 +58,7 @@ describe MetricsController do
end
it
'returns proper response'
do
get
:
metrics
get
:
index
expect
(
response
.
status
).
to
eq
(
404
)
end
...
...
@@ -67,7 +67,7 @@ describe MetricsController do
context
'without authorization token'
do
it
'returns proper response'
do
get
:
metrics
get
:
index
expect
(
response
.
status
).
to
eq
(
404
)
end
...
...
spec/lib/gitlab/health_checks/prometheus_text_format_spec.rb
0 → 100644
View file @
ae8f7666
describe
Gitlab
::
HealthChecks
::
PrometheusTextFormat
do
let
(
:metric_class
)
{
Gitlab
::
HealthChecks
::
Metric
}
subject
{
described_class
.
new
}
describe
'#marshal'
do
let
(
:sample_metrics
)
do
[
metric_class
.
new
(
'metric1'
,
1
),
metric_class
.
new
(
'metric2'
,
2
)
]
end
it
'marshal to text with non repeating type definition'
do
expected
=
<<-
EXPECTED
# TYPE metric1 gauge
metric1 1
# TYPE metric2 gauge
metric2 2
EXPECTED
expect
(
subject
.
marshal
(
sample_metrics
)).
to
eq
(
expected
.
chomp
)
end
context
'metrics where name repeats'
do
let
(
:sample_metrics
)
do
[
metric_class
.
new
(
'metric1'
,
1
),
metric_class
.
new
(
'metric1'
,
2
),
metric_class
.
new
(
'metric2'
,
3
)
]
end
it
'marshal to text with non repeating type definition'
do
expected
=
<<-
EXPECTED
# TYPE metric1 gauge
metric1 1
metric1 2
# TYPE metric2 gauge
metric2 3
EXPECTED
expect
(
subject
.
marshal
(
sample_metrics
)).
to
eq
(
expected
.
chomp
)
end
end
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