BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
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
...
@@ -5,6 +5,9 @@ module Gitlab
module
Prometheus
module
Prometheus
include
Gitlab
::
CurrentSettings
include
Gitlab
::
CurrentSettings
REGISTRY_MUTEX
=
Mutex
.
new
PROVIDER_MUTEX
=
Mutex
.
new
def
metrics_folder_present?
def
metrics_folder_present?
multiprocess_files_dir
=
::
Prometheus
::
Client
.
configuration
.
multiprocess_files_dir
multiprocess_files_dir
=
::
Prometheus
::
Client
.
configuration
.
multiprocess_files_dir
...
@@ -20,23 +23,38 @@ module Gitlab
...
@@ -20,23 +23,38 @@ module Gitlab
end
end
def
registry
def
registry
@registry
||=
::
Prometheus
::
Client
.
registry
return
@registry
if
@registry
REGISTRY_MUTEX
.
synchronize
do
@registry
||=
::
Prometheus
::
Client
.
registry
end
end
end
def
counter
(
name
,
docstring
,
base_labels
=
{})
def
counter
(
name
,
docstring
,
base_labels
=
{})
provide_metric
(
name
)
||
registry
.
counter
(
name
,
docstring
,
base_labels
)
safe_provide_metric
(
:counter
,
name
,
docstring
,
base_labels
)
end
end
def
summary
(
name
,
docstring
,
base_labels
=
{})
def
summary
(
name
,
docstring
,
base_labels
=
{})
provide_metric
(
name
)
||
registry
.
summary
(
name
,
docstring
,
base_labels
)
safe_provide_metric
(
:summary
,
name
,
docstring
,
base_labels
)
end
end
def
gauge
(
name
,
docstring
,
base_labels
=
{},
multiprocess_mode
=
:all
)
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
end
def
histogram
(
name
,
docstring
,
base_labels
=
{},
buckets
=
::
Prometheus
::
Client
::
Histogram
::
DEFAULT_BUCKETS
)
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
end
def
provide_metric
(
name
)
def
provide_metric
(
name
)
...
@@ -47,8 +65,6 @@ module Gitlab
...
@@ -47,8 +65,6 @@ module Gitlab
end
end
end
end
private
def
prometheus_metrics_enabled_unmemoized
def
prometheus_metrics_enabled_unmemoized
metrics_folder_present?
&&
current_application_settings
[
:prometheus_metrics_enabled
]
||
false
metrics_folder_present?
&&
current_application_settings
[
:prometheus_metrics_enabled
]
||
false
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