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
7d716cc8
Commit
7d716cc8
authored
Jan 19, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert InfluxDB to concern. Fix uninitialized metrics when metrics code is inherited.
parent
ea6196d4
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
157 additions
and
150 deletions
+157
-150
lib/gitlab/metrics.rb
lib/gitlab/metrics.rb
+1
-1
lib/gitlab/metrics/concern.rb
lib/gitlab/metrics/concern.rb
+5
-4
lib/gitlab/metrics/influx_db.rb
lib/gitlab/metrics/influx_db.rb
+145
-141
lib/gitlab/metrics/prometheus.rb
lib/gitlab/metrics/prometheus.rb
+1
-2
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
+5
-2
No files found.
lib/gitlab/metrics.rb
View file @
7d716cc8
module
Gitlab
module
Metrics
extend
Gitlab
::
Metrics
::
InfluxDb
include
Gitlab
::
Metrics
::
InfluxDb
include
Gitlab
::
Metrics
::
Prometheus
def
self
.
enabled?
...
...
lib/gitlab/metrics/concern.rb
View file @
7d716cc8
...
...
@@ -6,7 +6,7 @@ module Gitlab
extend
ActiveSupport
::
Concern
included
do
@_metric_provider_mutex
=
Mutex
.
new
@
@
_metric_provider_mutex
=
Mutex
.
new
@_metrics_provider_cache
=
{}
end
...
...
@@ -23,12 +23,12 @@ module Gitlab
end
define_singleton_method
(
name
)
do
@_metrics_provider_cache
[
name
]
||
init_metric
(
type
,
name
,
opts
,
&
block
)
@_metrics_provider_cache
&
.
[
](
name
)
||
init_metric
(
type
,
name
,
opts
,
&
block
)
end
end
def
fetch_metric
(
type
,
name
,
opts
=
{},
&
block
)
@_metrics_provider_cache
[
name
]
||
init_metric
(
type
,
name
,
opts
,
&
block
)
@_metrics_provider_cache
&
.
[
](
name
)
||
init_metric
(
type
,
name
,
opts
,
&
block
)
end
def
init_metric
(
type
,
name
,
opts
=
{},
&
block
)
...
...
@@ -43,7 +43,8 @@ module Gitlab
end
def
synchronized_cache_fill
(
key
)
@_metric_provider_mutex
.
synchronize
do
@@_metric_provider_mutex
.
synchronize
do
@_metrics_provider_cache
||=
{}
@_metrics_provider_cache
[
key
]
||=
yield
end
end
...
...
lib/gitlab/metrics/influx_db.rb
View file @
7d716cc8
This diff is collapsed.
Click to expand it.
lib/gitlab/metrics/prometheus.rb
View file @
7d716cc8
...
...
@@ -4,13 +4,12 @@ module Gitlab
module
Metrics
module
Prometheus
extend
ActiveSupport
::
Concern
include
Gitlab
::
Metrics
::
Concern
include
Gitlab
::
CurrentSettings
REGISTRY_MUTEX
=
Mutex
.
new
PROVIDER_MUTEX
=
Mutex
.
new
class_methods
do
include
Gitlab
::
CurrentSettings
include
Gitlab
::
Utils
::
StrongMemoize
def
metrics_folder_present?
...
...
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
View file @
7d716cc8
...
...
@@ -144,7 +144,10 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
end
context
'with a transaction'
do
let
(
:metric_cache_misses_total
)
{
double
(
'metric_cache_misses_total'
,
increment:
nil
)
}
before
do
allow
(
subscriber
).
to
receive
(
:metric_cache_misses_total
).
and_return
(
metric_cache_misses_total
)
allow
(
subscriber
).
to
receive
(
:current_transaction
)
.
and_return
(
transaction
)
end
...
...
@@ -157,9 +160,9 @@ describe Gitlab::Metrics::Subscribers::RailsCache do
end
it
'increments the cache_read_miss total'
do
expect
(
subscriber
.
send
(
:metric_cache_misses_total
)).
to
receive
(
:increment
).
with
({})
subscriber
.
cache_generate
(
event
)
expect
(
metric_cache_misses_total
).
to
have_received
(
:increment
).
with
({})
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