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
Jérome Perrin
gitlab-ce
Commits
b4dbc306
Commit
b4dbc306
authored
Sep 07, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Guard metrics creation with a mutex
parent
f64085e6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
lib/gitlab/metrics/prometheus.rb
lib/gitlab/metrics/prometheus.rb
+23
-7
No files found.
lib/gitlab/metrics/prometheus.rb
View file @
b4dbc306
...
...
@@ -5,6 +5,9 @@ module Gitlab
module
Prometheus
include
Gitlab
::
CurrentSettings
REGISTRY_MUTEX
=
Mutex
.
new
PROVIDER_MUTEX
=
Mutex
.
new
def
metrics_folder_present?
multiprocess_files_dir
=
::
Prometheus
::
Client
.
configuration
.
multiprocess_files_dir
...
...
@@ -20,23 +23,38 @@ module Gitlab
end
def
registry
@registry
||=
::
Prometheus
::
Client
.
registry
return
@registry
if
@registry
REGISTRY_MUTEX
.
synchronize
do
@registry
||=
::
Prometheus
::
Client
.
registry
end
end
def
counter
(
name
,
docstring
,
base_labels
=
{})
provide_metric
(
name
)
||
registry
.
counter
(
name
,
docstring
,
base_labels
)
safe_provide_metric
(
:counter
,
name
,
docstring
,
base_labels
)
end
def
summary
(
name
,
docstring
,
base_labels
=
{})
provide_metric
(
name
)
||
registry
.
summary
(
name
,
docstring
,
base_labels
)
safe_provide_metric
(
:summary
,
name
,
docstring
,
base_labels
)
end
def
gauge
(
name
,
docstring
,
base_labels
=
{},
multiprocess_mode
=
:all
)
provide_metric
(
name
)
||
registry
.
gauge
(
name
,
docstring
,
base_labels
,
multiprocess_mode
)
safe_provide_metric
(
:gauge
,
name
,
docstring
,
base_labels
,
multiprocess_mode
)
end
def
histogram
(
name
,
docstring
,
base_labels
=
{},
buckets
=
::
Prometheus
::
Client
::
Histogram
::
DEFAULT_BUCKETS
)
provide_metric
(
name
)
||
registry
.
histogram
(
name
,
docstring
,
base_labels
,
buckets
)
safe_provide_metric
(
:histogram
,
name
,
docstring
,
base_labels
,
buckets
)
end
private
def
safe_provide_metric
(
method
,
name
,
*
args
)
metric
=
provide_metric
(
name
)
return
metric
if
metric
PROVIDER_MUTEX
.
synchronize
do
provide_metric
(
name
)
||
registry
.
send
(
method
,
*
args
)
end
end
def
provide_metric
(
name
)
...
...
@@ -47,8 +65,6 @@ module Gitlab
end
end
private
def
prometheus_metrics_enabled_unmemoized
metrics_folder_present?
&&
current_application_settings
[
:prometheus_metrics_enabled
]
||
false
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