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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
580368c0
Commit
580368c0
authored
Jul 09, 2019
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make unicorn_workers to return meaningful results
parent
12422dbf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
11 deletions
+38
-11
changelogs/unreleased/fix-unicorn-sampler-workers-count.yml
changelogs/unreleased/fix-unicorn-sampler-workers-count.yml
+5
-0
lib/gitlab/metrics/samplers/unicorn_sampler.rb
lib/gitlab/metrics/samplers/unicorn_sampler.rb
+10
-1
spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb
spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb
+23
-10
No files found.
changelogs/unreleased/fix-unicorn-sampler-workers-count.yml
0 → 100644
View file @
580368c0
---
title
:
Make unicorn_workers to return meaningful results
merge_request
:
30506
author
:
type
:
fixed
lib/gitlab/metrics/samplers/unicorn_sampler.rb
View file @
580368c0
...
@@ -54,7 +54,16 @@ module Gitlab
...
@@ -54,7 +54,16 @@ module Gitlab
end
end
def
unicorn_workers_count
def
unicorn_workers_count
`pgrep -f '[u]nicorn_rails worker.+
#{
Rails
.
root
.
to_s
}
'`
.
split
.
count
http_servers
.
sum
(
&
:worker_processes
)
# rubocop: disable CodeReuse/ActiveRecord
end
# Traversal of ObjectSpace is expensive, on fully loaded application
# it takes around 80ms. The instances of HttpServers are not a subject
# to change so we can cache the list of servers.
def
http_servers
return
[]
unless
defined?
(
::
Unicorn
::
HttpServer
)
@http_servers
||=
ObjectSpace
.
each_object
(
::
Unicorn
::
HttpServer
).
to_a
end
end
end
end
end
end
...
...
spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb
View file @
580368c0
...
@@ -4,7 +4,7 @@ describe Gitlab::Metrics::Samplers::UnicornSampler do
...
@@ -4,7 +4,7 @@ describe Gitlab::Metrics::Samplers::UnicornSampler do
subject
{
described_class
.
new
(
1
.
second
)
}
subject
{
described_class
.
new
(
1
.
second
)
}
describe
'#sample'
do
describe
'#sample'
do
let
(
:unicorn
)
{
double
(
'unicorn'
)
}
let
(
:unicorn
)
{
Module
.
new
}
let
(
:raindrops
)
{
double
(
'raindrops'
)
}
let
(
:raindrops
)
{
double
(
'raindrops'
)
}
let
(
:stats
)
{
double
(
'stats'
)
}
let
(
:stats
)
{
double
(
'stats'
)
}
...
@@ -78,22 +78,35 @@ describe Gitlab::Metrics::Samplers::UnicornSampler do
...
@@ -78,22 +78,35 @@ describe Gitlab::Metrics::Samplers::UnicornSampler do
end
end
end
end
context
'additional metrics'
do
context
'unicorn workers'
do
let
(
:unicorn_workers
)
{
2
}
before
do
allow
(
unicorn
).
to
receive
(
:listener_names
).
and_return
([])
end
context
'without http server'
do
it
"does set unicorn_workers to 0"
do
expect
(
subject
.
metrics
[
:unicorn_workers
]).
to
receive
(
:set
).
with
({},
0
)
subject
.
sample
end
end
context
'with http server'
do
let
(
:http_server_class
)
{
Struct
.
new
(
:worker_processes
)
}
let!
(
:http_server
)
{
http_server_class
.
new
(
5
)
}
before
do
before
do
allow
(
unicorn
).
to
receive
(
:listener_names
).
and_return
([
""
])
stub_const
(
'Unicorn::HttpServer'
,
http_server_class
)
allow
(
::
Gitlab
::
Metrics
::
System
).
to
receive
(
:cpu_time
).
and_return
(
3.14
)
allow
(
subject
).
to
receive
(
:unicorn_workers_count
).
and_return
(
unicorn_workers
)
end
end
it
"sets additional metrics"
do
it
"sets additional metrics"
do
expect
(
subject
.
metrics
[
:unicorn_workers
]).
to
receive
(
:set
).
with
({},
unicorn_workers
)
expect
(
subject
.
metrics
[
:unicorn_workers
]).
to
receive
(
:set
).
with
({},
5
)
subject
.
sample
subject
.
sample
end
end
end
end
end
end
end
describe
'#start'
do
describe
'#start'
do
context
'when enabled'
do
context
'when enabled'
do
...
...
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