Commit fcd30cb5 authored by Alper Akgun's avatar Alper Akgun

Merge branch '300555-refactor-stubbing-prometheus-calls' into 'master'

Refactor stubbing Prometheus calls into a spec helper

See merge request gitlab-org/gitlab!59170
parents f5fa1cef 4220db7f
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'generator_helper' require 'generator_helper'
RSpec.describe Gitlab::UsageMetricDefinition::RedisHllGenerator do RSpec.describe Gitlab::UsageMetricDefinition::RedisHllGenerator do
include UsageDataHelpers
let(:category) { 'test_category' } let(:category) { 'test_category' }
let(:event) { 'i_test_event' } let(:event) { 'i_test_event' }
let(:args) { [category, event] } let(:args) { [category, event] }
...@@ -13,19 +15,7 @@ RSpec.describe Gitlab::UsageMetricDefinition::RedisHllGenerator do ...@@ -13,19 +15,7 @@ RSpec.describe Gitlab::UsageMetricDefinition::RedisHllGenerator do
before do before do
stub_const("#{Gitlab::UsageMetricDefinitionGenerator}::TOP_LEVEL_DIR", temp_dir) stub_const("#{Gitlab::UsageMetricDefinitionGenerator}::TOP_LEVEL_DIR", temp_dir)
# Stub Prometheus requests from Gitlab::Utils::UsageData # Stub Prometheus requests from Gitlab::Utils::UsageData
stub_request(:get, %r{^https?://::1:9090/-/ready}) stub_prometheus_queries
.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 end
it 'creates metric definition files' do it 'creates metric definition files' do
......
...@@ -12,19 +12,7 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator do ...@@ -12,19 +12,7 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator do
before do before do
stub_const("#{described_class}::TOP_LEVEL_DIR", temp_dir) stub_const("#{described_class}::TOP_LEVEL_DIR", temp_dir)
# Stub Prometheus requests from Gitlab::Utils::UsageData # Stub Prometheus requests from Gitlab::Utils::UsageData
stub_request(:get, 'https://::1:9090/-/ready') stub_prometheus_queries
.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 end
after do after do
......
...@@ -174,6 +174,22 @@ module UsageDataHelpers ...@@ -174,6 +174,22 @@ module UsageDataHelpers
allow(Gitlab::Prometheus::Internal).to receive(:prometheus_enabled?).and_return(false) allow(Gitlab::Prometheus::Internal).to receive(:prometheus_enabled?).and_return(false)
end 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) def clear_memoized_values(values)
values.each { |v| described_class.clear_memoization(v) } values.each { |v| described_class.clear_memoization(v) }
end end
......
...@@ -3,22 +3,12 @@ ...@@ -3,22 +3,12 @@
require 'rake_helper' require 'rake_helper'
RSpec.describe 'gitlab:usage data take tasks' do RSpec.describe 'gitlab:usage data take tasks' do
include UsageDataHelpers
before do before do
Rake.application.rake_require 'tasks/gitlab/usage_data' Rake.application.rake_require 'tasks/gitlab/usage_data'
# stub prometheus external http calls https://gitlab.com/gitlab-org/gitlab/-/issues/245277 # stub prometheus external http calls https://gitlab.com/gitlab-org/gitlab/-/issues/245277
stub_request(:get, %r{^http[s]?://::1:9090/-/ready}) stub_prometheus_queries
.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' }
)
end end
describe 'dump_sql_in_yaml' do describe 'dump_sql_in_yaml' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment