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
66c1acba
Commit
66c1acba
authored
Jan 16, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix code after refactoring
parent
53f818fd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
46 deletions
+45
-46
lib/gitlab/metrics/concern.rb
lib/gitlab/metrics/concern.rb
+8
-11
lib/gitlab/metrics/concern/metric_options.rb
lib/gitlab/metrics/concern/metric_options.rb
+13
-11
lib/gitlab/metrics/method_call.rb
lib/gitlab/metrics/method_call.rb
+5
-4
lib/gitlab/metrics/transaction.rb
lib/gitlab/metrics/transaction.rb
+18
-19
spec/lib/gitlab/metrics/method_call_spec.rb
spec/lib/gitlab/metrics/method_call_spec.rb
+1
-1
No files found.
lib/gitlab/metrics/concern.rb
View file @
66c1acba
...
...
@@ -9,6 +9,10 @@ module Gitlab
end
class_methods
do
def
reload_metric!
(
name
)
@@_metrics_provider_cache
.
delete
(
name
)
end
private
def
define_metric
(
type
,
name
,
opts
=
{},
&
block
)
...
...
@@ -16,7 +20,7 @@ module Gitlab
raise
ArgumentError
,
"metrics method
#{
name
}
already exists"
end
define_method
(
name
)
do
define_
singleton_
method
(
name
)
do
# avoid unnecessary method call to speed up metric access
return
@@_metrics_provider_cache
[
name
]
if
@@_metrics_provider_cache
.
has_key?
(
name
)
...
...
@@ -45,12 +49,11 @@ module Gitlab
case
type
when
:gauge
Gitlab
::
Metrics
.
gauge
(
name
,
options
.
docs
,
options
.
base_labels
,
options
.
multiprocess_mode
)
Gitlab
::
Metrics
.
gauge
(
name
,
options
.
docs
tring
,
options
.
base_labels
,
options
.
multiprocess_mode
)
when
:counter
Gitlab
::
Metrics
.
counter
(
name
,
options
.
docs
,
options
.
base_labels
)
Gitlab
::
Metrics
.
counter
(
name
,
options
.
docs
tring
,
options
.
base_labels
)
when
:histogram
options
[
:buckets
]
||=
::
Prometheus
::
Client
::
Histogram
::
DEFAULT_BUCKETS
Gitlab
::
Metrics
.
histogram
(
name
,
options
.
docs
,
options
.
base_labels
,
options
.
buckets
)
Gitlab
::
Metrics
.
histogram
(
name
,
options
.
docstring
,
options
.
base_labels
,
options
.
buckets
)
when
:summary
raise
NotImplementedError
,
"summary metrics are not currently supported"
else
...
...
@@ -58,12 +61,6 @@ module Gitlab
end
end
counter
:global
do
docstring
"Global counter"
multiprocess_mode
:all
buckets
[
0
,
1
]
end
# Fetch and/or initialize counter metric
# @param [Symbol] name
# @param [Hash] opts
...
...
lib/gitlab/metrics/concern/metric_options.rb
View file @
66c1acba
...
...
@@ -6,34 +6,36 @@ module Gitlab
@multiprocess_mode
=
options
[
:multiprocess_mode
]
||
:all
@buckets
=
options
[
:buckets
]
||
::
Prometheus
::
Client
::
Histogram
::
DEFAULT_BUCKETS
@base_labels
=
options
[
:base_labels
]
||
{}
@docstring
=
options
[
:docstring
]
@with_feature
=
options
[
:with_feature
]
end
def
docs
(
docs
=
nil
)
@docs
=
docs
unless
docs
.
nil?
def
docs
tring
(
docstring
=
nil
)
@docs
tring
=
docstring
unless
docstring
.
nil?
@docs
@docs
tring
end
def
multiprocess_mode
(
mode
)
@multiprocess_mode
=
mode
unless
@multiprocess_
mode
.
nil?
def
multiprocess_mode
(
mode
=
nil
)
@multiprocess_mode
=
mode
unless
mode
.
nil?
@multiprocess_mode
end
def
buckets
(
buckets
)
@buckets
=
buckets
unless
@
buckets
.
nil?
def
buckets
(
buckets
=
nil
)
@buckets
=
buckets
unless
buckets
.
nil?
@buckets
end
def
base_labels
(
base_labels
)
@base_labels
=
base_labels
unless
@
base_labels
.
nil?
def
base_labels
(
base_labels
=
nil
)
@base_labels
=
base_labels
unless
base_labels
.
nil?
@base_labels
end
def
with_feature
(
name
)
@feature_name
=
name
unless
@feature_
name
.
nil?
def
with_feature
(
name
=
nil
)
@feature_name
=
name
unless
name
.
nil?
@feature_name
end
...
...
lib/gitlab/metrics/method_call.rb
View file @
66c1acba
...
...
@@ -8,7 +8,8 @@ module Gitlab
BASE_LABELS
=
{
module:
nil
,
method:
nil
}.
freeze
attr_reader
:real_time
,
:cpu_time
,
:call_count
,
:labels
histogram
:gitlab_method_call_duration_seconds
,
'Method calls real duration'
,
define_histogram
:gitlab_method_call_duration_seconds
,
docstring:
'Method calls real duration'
,
base_labels:
Transaction
::
BASE_LABELS
.
merge
(
BASE_LABELS
),
buckets:
[
0.01
,
0.05
,
0.1
,
0.5
,
1
],
with_feature: :prometheus_metrics_method_instrumentation
...
...
lib/gitlab/metrics/transaction.rb
View file @
66c1acba
...
...
@@ -2,11 +2,12 @@ module Gitlab
module
Metrics
# Class for storing metrics information of a single transaction.
class
Transaction
include
Gitlab
::
Metrics
::
Concern
# base labels shared among all transactions
BASE_LABELS
=
{
controller:
nil
,
action:
nil
}.
freeze
THREAD_KEY
=
:_gitlab_metrics_transaction
METRICS_MUTEX
=
Mutex
.
new
# The series to store events (e.g. Git pushes) in.
EVENT_SERIES
=
'events'
.
freeze
...
...
@@ -136,26 +137,24 @@ module Gitlab
"
#{
labels
[
:controller
]
}
#
#{
labels
[
:action
]
}
"
if
labels
&&
!
labels
.
empty?
end
histogram
:gitlab_transaction_duration_seconds
,
'Transaction duration'
,
define_histogram
:gitlab_transaction_duration_seconds
,
docstring:
'Transaction duration'
,
base_labels:
BASE_LABELS
,
buckets:
[
0.001
,
0.01
,
0.1
,
0.5
,
10.0
],
with_feature: :prometheus_metrics_method_instrumentation
histogram
:gitlab_transaction_allocated_memory_bytes
,
'Transaction allocated memory bytes'
,
define_histogram
:gitlab_transaction_allocated_memory_bytes
,
docstring:
'Transaction allocated memory bytes'
,
base_labels:
BASE_LABELS
,
buckets:
[
100
,
1000
,
10000
,
100000
,
1000000
,
10000000
]
def
self
.
transaction_metric
(
name
,
type
,
prefix:
nil
,
tags:
{})
return
@transaction_metric
[
name
]
if
@transaction_metric
[
name
]
&
.
has_key?
(
name
)
METRICS_MUTEX
.
synchronize
do
@transaction_metric
||=
{}
@transaction_metric
[
name
]
||=
if
type
==
:counter
Gitlab
::
Metrics
.
counter
(
"gitlab_transaction_
#{
prefix
}#{
name
}
_total"
.
to_sym
,
"Transaction
#{
prefix
}#{
name
}
counter"
,
tags
.
merge
(
BASE_LABELS
))
else
Gitlab
::
Metrics
.
gauge
(
"gitlab_transaction_
#{
name
}
"
.
to_sym
,
"Transaction gauge
#{
name
}
"
,
tags
.
merge
(
BASE_LABELS
),
:livesum
)
metric_name
=
"gitlab_transaction_
#{
prefix
}#{
name
}
_total"
.
to_sym
fetch_metric
(
type
,
metric_name
)
do
docstring
"Transaction
#{
prefix
}#{
name
}
#{
type
}
"
base_labels
tags
.
merge
(
BASE_LABELS
)
if
type
==
:gauge
multiprocess_mode
:livesum
end
end
end
...
...
spec/lib/gitlab/metrics/method_call_spec.rb
View file @
66c1acba
...
...
@@ -6,7 +6,7 @@ describe Gitlab::Metrics::MethodCall do
describe
'#measure'
do
before
do
described_class
.
reload_
gitlab_method_call_duration_seconds!
described_class
.
reload_
metric!
(
:gitlab_method_call_duration_seconds
)
end
it
'measures the performance of the supplied block'
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