Skip to content

Commit 5576cd7

Browse files
committed
feat: add option to expose additional log fields
1 parent 47d2c16 commit 5576cd7

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

jobs/gorouter/spec

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ properties:
322322
router.logging.syslog_network:
323323
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."
324324
default: "udp"
325+
router.logging.extra_access_log_fields:
326+
description: |
327+
An array of additional access log fields to log. Any new log fields will only be exposed via
328+
this property and operators have to explicitly enable them. This is done to prevent breaking
329+
log parsing in existing setups by the introduction of new fields. Does not affect stdout /
330+
stderr logs.
331+
Available fields are: local_address
332+
default: []
325333
router.logging.format.timestamp:
326334
description: |
327335
Format for timestamp in component logs. Valid values are 'rfc3339', 'deprecated', and 'unix-epoch'."

jobs/gorouter/templates/gorouter.yml.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ if !['rfc3339', 'deprecated', 'unix-epoch'].include?(p('router.logging.format.ti
391391
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'."
392392
end
393393

394+
if_p('router.logging.extra_access_log_fields') do |extra_fields|
395+
valid_extra_log_fields=['local_address']
396+
if !extra_fields.all? { |el| valid_extra_log_fields.include?(el) }
397+
raise "router.logging.extra_access_log_fields (#{extra_fields}) contains invalid values, valid are #{valid_extra_log_fields}"
398+
end
399+
end
400+
401+
394402
timestamp_format=p('router.logging.format.timestamp')
395403
if timestamp_format == 'deprecated'
396404
timestamp_format = 'unix-epoch'
@@ -402,6 +410,7 @@ params['logging'] = {
402410
'syslog_addr' => p('router.logging.syslog_addr'),
403411
'syslog_network' => p('router.logging.syslog_network'),
404412
'level' => p('router.logging_level'),
413+
'extra_fields' => p('router.logging.extra_access_log_fields'),
405414
'loggregator_enabled' => true,
406415
'metron_address' => "localhost:#{p('metron.port')}",
407416
'disable_log_forwarded_for' => p('router.disable_log_forwarded_for'),

spec/gorouter_templates_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,38 @@
13481348
end
13491349
end
13501350

1351+
context 'when extra_access_log_fields is set' do
1352+
context 'to ["local_address"]' do
1353+
before do
1354+
deployment_manifest_fragment['router']['logging'] = { 'extra_access_log_fields' => ['local_address'] }
1355+
end
1356+
1357+
it 'properly sets the config property' do
1358+
expect(parsed_yaml['logging']['extra_access_log_fields']).to include('local_address')
1359+
end
1360+
end
1361+
1362+
context 'to ["foobar"]' do
1363+
before do
1364+
deployment_manifest_fragment['router']['logging'] = { 'extra_access_log_fields' => ['foobar'] }
1365+
end
1366+
1367+
it 'raises an error' do
1368+
expect { parsed_yaml }.to raise_error(RuntimeError, 'router.logging.extra_access_log_fields (["foobar"]) contains invalid values, valid are ["local_address"]')
1369+
end
1370+
end
1371+
1372+
context 'to ["local_address", "foobar"]' do
1373+
before do
1374+
deployment_manifest_fragment['router']['logging'] = { 'extra_access_log_fields' => ['local_address', 'foobar'] }
1375+
end
1376+
1377+
it 'still raises an error' do
1378+
expect { parsed_yaml }.to raise_error(RuntimeError, 'router.logging.extra_access_log_fields (["local_address", "foobar"]) contains invalid values, valid are ["local_address"]')
1379+
end
1380+
end
1381+
end
1382+
13511383
context 'when access log streaming via syslog is enabled' do
13521384
before do
13531385
deployment_manifest_fragment['router']['write_access_logs_locally'] = false

0 commit comments

Comments
 (0)