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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
dcacda20
Commit
dcacda20
authored
Jul 24, 2017
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add license check before enabling DB load balancing
parent
917438cc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
6 deletions
+46
-6
app/models/license.rb
app/models/license.rb
+3
-0
config/initializers/load_balancing.rb
config/initializers/load_balancing.rb
+9
-6
lib/gitlab/database/load_balancing.rb
lib/gitlab/database/load_balancing.rb
+2
-0
spec/lib/gitlab/database/load_balancing_spec.rb
spec/lib/gitlab/database/load_balancing_spec.rb
+32
-0
No files found.
app/models/license.rb
View file @
dcacda20
...
@@ -6,6 +6,7 @@ class License < ActiveRecord::Base
...
@@ -6,6 +6,7 @@ class License < ActiveRecord::Base
AUDITOR_USER_FEATURE
=
'GitLab_Auditor_User'
.
freeze
AUDITOR_USER_FEATURE
=
'GitLab_Auditor_User'
.
freeze
BURNDOWN_CHARTS_FEATURE
=
'GitLab_BurndownCharts'
.
freeze
BURNDOWN_CHARTS_FEATURE
=
'GitLab_BurndownCharts'
.
freeze
CONTRIBUTION_ANALYTICS_FEATURE
=
'GitLab_ContributionAnalytics'
.
freeze
CONTRIBUTION_ANALYTICS_FEATURE
=
'GitLab_ContributionAnalytics'
.
freeze
DB_LOAD_BALANCING_FEATURE
=
'GitLab_DbLoadBalancing'
.
freeze
DEPLOY_BOARD_FEATURE
=
'GitLab_DeployBoard'
.
freeze
DEPLOY_BOARD_FEATURE
=
'GitLab_DeployBoard'
.
freeze
ELASTIC_SEARCH_FEATURE
=
'GitLab_ElasticSearch'
.
freeze
ELASTIC_SEARCH_FEATURE
=
'GitLab_ElasticSearch'
.
freeze
EXPORT_ISSUES_FEATURE
=
'GitLab_ExportIssues'
.
freeze
EXPORT_ISSUES_FEATURE
=
'GitLab_ExportIssues'
.
freeze
...
@@ -34,6 +35,7 @@ class License < ActiveRecord::Base
...
@@ -34,6 +35,7 @@ class License < ActiveRecord::Base
FEATURE_CODES
=
{
FEATURE_CODES
=
{
admin_audit_log:
ADMIN_AUDIT_LOG_FEATURE
,
admin_audit_log:
ADMIN_AUDIT_LOG_FEATURE
,
auditor_user:
AUDITOR_USER_FEATURE
,
auditor_user:
AUDITOR_USER_FEATURE
,
db_load_balancing:
DB_LOAD_BALANCING_FEATURE
,
elastic_search:
ELASTIC_SEARCH_FEATURE
,
elastic_search:
ELASTIC_SEARCH_FEATURE
,
geo:
GEO_FEATURE
,
geo:
GEO_FEATURE
,
object_storage:
OBJECT_STORAGE_FEATURE
,
object_storage:
OBJECT_STORAGE_FEATURE
,
...
@@ -98,6 +100,7 @@ class License < ActiveRecord::Base
...
@@ -98,6 +100,7 @@ class License < ActiveRecord::Base
*
EES_FEATURES
,
*
EES_FEATURES
,
{
ADMIN_AUDIT_LOG_FEATURE
=>
1
},
{
ADMIN_AUDIT_LOG_FEATURE
=>
1
},
{
AUDITOR_USER_FEATURE
=>
1
},
{
AUDITOR_USER_FEATURE
=>
1
},
{
DB_LOAD_BALANCING_FEATURE
=>
1
},
{
DEPLOY_BOARD_FEATURE
=>
1
},
{
DEPLOY_BOARD_FEATURE
=>
1
},
{
FILE_LOCKS_FEATURE
=>
1
},
{
FILE_LOCKS_FEATURE
=>
1
},
{
GEO_FEATURE
=>
1
},
{
GEO_FEATURE
=>
1
},
...
...
config/initializers/load_balancing.rb
View file @
dcacda20
if
Gitlab
::
Database
::
LoadBalancing
.
enable?
# We need to run this initializer after migrations are done so it doesn't fail on CI
Gitlab
::
Database
.
disable_prepared_statements
if
ActiveRecord
::
Base
.
connected?
&&
ActiveRecord
::
Base
.
connection
.
table_exists?
(
'licenses'
)
if
Gitlab
::
Database
::
LoadBalancing
.
enable?
Gitlab
::
Database
.
disable_prepared_statements
Gitlab
::
Application
.
configure
do
|
config
|
Gitlab
::
Application
.
configure
do
|
config
|
config
.
middleware
.
use
(
Gitlab
::
Database
::
LoadBalancing
::
RackMiddleware
)
config
.
middleware
.
use
(
Gitlab
::
Database
::
LoadBalancing
::
RackMiddleware
)
end
end
Gitlab
::
Database
::
LoadBalancing
.
configure_proxy
Gitlab
::
Database
::
LoadBalancing
.
configure_proxy
end
end
end
lib/gitlab/database/load_balancing.rb
View file @
dcacda20
...
@@ -45,6 +45,8 @@ module Gitlab
...
@@ -45,6 +45,8 @@ module Gitlab
# Returns true if load balancing is to be enabled.
# Returns true if load balancing is to be enabled.
def
self
.
enable?
def
self
.
enable?
return
false
unless
::
License
.
feature_available?
(
:db_load_balancing
)
program_name
!=
'rake'
&&
!
hosts
.
empty?
&&
!
Sidekiq
.
server?
&&
program_name
!=
'rake'
&&
!
hosts
.
empty?
&&
!
Sidekiq
.
server?
&&
Database
.
postgresql?
Database
.
postgresql?
end
end
...
...
spec/lib/gitlab/database/load_balancing_spec.rb
View file @
dcacda20
...
@@ -26,6 +26,8 @@ describe Gitlab::Database::LoadBalancing do
...
@@ -26,6 +26,8 @@ describe Gitlab::Database::LoadBalancing do
end
end
describe
'.enable?'
do
describe
'.enable?'
do
let!
(
:license
)
{
create
(
:license
,
plan:
::
License
::
PREMIUM_PLAN
)
}
it
'returns false when no hosts are specified'
do
it
'returns false when no hosts are specified'
do
allow
(
described_class
).
to
receive
(
:hosts
).
and_return
([])
allow
(
described_class
).
to
receive
(
:hosts
).
and_return
([])
...
@@ -60,6 +62,36 @@ describe Gitlab::Database::LoadBalancing do
...
@@ -60,6 +62,36 @@ describe Gitlab::Database::LoadBalancing do
expect
(
described_class
.
enable?
).
to
eq
(
true
)
expect
(
described_class
.
enable?
).
to
eq
(
true
)
end
end
context
'without a license'
do
before
do
License
.
destroy_all
end
it
'is disabled'
do
expect
(
described_class
.
enable?
).
to
eq
(
false
)
end
end
context
'with an EES license'
do
let!
(
:license
)
{
create
(
:license
,
plan:
::
License
::
STARTER_PLAN
)
}
it
'is disabled'
do
expect
(
described_class
.
enable?
).
to
eq
(
false
)
end
end
context
'with an EEP license'
do
let!
(
:license
)
{
create
(
:license
,
plan:
::
License
::
PREMIUM_PLAN
)
}
it
'is enabled'
do
allow
(
described_class
).
to
receive
(
:hosts
).
and_return
(
%w(foo)
)
allow
(
Sidekiq
).
to
receive
(
:server?
).
and_return
(
false
)
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
enable?
).
to
eq
(
true
)
end
end
end
end
describe
'.program_name'
do
describe
'.program_name'
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