Skip to content

Commit c8383eb

Browse files
committed
fix request log retention on std tiers
1 parent 6919dbf commit c8383eb

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

app/workers/prune_event_logs_worker.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ def dedup_hi_vol_event_logs_for_date(account, date:)
136136
sum += count
137137
batch += 1
138138

139-
Keygen.logger.info "[workers.prune-event-logs] Deduped #{count} rows: account_id=#{account.id} date=#{date} batch=#{batch}/#{batches} progress=#{sum}/#{total}"
139+
Keygen.logger.info "[workers.prune-event-logs] Deduped #{count} rows: account_id=#{account.id} date=#{date} batch=#{batch}/#{batches} count=#{sum}/#{total}"
140140

141141
sleep BATCH_WAIT
142142

143143
break if count < BATCH_SIZE
144144
end
145145

146-
Keygen.logger.info "[workers.prune-event-logs] Deduping done: account_id=#{account.id} date=#{date} progress=#{sum}/#{total}"
146+
Keygen.logger.info "[workers.prune-event-logs] Deduping done: account_id=#{account.id} date=#{date} count=#{sum}/#{total}"
147147
end
148148

149149
def prune_event_logs_for_date(account, date:)

app/workers/prune_request_logs_worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def within_retention_period?(account, date:)
9292
plan = account.plan
9393

9494
return false unless
95-
plan.present? && plan.ent? && plan.request_log_retention_duration?
95+
plan.present? && plan.request_log_retention_duration?
9696

9797
cutoff_date = plan.request_log_retention_duration.seconds
9898
.ago

spec/workers/prune_request_logs_worker_spec.rb

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,36 @@
2222
)
2323
end
2424

25+
context 'without a request log retention policy' do
26+
let(:account) { create(:account, plan: build(:plan, :ent, request_log_retention_duration: nil)) }
27+
28+
it 'should prune backlog' do
29+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 91).days.ago)
30+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 90).days.ago)
31+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 31).days.ago)
32+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 30).days.ago)
33+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 1).days.ago)
34+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS - 1).days.ago)
35+
36+
expect { worker.perform_async }.to(
37+
change { account.request_logs.count }.from(300).to(50),
38+
)
39+
end
40+
end
41+
2542
context 'with a request log retention policy' do
26-
let(:account) { create(:account, plan: build(:plan, :ent, request_log_retention_duration: (worker::BACKLOG_DAYS + 30).days)) }
43+
let(:account) { create(:account, plan: build(:plan, :ent, request_log_retention_duration: (worker::BACKLOG_DAYS + 90).days)) }
2744

2845
it 'should prune according to retention policy' do
46+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 91).days.ago)
47+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 90).days.ago)
2948
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 31).days.ago)
30-
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 29).days.ago)
49+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 30).days.ago)
3150
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 1).days.ago)
3251
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS - 1).days.ago)
3352

3453
expect { worker.perform_async }.to(
35-
change { account.request_logs.count }.from(200).to(150),
54+
change { account.request_logs.count }.from(300).to(250),
3655
)
3756
end
3857
end
@@ -51,17 +70,36 @@
5170
)
5271
end
5372

73+
context 'without a request log retention policy' do
74+
let(:account) { create(:account, plan: build(:plan, :std, request_log_retention_duration: nil)) }
75+
76+
it 'should prune backlog' do
77+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 91).days.ago)
78+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 90).days.ago)
79+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 31).days.ago)
80+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 29).days.ago)
81+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 1).days.ago)
82+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS - 1).days.ago)
83+
84+
expect { worker.perform_async }.to(
85+
change { account.request_logs.count }.from(300).to(50),
86+
)
87+
end
88+
end
89+
5490
context 'with a request log retention policy' do
55-
let(:account) { create(:account, plan: build(:plan, :std, request_log_retention_duration: (worker::BACKLOG_DAYS + 3).days)) }
91+
let(:account) { create(:account, plan: build(:plan, :std, request_log_retention_duration: (worker::BACKLOG_DAYS + 30).days)) }
5692

5793
it 'should prune according to retention policy' do
58-
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 4).days.ago)
59-
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 3).days.ago)
94+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 91).days.ago)
95+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 90).days.ago)
96+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 31).days.ago)
97+
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 29).days.ago)
6098
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 1).days.ago)
6199
create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS - 1).days.ago)
62100

63101
expect { worker.perform_async }.to(
64-
change { account.request_logs.count }.from(200).to(50),
102+
change { account.request_logs.count }.from(300).to(150),
65103
)
66104
end
67105
end

0 commit comments

Comments
 (0)