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
iv
gitlab-ce
Commits
b7f49aa0
Commit
b7f49aa0
authored
Jan 13, 2016
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'configure-randomize-metrics-sample-interval' into 'master'
See merge request !2406
parents
c7d9e780
057eb824
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
318 additions
and
259 deletions
+318
-259
app/controllers/admin/application_settings_controller.rb
app/controllers/admin/application_settings_controller.rb
+1
-0
app/views/admin/application_settings/_form.html.haml
app/views/admin/application_settings/_form.html.haml
+7
-0
db/migrate/20160113111034_add_metrics_sample_interval.rb
db/migrate/20160113111034_add_metrics_sample_interval.rb
+6
-0
db/schema.rb
db/schema.rb
+255
-253
lib/gitlab/metrics.rb
lib/gitlab/metrics.rb
+2
-1
lib/gitlab/metrics/sampler.rb
lib/gitlab/metrics/sampler.rb
+26
-4
spec/lib/gitlab/metrics/sampler_spec.rb
spec/lib/gitlab/metrics/sampler_spec.rb
+21
-1
No files found.
app/controllers/admin/application_settings_controller.rb
View file @
b7f49aa0
...
...
@@ -73,6 +73,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:metrics_pool_size
,
:metrics_timeout
,
:metrics_method_call_threshold
,
:metrics_sample_interval
,
:recaptcha_enabled
,
:recaptcha_site_key
,
:recaptcha_private_key
,
...
...
app/views/admin/application_settings/_form.html.haml
View file @
b7f49aa0
...
...
@@ -202,6 +202,13 @@
.help-block
A method call is only tracked when it takes longer to complete than
the given amount of milliseconds.
.form-group
=
f
.
label
:metrics_sample_interval
,
'Sampler Interval (sec)'
,
class:
'control-label col-sm-2'
.col-sm-10
=
f
.
number_field
:metrics_sample_interval
,
class:
'form-control'
.help-block
The sampling interval in seconds. Sampled data includes memory usage,
retained Ruby objects, file descriptors and so on.
%fieldset
%legend
Spam and Anti-bot Protection
...
...
db/migrate/20160113111034_add_metrics_sample_interval.rb
0 → 100644
View file @
b7f49aa0
class
AddMetricsSampleInterval
<
ActiveRecord
::
Migration
def
change
add_column
:application_settings
,
:metrics_sample_interval
,
:integer
,
default:
15
end
end
db/schema.rb
View file @
b7f49aa0
This diff is collapsed.
Click to expand it.
lib/gitlab/metrics.rb
View file @
b7f49aa0
...
...
@@ -13,7 +13,8 @@ module Gitlab
timeout:
current_application_settings
[
:metrics_timeout
],
method_call_threshold:
current_application_settings
[
:metrics_method_call_threshold
],
host:
current_application_settings
[
:metrics_host
],
port:
current_application_settings
[
:metrics_port
]
port:
current_application_settings
[
:metrics_port
],
sample_interval:
current_application_settings
[
:metrics_sample_interval
]
||
15
}
end
...
...
lib/gitlab/metrics/sampler.rb
View file @
b7f49aa0
...
...
@@ -7,9 +7,14 @@ module Gitlab
# statistics, etc.
class
Sampler
# interval - The sampling interval in seconds.
def
initialize
(
interval
=
15
)
@interval
=
interval
@metrics
=
[]
def
initialize
(
interval
=
Metrics
.
settings
[
:sample_interval
])
interval_half
=
interval
.
to_f
/
2
@interval
=
interval
@interval_steps
=
(
-
interval_half
..
interval_half
).
step
(
0.1
).
to_a
@last_step
=
nil
@metrics
=
[]
@last_minor_gc
=
Delta
.
new
(
GC
.
stat
[
:minor_gc_count
])
@last_major_gc
=
Delta
.
new
(
GC
.
stat
[
:major_gc_count
])
...
...
@@ -26,7 +31,7 @@ module Gitlab
Thread
.
current
.
abort_on_exception
=
true
loop
do
sleep
(
@
interval
)
sleep
(
sleep_
interval
)
sample
end
...
...
@@ -102,6 +107,23 @@ module Gitlab
def
sidekiq?
Sidekiq
.
server?
end
# Returns the sleep interval with a random adjustment.
#
# The random adjustment is put in place to ensure we:
#
# 1. Don't generate samples at the exact same interval every time (thus
# potentially missing anything that happens in between samples).
# 2. Don't sample data at the same interval two times in a row.
def
sleep_interval
while
step
=
@interval_steps
.
sample
if
step
!=
@last_step
@last_step
=
step
return
@interval
+
@last_step
end
end
end
end
end
end
spec/lib/gitlab/metrics/sampler_spec.rb
View file @
b7f49aa0
...
...
@@ -9,7 +9,7 @@ describe Gitlab::Metrics::Sampler do
describe
'#start'
do
it
'gathers a sample at a given interval'
do
expect
(
sampler
).
to
receive
(
:sleep
).
with
(
5
)
expect
(
sampler
).
to
receive
(
:sleep
).
with
(
a_kind_of
(
Numeric
)
)
expect
(
sampler
).
to
receive
(
:sample
)
expect
(
sampler
).
to
receive
(
:loop
).
and_yield
...
...
@@ -116,4 +116,24 @@ describe Gitlab::Metrics::Sampler do
sampler
.
add_metric
(
'cats'
,
value:
10
)
end
end
describe
'#sleep_interval'
do
it
'returns a Numeric'
do
expect
(
sampler
.
sleep_interval
).
to
be_a_kind_of
(
Numeric
)
end
# Testing random behaviour is very hard, so treat this test as a basic smoke
# test instead of a very accurate behaviour/unit test.
it
'does not return the same interval twice in a row'
do
last
=
nil
100
.
times
do
interval
=
sampler
.
sleep_interval
expect
(
interval
).
to_not
eq
(
last
)
last
=
interval
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