|
16 | 16 | }
|
17 | 17 |
|
18 | 18 | before(:example) do
|
| 19 | + ## |
| 20 | + # redis mock |
19 | 21 | allow(redis).to receive(:connection) { {host: 'master.replicationgroup.abcde.use2.cache.amazonaws.com' } }
|
20 | 22 | allow(redis).to receive(:slowlog).with('get') {
|
21 | 23 | [
|
22 | 24 | [
|
23 | 25 | 1,
|
24 |
| - Time.new(2020,04,20,04,21,15).to_i, |
| 26 | + Time.new(2020,04,20,04,19,45).to_i, |
25 | 27 | 100000,
|
26 | 28 | [
|
27 | 29 | "eval",
|
|
33 | 35 | ],
|
34 | 36 | [
|
35 | 37 | 0,
|
36 |
| - Time.new(2020,04,20,04,21,13).to_i, |
| 38 | + Time.new(2020,04,20,04,19,15).to_i, |
37 | 39 | 200000,
|
38 | 40 | [
|
39 | 41 | "eval",
|
|
46 | 48 | ]
|
47 | 49 | }
|
48 | 50 |
|
| 51 | + ## |
| 52 | + # ddog mock |
49 | 53 | allow(ddog).to receive(:get_points).with(
|
50 | 54 | 'rspec.redis.slowlog.micros.95percentile{replication_group:replicationgroup}',
|
51 | 55 | Time.now - 86400,
|
|
68 | 72 | "length"=>3,
|
69 | 73 | "query_index"=>0,
|
70 | 74 | "aggr"=>nil,
|
71 |
| - "scope"=>"replication_group:infraeng-dev-redis", |
72 |
| - "pointlist"=>[[1587602100000.0, 99848.0], [1587603600000.0, 99994.0], [1587684300000.0, 99378.0]], |
| 75 | + "scope"=>"replication_group:replicationgroup", |
| 76 | + "pointlist"=>[[1587381405000.0, 99994.0], [1587381404000.0, 99378.0]], |
73 | 77 | "expression"=>"rspec.redis.slowlog.micros.95percentile{replication_group:infraeng-dev-redis}",
|
74 | 78 | "unit"=>nil,
|
75 | 79 | "display_name"=>"rspec.redis.slowlog.micros.95percentile"
|
|
83 | 87 | ]
|
84 | 88 | }
|
85 | 89 |
|
86 |
| - |
| 90 | + # Freeze time |
87 | 91 | Timecop.freeze(2020, 04, 20, 04, 20, 45)
|
88 | 92 |
|
| 93 | + # Shhh... |
89 | 94 | allow_any_instance_of(Logger).to receive(:info) {}
|
90 | 95 |
|
91 |
| - allow(slowlog_check).to receive(:last_time_submitted).and_return(slowlog_check.minute_precision(Time.now) - 240) |
92 | 96 | end
|
93 | 97 |
|
94 | 98 |
|
|
107 | 111 | end
|
108 | 112 | end
|
109 | 113 |
|
| 114 | + describe '#status_or_error' do |
| 115 | + context 'ok' do |
| 116 | + subject { slowlog_check.status_or_error(["200", {"status" => "ok"}]) } |
| 117 | + it { is_expected.to eq('ok') } |
| 118 | + end |
| 119 | + |
| 120 | + context 'error' do |
| 121 | + subject { slowlog_check.status_or_error(["404", {"errors" => ["error"]}]) } |
| 122 | + it { is_expected.to eq(['error']) } |
| 123 | + end |
| 124 | + |
| 125 | + context 'otherwise' do |
| 126 | + subject { slowlog_check.status_or_error(["404", {"somenewthing" => ["error"]}]) } |
| 127 | + it { is_expected.to eq(["404", {"somenewthing" => ['error']}]) } |
| 128 | + end |
| 129 | + |
| 130 | + end |
| 131 | + |
110 | 132 | describe '#last_datadog_metric' do
|
111 | 133 | subject { slowlog_check.last_datadog_metric}
|
112 | 134 |
|
|
118 | 140 | end
|
119 | 141 |
|
120 | 142 | context 'nth time' do
|
121 |
| - it { is_expected.to eq(Time.at(1587684300)) } |
| 143 | + it { is_expected.to eq(Time.new(2020,4,20,4,16)) } |
122 | 144 | end
|
123 | 145 | end
|
124 | 146 |
|
|
147 | 169 | end
|
148 | 170 |
|
149 | 171 | describe '#add_metric_to_bucket' do
|
| 172 | + subject { slowlog_check.add_metric_to_bucket(prior, new) } |
150 | 173 | let(:prior) {
|
151 | 174 | {
|
152 | 175 | values: [10],
|
|
172 | 195 | sum: 30
|
173 | 196 | }
|
174 | 197 | }
|
175 |
| - subject { slowlog_check.add_metric_to_bucket(prior, new) } |
176 | 198 | it { is_expected.to eq(result) }
|
177 | 199 | end
|
178 | 200 |
|
179 | 201 | describe '#slowlogs_by_flush_interval' do
|
180 | 202 | subject { slowlog_check.slowlogs_by_flush_interval }
|
181 |
| - |
182 | 203 | let(:bucket) {
|
183 | 204 | {
|
184 | 205 | "eval" =>
|
|
198 | 219 | {
|
199 | 220 | Time.new(2020,04,20,04,17) => nil,
|
200 | 221 | Time.new(2020,04,20,04,18) => nil,
|
201 |
| - Time.new(2020,04,20,04,19) => nil, |
202 |
| - Time.new(2020,04,20,04,20) => nil, |
203 |
| - Time.new(2020,04,20,04,21) => bucket |
| 222 | + Time.new(2020,04,20,04,19) => bucket, |
| 223 | + Time.new(2020,04,20,04,20) => nil |
204 | 224 | }
|
205 | 225 | )
|
206 | 226 | }
|
|
223 | 243 | describe '#ship_slowlogs' do
|
224 | 244 | subject { slowlog_check.ship_slowlogs }
|
225 | 245 | let(:tags) { slowlog_check.default_tags.merge(command: 'eval') }
|
226 |
| - |
227 | 246 | it 'sends the right data to datadog' do
|
228 | 247 | allow(ddog).to receive(:emit_points) {["200", { "status" => "ok" }]}
|
229 | 248 | subject
|
230 | 249 |
|
231 | 250 | expect(ddog).to have_received(:emit_points).with(
|
232 | 251 | "rspec.redis.slowlog.micros.avg",
|
233 |
| - [[Time.new(2020,04,20,04,21), 150000]], |
| 252 | + [[Time.new(2020,04,20,04,19), 150000]], |
234 | 253 | {
|
235 | 254 | :host=>"replicationgroup",
|
236 | 255 | :interval=>60,
|
|
269 | 288 |
|
270 | 289 | describe '#diff_metadatas' do
|
271 | 290 | subject { slowlog_check.diff_metadatas }
|
272 |
| - |
273 | 291 | let(:diff) {
|
274 | 292 | {
|
275 | 293 | "name"=>"rspec.redis.slowlog.micros.count",
|
|
282 | 300 | "unit"=>"entries"
|
283 | 301 | }
|
284 | 302 | }
|
285 |
| - |
286 | 303 | it { is_expected.to contain_exactly(diff) }
|
287 | 304 | end
|
288 | 305 |
|
|
307 | 324 | 'rspec.redis.slowlog.micros.count',
|
308 | 325 | diff
|
309 | 326 | )
|
310 |
| - |
311 | 327 | end
|
312 | 328 | end
|
313 | 329 | end
|
314 |
| - |
315 |
| - describe '#status_or_error' do |
316 |
| - context 'ok' do |
317 |
| - subject { slowlog_check.status_or_error(["200", {"status" => "ok"}]) } |
318 |
| - |
319 |
| - it { is_expected.to eq('ok') } |
320 |
| - |
321 |
| - end |
322 |
| - |
323 |
| - context 'error' do |
324 |
| - subject { slowlog_check.status_or_error(["404", {"errors" => ["error"]}]) } |
325 |
| - |
326 |
| - it { is_expected.to eq(['error']) } |
327 |
| - end |
328 |
| - |
329 |
| - context 'otherwise' do |
330 |
| - subject { slowlog_check.status_or_error(["404", {"somenewthing" => ["error"]}]) } |
331 |
| - |
332 |
| - it { is_expected.to eq(["404", {"somenewthing" => ['error']}]) } |
333 |
| - end |
334 |
| - |
335 |
| - end |
336 | 330 | end
|
0 commit comments