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
4220db7f
Commit
4220db7f
authored
Apr 14, 2021
by
Piotr Skorupa
Committed by
Alper Akgun
Apr 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor stubbing Prometheus calls into a spec helper
parent
66ce587c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
39 deletions
+23
-39
spec/lib/generators/gitlab/usage_metric_definition/redis_hll_generator_spec.rb
...itlab/usage_metric_definition/redis_hll_generator_spec.rb
+3
-13
spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb
...nerators/gitlab/usage_metric_definition_generator_spec.rb
+1
-13
spec/support/helpers/usage_data_helpers.rb
spec/support/helpers/usage_data_helpers.rb
+16
-0
spec/tasks/gitlab/usage_data_rake_spec.rb
spec/tasks/gitlab/usage_data_rake_spec.rb
+3
-13
No files found.
spec/lib/generators/gitlab/usage_metric_definition/redis_hll_generator_spec.rb
View file @
4220db7f
...
...
@@ -3,6 +3,8 @@
require
'generator_helper'
RSpec
.
describe
Gitlab
::
UsageMetricDefinition
::
RedisHllGenerator
do
include
UsageDataHelpers
let
(
:category
)
{
'test_category'
}
let
(
:event
)
{
'i_test_event'
}
let
(
:args
)
{
[
category
,
event
]
}
...
...
@@ -13,19 +15,7 @@ RSpec.describe Gitlab::UsageMetricDefinition::RedisHllGenerator do
before
do
stub_const
(
"
#{
Gitlab
::
UsageMetricDefinitionGenerator
}
::TOP_LEVEL_DIR"
,
temp_dir
)
# Stub Prometheus requests from Gitlab::Utils::UsageData
stub_request
(
:get
,
%r{^https?://::1:9090/-/ready}
)
.
to_return
(
status:
200
,
body:
[{}].
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
)
stub_request
(
:get
,
%r{^https?://::1:9090/api/v1/query
\?
query=.*}
)
.
to_return
(
status:
200
,
body:
[{}].
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
)
stub_prometheus_queries
end
it
'creates metric definition files'
do
...
...
spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb
View file @
4220db7f
...
...
@@ -12,19 +12,7 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator do
before
do
stub_const
(
"
#{
described_class
}
::TOP_LEVEL_DIR"
,
temp_dir
)
# Stub Prometheus requests from Gitlab::Utils::UsageData
stub_request
(
:get
,
'https://::1:9090/-/ready'
)
.
to_return
(
status:
200
,
body:
[{}].
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
)
stub_request
(
:get
,
%r{^https://::1:9090/api/v1/query
\?
query=.*}
)
.
to_return
(
status:
200
,
body:
[{}].
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
)
stub_prometheus_queries
end
after
do
...
...
spec/support/helpers/usage_data_helpers.rb
View file @
4220db7f
...
...
@@ -174,6 +174,22 @@ module UsageDataHelpers
allow
(
Gitlab
::
Prometheus
::
Internal
).
to
receive
(
:prometheus_enabled?
).
and_return
(
false
)
end
def
stub_prometheus_queries
stub_request
(
:get
,
%r{^https?://::1:9090/-/ready}
)
.
to_return
(
status:
200
,
body:
[{}].
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
)
stub_request
(
:get
,
%r{^https?://::1:9090/api/v1/query
\?
query=.*}
)
.
to_return
(
status:
200
,
body:
[{}].
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
)
end
def
clear_memoized_values
(
values
)
values
.
each
{
|
v
|
described_class
.
clear_memoization
(
v
)
}
end
...
...
spec/tasks/gitlab/usage_data_rake_spec.rb
View file @
4220db7f
...
...
@@ -3,22 +3,12 @@
require
'rake_helper'
RSpec
.
describe
'gitlab:usage data take tasks'
do
include
UsageDataHelpers
before
do
Rake
.
application
.
rake_require
'tasks/gitlab/usage_data'
# stub prometheus external http calls https://gitlab.com/gitlab-org/gitlab/-/issues/245277
stub_request
(
:get
,
%r{^http[s]?://::1:9090/-/ready}
)
.
to_return
(
status:
200
,
body:
[{}].
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
)
stub_request
(
:get
,
%r{^http[s]?://::1:9090/api/v1/query
\?
query=.*}
)
.
to_return
(
status:
200
,
body:
[{}].
to_json
,
headers:
{
'Content-Type'
=>
'application/json'
}
)
stub_prometheus_queries
end
describe
'dump_sql_in_yaml'
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