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
466beeb3
Commit
466beeb3
authored
May 23, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use interpolation instead of concatenation
parent
62fe37e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
app/controllers/metrics_controller.rb
app/controllers/metrics_controller.rb
+4
-4
No files found.
app/controllers/metrics_controller.rb
View file @
466beeb3
...
@@ -14,7 +14,7 @@ class MetricsController < ActionController::Base
...
@@ -14,7 +14,7 @@ class MetricsController < ActionController::Base
def
metrics
def
metrics
metrics_text
=
Prometheus
::
Client
::
Formats
::
Text
.
marshal_multiprocess
(
multiprocess_metrics_path
)
metrics_text
=
Prometheus
::
Client
::
Formats
::
Text
.
marshal_multiprocess
(
multiprocess_metrics_path
)
response
=
health_metrics_text
+
"
\n
"
+
metrics_text
response
=
"
#{
health_metrics_text
}
\n
#{
metrics_text
}
"
render
text:
response
,
content_type:
'text/plain; version=0.0.4'
render
text:
response
,
content_type:
'text/plain; version=0.0.4'
end
end
...
@@ -32,15 +32,15 @@ class MetricsController < ActionController::Base
...
@@ -32,15 +32,15 @@ class MetricsController < ActionController::Base
def
health_metrics_text
def
health_metrics_text
results
=
CHECKS
.
flat_map
(
&
:metrics
)
results
=
CHECKS
.
flat_map
(
&
:metrics
)
types
=
results
.
map
(
&
:name
)
types
=
results
.
map
(
&
:name
).
uniq
.
map
{
|
metric_name
|
"# TYPE
#{
metric_name
}
gauge"
}
.
uniq
.
map
{
|
metric_name
|
"# TYPE
#{
metric_name
}
gauge"
}
metrics
=
results
.
map
(
&
method
(
:metric_to_prom_line
))
metrics
=
results
.
map
(
&
method
(
:metric_to_prom_line
))
types
.
concat
(
metrics
).
join
(
"
\n
"
)
types
.
concat
(
metrics
).
join
(
"
\n
"
)
end
end
def
metric_to_prom_line
(
metric
)
def
metric_to_prom_line
(
metric
)
labels
=
metric
.
labels
&
.
map
{
|
key
,
value
|
"
#{
key
}
=
\"
#{
value
}
\"
"
}
&
.
join
(
','
)
||
''
labels
=
metric
.
labels
&
.
map
{
|
key
,
value
|
"
#{
key
}
=
\"
#{
value
}
\"
"
}
&
.
join
(
','
)
||
''
if
labels
.
empty?
if
labels
.
empty?
"
#{
metric
.
name
}
#{
metric
.
value
}
"
"
#{
metric
.
name
}
#{
metric
.
value
}
"
else
else
...
...
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