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
aa4ec037
Commit
aa4ec037
authored
May 18, 2020
by
allison.browne
Committed by
Ash McKenzie
May 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes based on Code Review
Add specs for GitLab staging helper Add a new helper method, other cleanup.
parent
cb5938d2
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
17 deletions
+73
-17
db/structure.sql
db/structure.sql
+2
-1
lib/gitlab.rb
lib/gitlab.rb
+5
-1
lib/gitlab/monitor/demo_projects.rb
lib/gitlab/monitor/demo_projects.rb
+10
-3
spec/lib/gitlab/monitor/demo_projects_spec.rb
spec/lib/gitlab/monitor/demo_projects_spec.rb
+12
-11
spec/lib/gitlab_spec.rb
spec/lib/gitlab_spec.rb
+43
-0
spec/workers/clusters/applications/check_prometheus_health_worker_spec.rb
...sters/applications/check_prometheus_health_worker_spec.rb
+1
-1
No files found.
db/structure.sql
View file @
aa4ec037
...
@@ -5283,7 +5283,8 @@ CREATE TABLE public.project_settings (
...
@@ -5283,7 +5283,8 @@ CREATE TABLE public.project_settings (
created_at
timestamp
with
time
zone
NOT
NULL
,
created_at
timestamp
with
time
zone
NOT
NULL
,
updated_at
timestamp
with
time
zone
NOT
NULL
,
updated_at
timestamp
with
time
zone
NOT
NULL
,
push_rule_id
bigint
,
push_rule_id
bigint
,
show_default_award_emojis
boolean
DEFAULT
true
NOT
NULL
show_default_award_emojis
boolean
DEFAULT
true
,
CONSTRAINT
check_bde223416c
CHECK
((
show_default_award_emojis
IS
NOT
NULL
))
);
);
CREATE
TABLE
public
.
project_statistics
(
CREATE
TABLE
public
.
project_statistics
(
...
...
lib/gitlab.rb
View file @
aa4ec037
...
@@ -35,8 +35,8 @@ module Gitlab
...
@@ -35,8 +35,8 @@ module Gitlab
end
end
end
end
STAGING_COM_URL
=
'https://staging.gitlab.com'
COM_URL
=
'https://gitlab.com'
COM_URL
=
'https://gitlab.com'
STAGING_COM_URL
=
'https://staging.gitlab.com'
APP_DIRS_PATTERN
=
%r{^/?(app|config|ee|lib|spec|
\(\w
*
\)
)}
.
freeze
APP_DIRS_PATTERN
=
%r{^/?(app|config|ee|lib|spec|
\(\w
*
\)
)}
.
freeze
SUBDOMAIN_REGEX
=
%r{
\A
https://[a-z0-9]+
\.
gitlab
\.
com
\z
}
.
freeze
SUBDOMAIN_REGEX
=
%r{
\A
https://[a-z0-9]+
\.
gitlab
\.
com
\z
}
.
freeze
VERSION
=
File
.
read
(
root
.
join
(
"VERSION"
)).
strip
.
freeze
VERSION
=
File
.
read
(
root
.
join
(
"VERSION"
)).
strip
.
freeze
...
@@ -80,6 +80,10 @@ module Gitlab
...
@@ -80,6 +80,10 @@ module Gitlab
Rails
.
env
.
development?
||
com?
Rails
.
env
.
development?
||
com?
end
end
def
self
.
dev_or_test_env?
Rails
.
env
.
development?
||
Rails
.
env
.
test?
end
def
self
.
ee?
def
self
.
ee?
@is_ee
||=
@is_ee
||=
# We use this method when the Rails environment is not loaded. This
# We use this method when the Rails environment is not loaded. This
...
...
lib/gitlab/monitor/demo_projects.rb
View file @
aa4ec037
...
@@ -2,18 +2,25 @@
...
@@ -2,18 +2,25 @@
module
Gitlab
module
Gitlab
module
Monitor
module
Monitor
# See Demo Project documentation
# https://about.gitlab.com/handbook/engineering/development/ops/monitor/#demo-environments
module
DemoProjects
module
DemoProjects
# [https://gitlab.com/gitlab-org/monitor/tanuki-inc, https://gitlab.com/gitlab-org/monitor/monitor-sandbox]
DOT_COM_IDS
=
[
14986497
,
12507547
].
freeze
DOT_COM_IDS
=
[
14986497
,
12507547
].
freeze
# [https://staging.gitlab.com/gitlab-org/monitor/monitor-sandbox]
STAGING_IDS
=
[
4422333
].
freeze
STAGING_IDS
=
[
4422333
].
freeze
def
self
.
primary_keys
def
self
.
primary_keys
if
::
Gitlab
.
com?
# .com? returns true for staging
if
::
Gitlab
.
com?
&&
!::
Gitlab
.
staging?
DOT_COM_IDS
DOT_COM_IDS
elsif
::
Gitlab
.
staging?
elsif
::
Gitlab
.
staging?
STAGING_IDS
STAGING_IDS
elsif
Rails
.
env
.
development?
||
Rails
.
env
.
test
?
elsif
::
Gitlab
.
dev_or_test_env
?
Project
.
pluck
(
:id
)
# rubocop: disable CodeReuse/ActiveRecord
Project
.
pluck
(
:id
)
# rubocop: disable CodeReuse/ActiveRecord
end
||
[]
else
[]
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/monitor/demo_projects_spec.rb
View file @
aa4ec037
...
@@ -6,29 +6,30 @@ describe Gitlab::Monitor::DemoProjects do
...
@@ -6,29 +6,30 @@ describe Gitlab::Monitor::DemoProjects do
describe
'#primary_keys'
do
describe
'#primary_keys'
do
subject
{
described_class
.
primary_keys
}
subject
{
described_class
.
primary_keys
}
it
'fetches primary_keys when in test env'
do
project
=
create
(
:project
)
expect
(
subject
).
to
eq
([
project
.
id
])
end
it
'fetches primary_keys when on gitlab.com'
do
it
'fetches primary_keys when on gitlab.com'
do
expect
(
Gitlab
).
to
receive
(
:'com?'
).
and_return
(
true
)
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
allow
(
Gitlab
).
to
receive
(
:staging?
).
and_return
(
false
)
expect
(
subject
).
to
eq
(
Gitlab
::
Monitor
::
DemoProjects
::
DOT_COM_IDS
)
expect
(
subject
).
to
eq
(
Gitlab
::
Monitor
::
DemoProjects
::
DOT_COM_IDS
)
end
end
it
'fetches primary_keys when on staging'
do
it
'fetches primary_keys when on staging'
do
expect
(
Gitlab
).
to
receive
(
:staging?
).
and_return
(
true
)
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
allow
(
Gitlab
).
to
receive
(
:staging?
).
and_return
(
true
)
expect
(
subject
).
to
eq
(
Gitlab
::
Monitor
::
DemoProjects
::
STAGING_IDS
)
expect
(
subject
).
to
eq
(
Gitlab
::
Monitor
::
DemoProjects
::
STAGING_IDS
)
end
end
it
'fetches all keys when in the dev or test env'
do
project
=
create
(
:project
)
allow
(
Gitlab
).
to
receive
(
:dev_or_test_env?
).
and_return
(
true
)
expect
(
subject
).
to
eq
([
project
.
id
])
end
it
'falls back on empty array'
do
it
'falls back on empty array'
do
stub_config_setting
(
url:
'https://helloworld'
)
stub_config_setting
(
url:
'https://helloworld'
)
expect
(
Rails
).
to
receive
(
:env
).
and_return
(
allow
(
Gitlab
).
to
receive
(
:dev_or_test_env?
).
and_return
(
false
)
double
(
development?:
false
,
test?:
false
)
).
twice
expect
(
subject
).
to
eq
([])
expect
(
subject
).
to
eq
([])
end
end
...
...
spec/lib/gitlab_spec.rb
View file @
aa4ec037
...
@@ -96,6 +96,28 @@ describe Gitlab do
...
@@ -96,6 +96,28 @@ describe Gitlab do
end
end
end
end
describe
'.staging?'
do
subject
{
described_class
.
staging?
}
it
'is false when on GitLab.com'
do
stub_config_setting
(
url:
'https://gitlab.com'
)
expect
(
subject
).
to
eq
false
end
it
'is true when on staging'
do
stub_config_setting
(
url:
'https://staging.gitlab.com'
)
expect
(
subject
).
to
eq
true
end
it
'is flase when not on staging'
do
stub_config_setting
(
url:
'https://example.gitlab.com'
)
expect
(
subject
).
to
eq
false
end
end
describe
'.canary?'
do
describe
'.canary?'
do
it
'is true when CANARY env var is set to true'
do
it
'is true when CANARY env var is set to true'
do
stub_env
(
'CANARY'
,
'1'
)
stub_env
(
'CANARY'
,
'1'
)
...
@@ -186,6 +208,27 @@ describe Gitlab do
...
@@ -186,6 +208,27 @@ describe Gitlab do
end
end
end
end
describe
'.dev_or_test_env?'
do
subject
{
described_class
.
dev_or_test_env?
}
it
'is true when test env'
do
expect
(
subject
).
to
eq
true
end
it
'is true when dev env'
do
allow
(
Rails
).
to
receive
(
:env
).
and_return
(
ActiveSupport
::
StringInquirer
.
new
(
'development'
))
expect
(
subject
).
to
eq
true
end
it
'is false when env is not dev or test'
do
allow
(
described_class
).
to
receive
(
:com?
).
and_return
(
false
)
allow
(
Rails
).
to
receive
(
:env
).
and_return
(
ActiveSupport
::
StringInquirer
.
new
(
'production'
))
expect
(
subject
).
to
eq
false
end
end
describe
'.ee?'
do
describe
'.ee?'
do
before
do
before
do
stub_env
(
'FOSS_ONLY'
,
nil
)
# Make sure the ENV is clean
stub_env
(
'FOSS_ONLY'
,
nil
)
# Make sure the ENV is clean
...
...
spec/workers/clusters/applications/check_prometheus_health_worker_spec.rb
View file @
aa4ec037
...
@@ -8,7 +8,7 @@ describe Clusters::Applications::CheckPrometheusHealthWorker, '#perform' do
...
@@ -8,7 +8,7 @@ describe Clusters::Applications::CheckPrometheusHealthWorker, '#perform' do
it
'triggers health service'
do
it
'triggers health service'
do
cluster
=
create
(
:cluster
)
cluster
=
create
(
:cluster
)
allow
(
Gitlab
::
Monitor
::
DemoProjects
).
to
receive
(
:primary_keys
)
allow
(
Gitlab
::
Monitor
::
DemoProjects
).
to
receive
(
:primary_keys
)
allow
(
Clusters
::
Cluster
).
to
receive
(
:with_application_prometheus
).
and_return
(
double
(
with_project_alert_service_data:
[
cluster
])
)
allow
(
Clusters
::
Cluster
).
to
receive
_message_chain
(
:with_application_prometheus
,
:with_project_alert_service_data
).
and_return
([
cluster
]
)
service_instance
=
instance_double
(
Clusters
::
Applications
::
PrometheusHealthCheckService
)
service_instance
=
instance_double
(
Clusters
::
Applications
::
PrometheusHealthCheckService
)
expect
(
Clusters
::
Applications
::
PrometheusHealthCheckService
).
to
receive
(
:new
).
with
(
cluster
).
and_return
(
service_instance
)
expect
(
Clusters
::
Applications
::
PrometheusHealthCheckService
).
to
receive
(
:new
).
with
(
cluster
).
and_return
(
service_instance
)
...
...
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