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
e21b1501
Commit
e21b1501
authored
Jun 02, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow enabling Prometheus metrics via ENV variable when db is seeded
parent
7b75004d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
7 deletions
+66
-7
db/fixtures/production/010_settings.rb
db/fixtures/production/010_settings.rb
+20
-7
spec/db/production/settings_spec.rb
spec/db/production/settings_spec.rb
+46
-0
No files found.
db/fixtures/production/010_settings.rb
View file @
e21b1501
if
ENV
[
'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN'
].
present?
def
save
(
settings
,
topic
)
settings
=
ApplicationSetting
.
current
||
ApplicationSetting
.
create_from_defaults
settings
.
set_runners_registration_token
(
ENV
[
'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN'
])
if
settings
.
save
if
settings
.
save
puts
"Saved
Runner Registration Token
"
.
color
(
:green
)
puts
"Saved
#{
topic
}
"
.
color
(
:green
)
else
else
puts
"Could not save
Runner Registration Token
"
.
color
(
:red
)
puts
"Could not save
#{
topic
}
"
.
color
(
:red
)
puts
puts
settings
.
errors
.
full_messages
.
map
do
|
message
|
settings
.
errors
.
full_messages
.
map
do
|
message
|
puts
"-->
#{
message
}
"
.
color
(
:red
)
puts
"-->
#{
message
}
"
.
color
(
:red
)
end
end
puts
puts
exit
1
exit
(
1
)
end
end
envs
=
%w{ GITLAB_PROMETHEUS_METRICS_ENABLED GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN }
if
envs
.
any?
{
|
env_name
|
ENV
[
env_name
].
present?
}
settings
=
ApplicationSetting
.
current
||
ApplicationSetting
.
create_from_defaults
if
ENV
[
'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN'
].
present?
settings
.
set_runners_registration_token
(
ENV
[
'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN'
])
save
(
settings
,
'Runner Registration Token'
)
end
if
ENV
[
'GITLAB_PROMETHEUS_METRICS_ENABLED'
].
present?
value
=
Gitlab
::
Utils
.
to_boolean
(
ENV
[
'GITLAB_PROMETHEUS_METRICS_ENABLED'
])
settings
.
prometheus_metrics_enabled
=
value
save
(
settings
,
'GITLAB_PROMETHEUS_METRICS_ENABLED'
)
end
end
end
end
spec/db/production/settings_spec.rb
0 → 100644
View file @
e21b1501
require
'spec_helper'
require
'rainbow/ext/string'
describe
'seed production settings'
,
lib:
true
do
include
StubENV
let
(
:settings_file
)
{
File
.
join
(
__dir__
,
'../../../db/fixtures/production/010_settings.rb'
)
}
let
(
:settings
)
{
ApplicationSetting
.
current
||
ApplicationSetting
.
create_from_defaults
}
context
'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN is set in the environment'
do
before
do
stub_env
(
'GITLAB_SHARED_RUNNERS_REGISTRATION_TOKEN'
,
'013456789'
)
end
it
'writes the token to the database'
do
load
(
settings_file
)
expect
(
settings
.
runners_registration_token
).
to
eq
(
'013456789'
)
end
end
context
'GITLAB_PROMETHEUS_METRICS_ENABLED is set in the environment'
do
context
'GITLAB_PROMETHEUS_METRICS_ENABLED is true'
do
before
do
stub_env
(
'GITLAB_PROMETHEUS_METRICS_ENABLED'
,
'true'
)
end
it
'prometheus_metrics_enabled is set to true '
do
load
(
settings_file
)
expect
(
settings
.
prometheus_metrics_enabled
).
to
eq
(
true
)
end
end
context
'GITLAB_PROMETHEUS_METRICS_ENABLED is false'
do
before
do
stub_env
(
'GITLAB_PROMETHEUS_METRICS_ENABLED'
,
'false'
)
end
it
'prometheus_metrics_enabled is set to false'
do
load
(
settings_file
)
expect
(
settings
.
prometheus_metrics_enabled
).
to
eq
(
false
)
end
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