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

feat: add option to expose additional log fields #448

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions jobs/gorouter/spec
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ properties:
router.logging.syslog_network:
description: "Network protocol to use when connecting to the syslog server. Valid values are 'tcp', 'udp', <empty>. When choosing an empty string value, the local syslog daemon is used."
default: "udp"
router.logging.extra_fields:
description: |
An array of additional fields to log. Any new log fields will only be exposed via this
property and operators have to explicitly enable them. This is done to prevent breaking
log parsing in existing setups by the introduction of new fields.
Available fields are: local_address
default: []
router.logging.format.timestamp:
description: |
Format for timestamp in component logs. Valid values are 'rfc3339', 'deprecated', and 'unix-epoch'."
Expand Down
9 changes: 9 additions & 0 deletions jobs/gorouter/templates/gorouter.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ if !['rfc3339', 'deprecated', 'unix-epoch'].include?(p('router.logging.format.ti
raise "'#{p('router.logging.format.timestamp')}' is not a valid timestamp format for the property 'router.logging.format.timestamp'. Valid options are: 'rfc3339', 'deprecated', and 'unix-epoch'."
end

if_p('router.logging.extra_fields') do |extra_fields|
valid_extra_log_fields=['local_address']
if !extra_fields.all? { |el| valid_extra_log_fields.include?(el) }
raise "router.logging.extra_fields (#{extra_fields}) contains invalid values, valid are #{valid_extra_log_fields}"
end
end


timestamp_format=p('router.logging.format.timestamp')
if timestamp_format == 'deprecated'
timestamp_format = 'unix-epoch'
Expand All @@ -402,6 +410,7 @@ params['logging'] = {
'syslog_addr' => p('router.logging.syslog_addr'),
'syslog_network' => p('router.logging.syslog_network'),
'level' => p('router.logging_level'),
'extra_fields' => p('router.logging.extra_fields'),
'loggregator_enabled' => true,
'metron_address' => "localhost:#{p('metron.port')}",
'disable_log_forwarded_for' => p('router.disable_log_forwarded_for'),
Expand Down
32 changes: 32 additions & 0 deletions spec/gorouter_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,38 @@
end
end

context 'when extra_fields is set' do
context 'to ["local_address"]' do
before do
deployment_manifest_fragment['router']['logging'] = { 'extra_fields' => ['local_address'] }
end

it 'properly sets the config property' do
expect(parsed_yaml['logging']['extra_fields']).to include('local_address')
end
end

context 'to ["foobar"]' do
before do
deployment_manifest_fragment['router']['logging'] = { 'extra_fields' => ['foobar'] }
end

it 'raises an error' do
expect { parsed_yaml }.to raise_error(RuntimeError, 'router.logging.extra_fields (["foobar"]) contains invalid values, valid are ["local_address"]')
end
end

context 'to ["local_address", "foobar"]' do
before do
deployment_manifest_fragment['router']['logging'] = { 'extra_fields' => ['local_address', 'foobar'] }
end

it 'still raises an error' do
expect { parsed_yaml }.to raise_error(RuntimeError, 'router.logging.extra_fields (["local_address", "foobar"]) contains invalid values, valid are ["local_address"]')
end
end
end

context 'when access log streaming via syslog is enabled' do
before do
deployment_manifest_fragment['router']['write_access_logs_locally'] = false
Expand Down