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
040167f0
Commit
040167f0
authored
Dec 20, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use seconds where possible, and convert to milliseconds for Influxdb consumption
parent
ed715b79
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
28 deletions
+31
-28
changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml
...leased/pawel-reduce_cardinality_of_prometheus_metrics.yml
+5
-0
lib/gitlab/metrics/method_call.rb
lib/gitlab/metrics/method_call.rb
+10
-14
lib/gitlab/metrics/system.rb
lib/gitlab/metrics/system.rb
+4
-4
spec/lib/gitlab/metrics/method_call_spec.rb
spec/lib/gitlab/metrics/method_call_spec.rb
+10
-8
spec/lib/gitlab/metrics/system_spec.rb
spec/lib/gitlab/metrics/system_spec.rb
+2
-2
No files found.
changelogs/unreleased/pawel-reduce_cardinality_of_prometheus_metrics.yml
0 → 100644
View file @
040167f0
---
title
:
Reduce the number of buckets in gitlab_cache_operation_duration_seconds
merge_request
:
15881
author
:
type
:
changed
lib/gitlab/metrics/method_call.rb
View file @
040167f0
...
...
@@ -4,7 +4,7 @@ module Gitlab
class
MethodCall
MUTEX
=
Mutex
.
new
BASE_LABELS
=
{
module:
nil
,
method:
nil
}.
freeze
attr_reader
:real_time
_seconds
,
:cpu_time
,
:call_count
,
:labels
attr_reader
:real_time
,
:cpu_time
,
:call_count
,
:labels
def
self
.
call_duration_histogram
return
@call_duration_histogram
if
@call_duration_histogram
...
...
@@ -27,42 +27,38 @@ module Gitlab
@transaction
=
transaction
@name
=
name
@labels
=
{
module:
@module_name
,
method:
@method_name
}
@real_time
_seconds
=
0.0
@cpu_time
=
0
@real_time
=
0.0
@cpu_time
=
0
.0
@call_count
=
0
end
# Measures the real and CPU execution time of the supplied block.
def
measure
start_real
_seconds
=
System
.
monotonic_time
start_real
=
System
.
monotonic_time
start_cpu
=
System
.
cpu_time
retval
=
yield
real_time
_seconds
=
System
.
monotonic_time
-
start_real_seconds
real_time
=
System
.
monotonic_time
-
start_real
cpu_time
=
System
.
cpu_time
-
start_cpu
@real_time
_seconds
+=
real_time_seconds
@real_time
+=
real_time
@cpu_time
+=
cpu_time
@call_count
+=
1
if
call_measurement_enabled?
&&
above_threshold?
self
.
class
.
call_duration_histogram
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
_seconds
)
self
.
class
.
call_duration_histogram
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
)
end
retval
end
def
real_time_milliseconds
real_time_seconds
.
in_milliseconds
.
to_i
end
# Returns a Metric instance of the current method call.
def
to_metric
Metric
.
new
(
Instrumentation
.
series
,
{
duration:
real_time
_milliseconds
,
cpu_duration:
cpu_time
,
duration:
real_time
.
in_milliseconds
.
to_i
,
cpu_duration:
cpu_time
.
in_milliseconds
.
to_i
,
call_count:
call_count
},
method:
@name
...
...
@@ -72,7 +68,7 @@ module Gitlab
# Returns true if the total runtime of this method exceeds the method call
# threshold.
def
above_threshold?
real_time_milliseconds
>=
Metrics
.
method_call_threshold
real_time
.
in
_milliseconds
>=
Metrics
.
method_call_threshold
end
def
call_measurement_enabled?
...
...
lib/gitlab/metrics/system.rb
View file @
040167f0
...
...
@@ -35,19 +35,19 @@ module Gitlab
if
Process
.
const_defined?
(
:CLOCK_THREAD_CPUTIME_ID
)
def
self
.
cpu_time
Process
.
clock_gettime
(
Process
::
CLOCK_THREAD_CPUTIME_ID
,
:
milli
second
)
.
clock_gettime
(
Process
::
CLOCK_THREAD_CPUTIME_ID
,
:
float_
second
)
end
else
def
self
.
cpu_time
Process
.
clock_gettime
(
Process
::
CLOCK_PROCESS_CPUTIME_ID
,
:
milli
second
)
.
clock_gettime
(
Process
::
CLOCK_PROCESS_CPUTIME_ID
,
:
float_
second
)
end
end
# Returns the current real time in a given precision.
#
# Returns the time as a F
ixnum
.
def
self
.
real_time
(
precision
=
:
milli
second
)
# Returns the time as a F
loat for precision = :float_second
.
def
self
.
real_time
(
precision
=
:
float_
second
)
Process
.
clock_gettime
(
Process
::
CLOCK_REALTIME
,
precision
)
end
...
...
spec/lib/gitlab/metrics/method_call_spec.rb
View file @
040167f0
...
...
@@ -8,8 +8,7 @@ describe Gitlab::Metrics::MethodCall do
it
'measures the performance of the supplied block'
do
method_call
.
measure
{
'foo'
}
expect
(
method_call
.
real_time_seconds
).
to
be_a_kind_of
(
Numeric
)
expect
(
method_call
.
real_time_milliseconds
).
to
be_a_kind_of
(
Numeric
)
expect
(
method_call
.
real_time
).
to
be_a_kind_of
(
Numeric
)
expect
(
method_call
.
cpu_time
).
to
be_a_kind_of
(
Numeric
)
expect
(
method_call
.
call_count
).
to
eq
(
1
)
end
...
...
@@ -65,14 +64,17 @@ describe Gitlab::Metrics::MethodCall do
describe
'#to_metric'
do
it
'returns a Metric instance'
do
expect
(
method_call
).
to
receive
(
:real_time
).
and_return
(
4.0001
)
expect
(
method_call
).
to
receive
(
:cpu_time
).
and_return
(
3.0001
)
method_call
.
measure
{
'foo'
}
metric
=
method_call
.
to_metric
expect
(
metric
).
to
be_an_instance_of
(
Gitlab
::
Metrics
::
Metric
)
expect
(
metric
.
series
).
to
eq
(
'rails_method_calls'
)
expect
(
metric
.
values
[
:duration
]).
to
be_a_kind_of
(
Numeric
)
expect
(
metric
.
values
[
:cpu_duration
]).
to
be_a_kind_of
(
Numeric
)
expect
(
metric
.
values
[
:duration
]).
to
eq
(
4000
)
expect
(
metric
.
values
[
:cpu_duration
]).
to
eq
(
3000
)
expect
(
metric
.
values
[
:call_count
]).
to
be_an
(
Integer
)
expect
(
metric
.
tags
).
to
eq
({
method:
'Foo#bar'
})
...
...
@@ -85,13 +87,13 @@ describe Gitlab::Metrics::MethodCall do
end
it
'returns false when the total call time is not above the threshold'
do
expect
(
method_call
).
to
receive
(
:real_time
_seconds
).
and_return
(
0.009
)
expect
(
method_call
).
to
receive
(
:real_time
).
and_return
(
0.009
)
expect
(
method_call
.
above_threshold?
).
to
eq
(
false
)
end
it
'returns true when the total call time is above the threshold'
do
expect
(
method_call
).
to
receive
(
:real_time
_seconds
).
and_return
(
9
)
expect
(
method_call
).
to
receive
(
:real_time
).
and_return
(
9
)
expect
(
method_call
.
above_threshold?
).
to
eq
(
true
)
end
...
...
@@ -132,7 +134,7 @@ describe Gitlab::Metrics::MethodCall do
describe
'#real_time'
do
context
'without timings'
do
it
'returns 0.0'
do
expect
(
method_call
.
real_time
_seconds
).
to
eq
(
0.0
)
expect
(
method_call
.
real_time
).
to
eq
(
0.0
)
end
end
...
...
@@ -140,7 +142,7 @@ describe Gitlab::Metrics::MethodCall do
it
'returns the total real time'
do
method_call
.
measure
{
'foo'
}
expect
(
method_call
.
real_time
_seconds
>=
0.0
).
to
be
(
true
)
expect
(
method_call
.
real_time
>=
0.0
).
to
be
(
true
)
end
end
end
...
...
spec/lib/gitlab/metrics/system_spec.rb
View file @
040167f0
...
...
@@ -29,13 +29,13 @@ describe Gitlab::Metrics::System do
describe
'.cpu_time'
do
it
'returns a Fixnum'
do
expect
(
described_class
.
cpu_time
).
to
be_an
(
Integer
)
expect
(
described_class
.
cpu_time
).
to
be_an
(
Float
)
end
end
describe
'.real_time'
do
it
'returns a Fixnum'
do
expect
(
described_class
.
real_time
).
to
be_an
(
Integer
)
expect
(
described_class
.
real_time
).
to
be_an
(
Float
)
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