Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix app crash events for apps using rolling deployments #3790

Merged
merged 1 commit into from
May 15, 2024
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
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