Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/jobs/replay_ingest_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def perform(replay_id, raw_events_json)
checksum = Digest::SHA256.hexdigest(compressed)
key = replay.storage_path

if ReplayStorage::BUCKET.present?
if ReplayStorage::BUCKET.present? || Rails.env.test?
result = ReplayStorage.client.upload(key: key, data: compressed)
success = result[:success]
storage_key = result[:key]
Expand Down
6 changes: 6 additions & 0 deletions app/jobs/usage_snapshot_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def update_account_usage(account)
.where(occurred_at: start_at..end_at)
.count

# Count replay sessions in billing period
replays_count = Replay.where(account_id: account.id)
.where(created_at: start_at..end_at)
.count

# Count projects (current count)
projects_count = Project.where(account_id: account.id).count

Expand All @@ -82,6 +87,7 @@ def update_account_usage(account)
cached_uptime_monitors_used: uptime_monitors_count,
cached_status_pages_used: status_pages_count,
cached_log_entries_used: log_entries_count,
cached_replays_used: replays_count,
cached_projects_used: projects_count,
usage_cached_at: Time.current
)
Expand Down
16 changes: 8 additions & 8 deletions db/seeds/logs_localhost.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
{ level: 4, source: "Stripe::WebhookHandler", message: "Webhook signature verification failed for event evt_1N...", environment: "production" },
{ level: 3, source: "S3Storage", message: "Upload retry #2 for attachment 8f2a — SlowDown response from S3", environment: "production" },
{ level: 2, source: "HealthCheck", message: "All checks passing: db=ok redis=ok sidekiq=ok", environment: "production" },
{ level: 4, source: "ActionController", message: "Timeout::Error: execution expired after 30s in ReportsController#generate", environment: "production" },
{ level: 4, source: "ActionController", message: "Timeout::Error: execution expired after 30s in ReportsController#generate", environment: "production" }
]

# Generate ~200 log entries spread over the last 24 hours
Expand All @@ -84,13 +84,13 @@

scenarios.each do |scenario|
count = case scenario[:level]
when 0 then rand(2..4) # trace: few
when 1 then rand(4..8) # debug: moderate
when 2 then rand(5..12) # info: most common
when 3 then rand(3..6) # warn: some
when 4 then rand(2..5) # error: fewer
when 5 then rand(1..2) # fatal: rare
end
when 0 then rand(2..4) # trace: few
when 1 then rand(4..8) # debug: moderate
when 2 then rand(5..12) # info: most common
when 3 then rand(3..6) # warn: some
when 4 then rand(2..5) # error: fewer
when 5 then rand(1..2) # fatal: rare
end

count.times do
occurred = rand(24.hours).seconds.ago
Expand Down
3 changes: 3 additions & 0 deletions test/integration/check_ins_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class CheckInsControllerTest < ActionDispatch::IntegrationTest
end

test "POST create check-in" do
# Ensure this test is not blocked by shared monitor quota fixtures.
@account.update!(addon_uptime_monitors: 10)

assert_difference -> { CheckIn.count }, 1 do
post check_ins_path, params: {
check_in: {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/checkouts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CheckoutsControllerTest < ActionDispatch::IntegrationTest
}) do
post checkouts_path, params: { plan: "starter" }

assert_redirected_to settings_path
assert_redirected_to plan_path
assert flash[:alert].present?
end
end
Expand Down
7 changes: 4 additions & 3 deletions test/integration/pricing_addons_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class PricingAddonsTest < ActionDispatch::IntegrationTest

test "plan cards include uptime monitors" do
get plan_path
assert_match(/3 uptime monitors/, response.body) # Team
assert_match(/5 uptime monitors/, response.body) # Business
assert_match(/monitors \(uptime \+ cron\)/, response.body) # Team card copy
assert_match(/5 monitors \(uptime \+ cron\)/, response.body) # Business
end

test "plan cards include session replays" do
Expand All @@ -145,7 +145,8 @@ class PricingAddonsTest < ActionDispatch::IntegrationTest

test "subscribe button exists" do
get plan_path
assert_select "button[type='submit']", text: "Subscribe"
assert_select "[data-addons-target='submitButton']", 1
assert_select "[data-addons-target='submitButton']", /Subscribe|Update Plan/
end

# ===========================================================================
Expand Down
36 changes: 36 additions & 0 deletions test/jobs/usage_snapshot_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,41 @@ class UsageSnapshotJobTest < ActiveSupport::TestCase
assert @account.cached_performance_events_used >= 1
end

test "counts replay sessions in billing period" do
period_start = @account.event_usage_period_start
period_end = @account.event_usage_period_end
baseline_count = Replay.where(account_id: @account.id)
.where(created_at: period_start..period_end)
.count

Replay.create!(
account: @account,
project: @project,
replay_id: SecureRandom.uuid,
session_id: SecureRandom.uuid,
started_at: Time.current,
duration_ms: 1200,
status: "pending",
created_at: Time.current
)

Replay.create!(
account: @account,
project: @project,
replay_id: SecureRandom.uuid,
session_id: SecureRandom.uuid,
started_at: 45.days.ago,
duration_ms: 800,
status: "expired",
created_at: 45.days.ago
)

UsageSnapshotJob.new.perform

@account.reload
assert_equal baseline_count + 1, @account.cached_replays_used
end

test "sets cached values to 0 with no data" do
# Use an account with no associated data (trial_account has no events/projects)
empty_account = accounts(:trial_account)
Expand All @@ -82,6 +117,7 @@ class UsageSnapshotJobTest < ActiveSupport::TestCase
assert_equal 0, empty_account.cached_pull_requests_used
assert_equal 0, empty_account.cached_uptime_monitors_used
assert_equal 0, empty_account.cached_status_pages_used
assert_equal 0, empty_account.cached_replays_used
end

test "defaults to current month when billing period not set" do
Expand Down
Loading