2019-07-09 10:07:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-07-17 15:33:49 -04:00
|
|
|
describe Peek::Views::RedisDetailed, :request_store do
|
|
|
|
subject { described_class.new }
|
2019-07-09 10:07:41 -04:00
|
|
|
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:cmd, :expected) do
|
|
|
|
[:auth, 'test'] | 'auth <redacted>'
|
|
|
|
[:set, 'key', 'value'] | 'set key <redacted>'
|
|
|
|
[:set, 'bad'] | 'set bad'
|
|
|
|
[:hmset, 'key1', 'value1', 'key2', 'value2'] | 'hmset key1 <redacted>'
|
|
|
|
[:get, 'key'] | 'get key'
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
2019-07-17 15:33:49 -04:00
|
|
|
it 'scrubs Redis commands' do
|
2020-06-04 08:08:21 -04:00
|
|
|
Gitlab::Instrumentation::Redis::SharedState.detail_store << { cmd: cmd, duration: 1.second }
|
2019-07-09 10:07:41 -04:00
|
|
|
|
2019-07-17 15:33:49 -04:00
|
|
|
expect(subject.results[:details].count).to eq(1)
|
|
|
|
expect(subject.results[:details].first)
|
2019-08-06 11:04:43 -04:00
|
|
|
.to include({
|
|
|
|
cmd: expected,
|
|
|
|
duration: 1000
|
|
|
|
})
|
2019-07-09 10:07:41 -04:00
|
|
|
end
|
|
|
|
end
|
2019-07-17 15:33:49 -04:00
|
|
|
|
|
|
|
it 'returns aggregated results' do
|
2020-06-04 08:08:21 -04:00
|
|
|
Gitlab::Instrumentation::Redis::Cache.detail_store << { cmd: [:get, 'test'], duration: 0.001 }
|
|
|
|
Gitlab::Instrumentation::Redis::Cache.detail_store << { cmd: [:get, 'test'], duration: 1.second }
|
|
|
|
Gitlab::Instrumentation::Redis::SharedState.detail_store << { cmd: [:get, 'test'], duration: 1.second }
|
2019-07-17 15:33:49 -04:00
|
|
|
|
2020-06-04 08:08:21 -04:00
|
|
|
expect(subject.results[:calls]).to eq(3)
|
|
|
|
expect(subject.results[:duration]).to eq('2001.00ms')
|
|
|
|
expect(subject.results[:details].count).to eq(3)
|
2019-07-17 15:33:49 -04:00
|
|
|
end
|
2019-07-09 10:07:41 -04:00
|
|
|
end
|