2020-06-23 00:09:42 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Instrumentation::Redis do
|
2020-06-23 00:09:42 +05:30
|
|
|
def stub_storages(method, value)
|
|
|
|
described_class::STORAGES.each do |storage|
|
|
|
|
allow(storage).to receive(method) { value }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'aggregation of redis storage data' do |method|
|
|
|
|
describe "#{method} sum" do
|
|
|
|
it "sums data from all Redis storages" do
|
|
|
|
amount = 0.3
|
|
|
|
|
|
|
|
stub_storages(method, amount)
|
|
|
|
|
|
|
|
expect(described_class.public_send(method)).to eq(described_class::STORAGES.size * amount)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'aggregation of redis storage data', :get_request_count
|
|
|
|
it_behaves_like 'aggregation of redis storage data', :query_time
|
|
|
|
it_behaves_like 'aggregation of redis storage data', :read_bytes
|
|
|
|
it_behaves_like 'aggregation of redis storage data', :write_bytes
|
|
|
|
|
|
|
|
describe '.payload', :request_store do
|
|
|
|
before do
|
2021-11-11 11:23:49 +05:30
|
|
|
# If this is the first spec in a spec run that uses Redis, there
|
|
|
|
# will be an extra SELECT command to choose the right database. We
|
|
|
|
# don't want to make the spec less precise, so we force that to
|
|
|
|
# happen (if needed) first, then clear the counts.
|
|
|
|
Gitlab::Redis::Cache.with { |redis| redis.info }
|
|
|
|
RequestStore.clear!
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
Gitlab::Redis::Cache.with { |redis| redis.set('cache-test', 321) }
|
|
|
|
Gitlab::Redis::SharedState.with { |redis| redis.set('shared-state-test', 123) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns payload filtering out zeroed values' do
|
|
|
|
expected_payload = {
|
|
|
|
# Aggregated results
|
|
|
|
redis_calls: 2,
|
|
|
|
redis_duration_s: be >= 0,
|
|
|
|
redis_read_bytes: be >= 0,
|
|
|
|
redis_write_bytes: be >= 0,
|
|
|
|
|
|
|
|
# Cache results
|
|
|
|
redis_cache_calls: 1,
|
|
|
|
redis_cache_duration_s: be >= 0,
|
|
|
|
redis_cache_read_bytes: be >= 0,
|
|
|
|
redis_cache_write_bytes: be >= 0,
|
|
|
|
|
|
|
|
# Shared state results
|
|
|
|
redis_shared_state_calls: 1,
|
|
|
|
redis_shared_state_duration_s: be >= 0,
|
|
|
|
redis_shared_state_read_bytes: be >= 0,
|
|
|
|
redis_shared_state_write_bytes: be >= 0
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(described_class.payload).to include(expected_payload)
|
|
|
|
expect(described_class.payload.keys).to match_array(expected_payload.keys)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.detail_store' do
|
|
|
|
it 'returns a flat array of detail stores with the storage name added to each item' do
|
|
|
|
details_row = { cmd: 'GET foo', duration: 1 }
|
|
|
|
|
|
|
|
stub_storages(:detail_store, [details_row])
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expected_detail_stores = Gitlab::Redis::ALL_CLASSES.map(&:store_name)
|
|
|
|
.map { |store_name| details_row.merge(storage: store_name) }
|
|
|
|
expected_detail_stores << details_row.merge(storage: 'ActionCable')
|
|
|
|
expect(described_class.detail_store).to contain_exactly(*expected_detail_stores)
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|