Skip to content

Commit

Permalink
Fix app crash events for apps using rolling deployments
Browse files Browse the repository at this point in the history
- The internal app crash event endpoint assumed that the web process
  guid == app guid (legacy behavior from the v2->v3 data model migrations)
- Rolling deployments create new web processes that have different guids
  which made it so this endpoint no longer created events associated with
  the parent app
- This change updates the endpoint to make app crash events for the app
  guid instead of the process guid which should resolve the rolling
  deployment issue and support crash events for non-web process types

Fixes #2587
  • Loading branch information
tcdowney committed May 14, 2024
1 parent 858245d commit a90ad04
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 6 additions & 6 deletions app/controllers/internal/app_crashed_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ class AppCrashedController < RestController::BaseController
allow_unauthenticated_access

post '/internal/v4/apps/:process_guid/crashed', :crashed
def crashed(process_guid)
def crashed(lrp_process_guid)
crash_payload = crashed_request

app_guid = Diego::ProcessGuid.cc_process_guid(process_guid)
cc_process_guid = Diego::ProcessGuid.cc_process_guid(lrp_process_guid)

process = ProcessModel.find(guid: app_guid)
raise CloudController::Errors::NotFound.new_from_details('ProcessNotFound', app_guid) unless process
process = ProcessModel.find(guid: cc_process_guid)
raise CloudController::Errors::NotFound.new_from_details('ProcessNotFound', cc_process_guid) unless process

crash_payload['version'] = Diego::ProcessGuid.cc_process_version(process_guid)
crash_payload['version'] = Diego::ProcessGuid.cc_process_version(lrp_process_guid)

Repositories::ProcessEventRepository.record_crash(process, crash_payload)
Repositories::AppEventRepository.new.create_app_crash_event(process, crash_payload)
Repositories::AppEventRepository.new.create_app_crash_event(process.app, crash_payload)

[200, '{}']
end
Expand Down
15 changes: 8 additions & 7 deletions spec/unit/controllers/internal/app_crashed_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
module VCAP::CloudController
RSpec.describe AppCrashedController do
describe 'POST /internal/v4/apps/:process_guid/crashed' do
let(:diego_process) { ProcessModelFactory.make(state: 'STARTED', diego: true) }
let(:diego_process) { ProcessModelFactory.make(state: 'STARTED', diego: true, type: 'rolled-web') }
let(:app_model) { diego_process.app }
let(:process_guid) { Diego::ProcessGuid.from(diego_process.guid, 'some-version-guid') }
let(:url) { "/internal/v4/apps/#{process_guid}/crashed" }

Expand Down Expand Up @@ -35,13 +36,13 @@ module VCAP::CloudController
expect(last_response.status).to eq(200)
expect(last_response.body).to eq '{}'

app_event = Event.find(actee: diego_process.guid, actor_type: 'app')
app_event = Event.find(actee: app_model.guid, actor_type: 'app')

expect(app_event).to be
expect(app_event.space).to eq(diego_process.space)
expect(app_event.space).to eq(app_model.space)
expect(app_event.type).to eq('app.crash')
expect(app_event.actor_type).to eq('app')
expect(app_event.actor).to eq(diego_process.guid)
expect(app_event.actor).to eq(app_model.guid)
expect(app_event.metadata['instance']).to eq(crashed_request['instance'])
expect(app_event.metadata['index']).to eq(crashed_request['index'])
expect(app_event.metadata['exit_status']).to eq(crashed_request['exit_status'])
Expand All @@ -54,15 +55,15 @@ module VCAP::CloudController
expect(last_response.status).to eq(200)
expect(last_response.body).to eq '{}'

app_event = Event.find(actee: diego_process.guid, actor_type: 'process')
app_event = Event.find(actee: app_model.guid, actor_type: 'process')

expect(app_event).to be
expect(app_event.space).to eq(diego_process.space)
expect(app_event.space).to eq(app_model.space)
expect(app_event.type).to eq('audit.app.process.crash')
expect(app_event.actor_type).to eq('process')
expect(app_event.actor).to eq(diego_process.guid)
expect(app_event.actee_type).to eq('app')
expect(app_event.actee).to eq(diego_process.app.guid)
expect(app_event.actee).to eq(app_model.guid)
expect(app_event.metadata['instance']).to eq(crashed_request['instance'])
expect(app_event.metadata['index']).to eq(crashed_request['index'])
expect(app_event.metadata['exit_status']).to eq(crashed_request['exit_status'])
Expand Down

0 comments on commit a90ad04

Please sign in to comment.