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

Don't add a Steno sink in test env #3825

Merged
merged 1 commit into from
Sep 20, 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
2 changes: 1 addition & 1 deletion config/cloud_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ logging:
anonymize_ips: false
format:
timestamp: 'rfc3339'
stdout_sink_enabled: true
stdout_sink_enabled: false

log_audit_events: false

Expand Down
1 change: 1 addition & 0 deletions lib/cloud_controller/config_schemas/base/api_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ApiSchema < VCAP::Config
level: String, # debug, info, etc.
file: String, # Log file to use
syslog: String, # Name to associate with syslog messages (should start with 'vcap.')
optional(:stdout_sink_enabled) => bool,
optional(:anonymize_ips) => bool,
optional(:format) => {
optional(:timestamp) => String
Expand Down
3 changes: 2 additions & 1 deletion lib/cloud_controller/config_schemas/base/migrate_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class MigrateSchema < VCAP::Config
logging: {
level: String, # debug, info, etc.
file: String, # Log file to use
syslog: String # Name to associate with syslog messages (should start with 'vcap.')
syslog: String, # Name to associate with syslog messages (should start with 'vcap.')
optional(:stdout_sink_enabled) => bool
}
}
end
Expand Down
4 changes: 3 additions & 1 deletion lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ namespace :db do

def logging_output
VCAP::CloudController::StenoConfigurer.new(RakeConfig.config.get(:logging)).configure do |steno_config_hash|
steno_config_hash[:sinks] << Steno::Sink::IO.new($stdout)
if RakeConfig.config.get(:logging, :stdout_sink_enabled).nil? || RakeConfig.config.get(:logging, :stdout_sink_enabled)
steno_config_hash[:sinks] << Steno::Sink::IO.new($stdout)
end
end
end

Expand Down
70 changes: 69 additions & 1 deletion spec/tasks/db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,33 @@
let(:db_migrator) { instance_double(DBMigrator) }

describe ':migrate' do
let(:stdout_sink_enabled) { true }
let(:logging_config) do
{
logging: {
stdout_sink_enabled: stdout_sink_enabled,
level: 'debug2',
syslog: 'vcap.example',
file: '/tmp/cloud_controller.log',
anonymize_ips: false,
format: { timestamp: 'rfc3339' }
}
}
end

before do
TestConfig.override(**logging_config)
allow(RakeConfig).to receive(:config).and_return(TestConfig.config_instance)
allow(DBMigrator).to receive(:from_config).and_return(db_migrator)
allow(db_migrator).to receive(:apply_migrations)
end

after do
Steno.config.sinks.delete_if { |sink| sink.instance_variable_get(:@io) == $stdout }
end

it 'logs to configured sinks + STDOUT' do
Rake::Task['db:migrate'].invoke
Rake::Task['db:migrate'].execute

# From test config:
expect(Steno.config.sinks).to include(an_instance_of(Steno::Sink::Syslog))
Expand All @@ -21,5 +40,54 @@
# From db.rake:
expect(Steno.config.sinks).to include(an_instance_of(Steno::Sink::IO).and(satisfy { |sink| sink.instance_variable_get(:@io) == $stdout }))
end

describe 'steno sink' do
let(:logging_config) do
{
logging: {
stdout_sink_enabled: stdout_sink_enabled,
level: 'debug2',
file: '/tmp/cloud_controller.log',
anonymize_ips: false,
format: { timestamp: 'rfc3339' }
}
}
end

context 'when `stdout_sink_enabled` is `true`' do
it 'configures steno logger with stdout sink' do
Rake::Task['db:migrate'].execute
expect(Steno.logger('cc.db.migrations').instance_variable_get(:@sinks).length).to eq(2)
end
end

context 'when `stdout_sink_enabled` is not set' do
let(:logging_config) do
{
logging: {
level: 'debug2',
file: '/tmp/cloud_controller.log',
anonymize_ips: false,
format: { timestamp: 'rfc3339' }
}
}
end

it 'configures steno logger with stdout sink' do
Rake::Task['db:migrate'].invoke

expect(Steno.logger('cc.db.migrations').instance_variable_get(:@sinks).length).to eq(2)
end
end

context 'when `stdout_sink_enabled` is `false`' do
let(:stdout_sink_enabled) { false }

it 'configures steno logger without stdout sink' do
Rake::Task['db:migrate'].execute
expect(Steno.logger('cc.db.migrations').instance_variable_get(:@sinks).length).to eq(1)
end
end
end
end
end
4 changes: 2 additions & 2 deletions spec/unit/lib/bosh_errand_environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
describe '#initialize' do
it 'configures steno logger with stdout sink' do
bosh_errand_environment.setup_environment
expect(Steno.logger('cc.errand').instance_variable_get(:@sinks).length).to be(2)
expect(Steno.logger('cc.errand').instance_variable_get(:@sinks).length).to eq(2)
end

context 'when `stdout_sink_enabled` is `false`' do
let(:stdout_sink_enabled) { false }

it 'configures steno logger wo stdout sink' do
bosh_errand_environment.setup_environment
expect(Steno.logger('cc.errand').instance_variable_get(:@sinks).length).to be(1)
expect(Steno.logger('cc.errand').instance_variable_get(:@sinks).length).to eq(1)
end
end
end
Expand Down