Skip to content

Commit

Permalink
Don't add a Steno sink in test env
Browse files Browse the repository at this point in the history
* this gets applied to the entire test run in GithubActions and makes
  the test output hard to read
  • Loading branch information
sethboyles committed Sep 17, 2024
1 parent 1f30750 commit 81d0f50
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
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
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

0 comments on commit 81d0f50

Please sign in to comment.