Commit a22bc367 authored by Max Woolf's avatar Max Woolf

Merge branch 'psk-make-usage-data-queries-deterministic' into 'master'

Change metric SQL queries calls to be deterministic

See merge request gitlab-org/gitlab!84332
parents abc0d02c c79e8418
......@@ -23,4 +23,24 @@ RSpec.describe Gitlab::Usage::ServicePingReport, :use_clean_rails_memory_store_c
expect { described_class.for(output: :all_metrics_values) }.not_to raise_error
end
end
context 'for output: :metrics_queries' do
before do
stub_usage_data_connections
stub_object_store_settings
stub_prometheus_queries
end
it 'returns queries that do not change between calls' do
report = Timecop.freeze(2021, 1, 1) do
described_class.for(output: :metrics_queries)
end
other_report = Timecop.freeze(2021, 1, 1) do
described_class.for(output: :metrics_queries)
end
expect(report).to eq(other_report)
end
end
end
......@@ -50,7 +50,7 @@ module Gitlab
def alt_usage_data(value = nil, fallback: FALLBACK, &block)
if block_given?
{ alt_usage_data_block: block.to_s }
{ alt_usage_data_block: "non-SQL usage data block" }
else
{ alt_usage_data_value: value }
end
......@@ -58,9 +58,9 @@ module Gitlab
def redis_usage_data(counter = nil, &block)
if block_given?
{ redis_usage_data_block: block.to_s }
{ redis_usage_data_block: "non-SQL usage data block" }
elsif counter.present?
{ redis_usage_data_counter: counter }
{ redis_usage_data_counter: counter.to_s }
end
end
......@@ -74,6 +74,13 @@ module Gitlab
def epics_deepest_relationship_level
{ epics_deepest_relationship_level: 0 }
end
def topology_usage_data
{
duration_s: 0,
failures: []
}
end
end
end
end
......@@ -34,14 +34,14 @@ RSpec.describe Gitlab::UsageDataQueries do
describe '.redis_usage_data' do
subject(:redis_usage_data) { described_class.redis_usage_data { 42 } }
it 'returns a class for redis_usage_data with a counter call' do
it 'returns a stringified class for redis_usage_data with a counter call' do
expect(described_class.redis_usage_data(Gitlab::UsageDataCounters::WikiPageCounter))
.to eq(redis_usage_data_counter: Gitlab::UsageDataCounters::WikiPageCounter)
.to eq(redis_usage_data_counter: "Gitlab::UsageDataCounters::WikiPageCounter")
end
it 'returns a stringified block for redis_usage_data with a block' do
it 'returns a placeholder string for redis_usage_data with a block' do
is_expected.to include(:redis_usage_data_block)
expect(redis_usage_data[:redis_usage_data_block]).to start_with('#<Proc:')
expect(redis_usage_data[:redis_usage_data_block]).to eq('non-SQL usage data block')
end
end
......@@ -53,8 +53,8 @@ RSpec.describe Gitlab::UsageDataQueries do
.to eq(alt_usage_data_value: 1)
end
it 'returns a stringified block for alt_usage_data with a block' do
expect(alt_usage_data[:alt_usage_data_block]).to start_with('#<Proc:')
it 'returns a placeholder string for alt_usage_data with a block' do
expect(alt_usage_data[:alt_usage_data_block]).to eq('non-SQL usage data block')
end
end
......
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