Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 263d771

Browse files
joyvuu-davedpb587-pivotal
authored andcommitted
Create consistent AppUsageEvent records
When a user makes a POST to /v2/app_usage_events/destructively_purge_all_and_reseed_started_apps, all existing AppUsageEvent records are purged from the database and new AppUsageEvent records are created for any running processes. This action is taken by clients who may have missed previous events that have now been pruned from the database as part of routeine mainteance and now need a new starting spot for tracking usage. All AppUsageEvent records created outside of a purge and reseed action will have their parent_app_name and parent_app_guid fields set. This change makes AppUsageEvent recoreds created as a result of a purge consistent with all other records in that respect. Not having the parent_app_name and parent_app_guid fields set was causing 3rd party usage monitoring systems that expected their presence to break. Authored-by: Dave Riddle <driddle@pivotal.io>
1 parent 9d48077 commit 263d771

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

app/repositories/app_usage_event_repository.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def purge_and_reseed_started_apps!
110110
space_name: "#{Space.table_name}__name".to_sym,
111111
org_guid: "#{Organization.table_name}__guid".to_sym,
112112
created_at: Sequel.datetime_class.now,
113+
parent_app_name: :parent_app__name,
114+
parent_app_guid: :parent_app__guid,
113115
}
114116

115117
latest_package_query = PackageModel.select(:app_guid).select_append { max(id).as(:id) }.group(:app_guid)

spec/unit/repositories/app_usage_event_repository_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,13 @@ module Repositories
546546
expect(AppUsageEvent.last).to match_app(process)
547547
end
548548

549+
it 'sets the parent_app_name and parent_app_guid' do
550+
repository.purge_and_reseed_started_apps!
551+
552+
expect(AppUsageEvent.last.parent_app_name).to eq(process.app.name)
553+
expect(AppUsageEvent.last.parent_app_guid).to eq(process.app.guid)
554+
end
555+
549556
context 'with associated buildpack information' do
550557
before do
551558
process.desired_droplet.update(

0 commit comments

Comments
 (0)