Skip to content

Commit

Permalink
Add revision version to app logs (#3885)
Browse files Browse the repository at this point in the history
* Add new configuration to all job schemas that interact with diego.
* Even if the app has the revision feature disabled we still show the revision in
the logs if it has a revision associated with it.

Co-authored-by: Sam Gunaratne <[email protected]>
  • Loading branch information
sethboyles and Samze authored Jul 17, 2024
1 parent 0c49309 commit 44d70c0
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/cloud_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,5 @@ custom_metric_tag_prefix_list: ["metric.tag.cloudfoundry.org"]

max_manifest_service_binding_poll_duration_in_seconds: 60
update_metric_tags_on_rename: true

app_log_revision: true
4 changes: 3 additions & 1 deletion lib/cloud_controller/config_schemas/vms/api_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class ApiSchema < VCAP::Config
docker_staging_stack: String,
optional(:temporary_oci_buildpack_mode) => enum('oci-phase-1', NilClass),
enable_declarative_asset_downloads: bool
}
},

app_log_revision: bool
}
end

Expand Down
4 changes: 3 additions & 1 deletion lib/cloud_controller/config_schemas/vms/clock_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class ClockSchema < VCAP::Config
use_privileged_containers_for_staging: bool,
optional(:temporary_oci_buildpack_mode) => enum('oci-phase-1', NilClass),
enable_declarative_asset_downloads: bool
}
},

app_log_revision: bool
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class DeploymentUpdaterSchema < VCAP::Config
use_privileged_containers_for_staging: bool,
optional(:temporary_oci_buildpack_mode) => enum('oci-phase-1', NilClass),
enable_declarative_asset_downloads: bool
}
},

app_log_revision: bool
}
end

Expand Down
4 changes: 3 additions & 1 deletion lib/cloud_controller/config_schemas/vms/worker_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class WorkerSchema < VCAP::Config
use_privileged_containers_for_staging: bool,
optional(:temporary_oci_buildpack_mode) => enum('oci-phase-1', NilClass),
enable_declarative_asset_downloads: bool
}
},

app_log_revision: bool
}
end

Expand Down
10 changes: 9 additions & 1 deletion lib/cloud_controller/diego/main_lrp_action_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ def generate_app_action(start_command, user, environment_variables)
path: '/tmp/lifecycle/launcher',
args: launcher_args,
env: environment_variables,
log_source: "APP/PROC/#{process.type.upcase}",
log_source: app_log_source,
resource_limits: ::Diego::Bbs::Models::ResourceLimits.new(nofile: process.file_descriptors)
))
end

def app_log_source
if VCAP::CloudController::Config.config.get(:app_log_revision) && process.revision
"APP/REV/#{process.revision.version}/PROC/#{process.type.upcase}"
else
"APP/PROC/#{process.type.upcase}"
end
end

def allow_ssh?
process.enable_ssh
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,58 @@ module Diego
each { |env_vars| expect(env_vars).not_to include(an_object_satisfying { |var| var.name == 'VCAP_PLATFORM_OPTIONS' }) }
end

context 'revisions' do
let(:revision) { RevisionModel.make(app: app_model, version: 99) }

before do
process.revision = revision
end

context 'when the app_log_revision config is enabled' do
before do
TestConfig.config[:app_log_revision] = true
end

it 'shows the revision id in the log source' do
action = MainLRPActionBuilder.build(process, lrp_builder, ssh_key)
expect(action.codependent_action.actions.first.run_action.log_source).to eq('APP/REV/99/PROC/WEB')
end

context 'and the revision is not present' do
before do
process.update(revision: nil)
end

it 'does not show revision in the log source' do
action = MainLRPActionBuilder.build(process, lrp_builder, ssh_key)
expect(action.codependent_action.actions.first.run_action.log_source).to eq('APP/PROC/WEB')
end
end

context 'and when the app feature revisions is disabled' do
before do
app_model.update(revisions_enabled: false)
end

it 'still shows existing revisions in the log source' do
action = MainLRPActionBuilder.build(process, lrp_builder, ssh_key)
expect(action.codependent_action.actions.first.run_action.log_source).to eq('APP/REV/99/PROC/WEB')
end
end
end

context 'when the app_log_revision config is disabled' do
before do
TestConfig.config[:app_log_revision] = false
end

it 'does not show the revision in the log source' do
action = MainLRPActionBuilder.build(process, lrp_builder, ssh_key)
expect(action.codependent_action.actions.first.run_action.log_source).to eq('APP/PROC/WEB')
end
end
end

context 'sidecars' do
let(:sidecar_action_environment_variables) do
[::Diego::Bbs::Models::EnvironmentVariable.new(name: 'PORT', value: '4444'),
Expand Down

0 comments on commit 44d70c0

Please sign in to comment.