Bug 1264039 - logshifter does not parse config properly if there's no newline at the end
Summary: logshifter does not parse config properly if there's no newline at the end
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: Logging
Version: 2.2.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
: ---
Assignee: Timothy Williams
QA Contact: chunchen
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-09-17 11:32 UTC by Evgheni Dereveanchin
Modified: 2019-08-15 05:27 UTC (History)
6 users (show)

Fixed In Version: openshift-origin-logshifter-1.10.1.2-1
Doc Type: Bug Fix
Doc Text:
When reading configuration files, logshifter previously read each line using a newline as the separator. When no newline character or EOL character existed at the end of a configuration file whose last line was not empty, the last line of the configuration would be ignored. This bug fix updates logshifter to catch an EOF and ensure that if the EOF is on a non-empty line, the line is read into the configuration. As a result, all lines in the logshifter configuration file are read, whether they end with a newline or EOL character or not.
Clone Of:
Environment:
Last Closed: 2015-09-30 16:38:43 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2015:1844 0 normal SHIPPED_LIVE Important: Red Hat OpenShift Enterprise 2.2.7 security, bug fix and enhancement update 2015-09-30 20:35:28 UTC

Description Evgheni Dereveanchin 2015-09-17 11:32:45 UTC
Description of problem:
Currently logshifter fails to start if the newline at the end of the file is missing.

Version-Release number of selected component (if applicable):
openshift-origin-logshifter-1.8.2.1-1.el6op.x86_64

How reproducible:
always

Steps to Reproduce:
1. open /etc/openshift/logshifter.conf on a node and remove the last empty line
2. try to start logshifter:
/usr/bin/logshifter -verbose -tag ruby


Actual results:

Logshifter cannot start, error returned:

config: &{queueSize:1000 inputBufferSize:4096 outputType:multi syslogBufferSize:4096 fileBufferSize:4096 fileWriterDir: outputTypeFromEnviron:false}
using max file size 10485760 and max files 10
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
runtime.panic(0x560780, 0x72cdaa)
	/usr/lib64/golang/src/pkg/runtime/panic.c:266 +0xb6
main.(*FileWriter).Init(0xc2100213c0, 0x0, 0x0)
	/builddir/build/BUILD/openshift-origin-logshifter-1.8.2.1/_build/src/github.com/openshift/logshifter/file_writer.go:62 +0x300
main.(*MultiWriter).Init(0xc21004f440, 0xc210000170, 0x568380)
	/builddir/build/BUILD/openshift-origin-logshifter-1.8.2.1/_build/src/github.com/openshift/logshifter/multi_writer.go:14 +0x5d
main.(*Output).Write(0xc21004f480, 0xc21004f480, 0x0, 0x0)
	/builddir/build/BUILD/openshift-origin-logshifter-1.8.2.1/_build/src/github.com/openshift/logshifter/output.go:27 +0x5f
main.(*Shifter).Start(0xc210021410, 0xc210021410, 0x4)
	/builddir/build/BUILD/openshift-origin-logshifter-1.8.2.1/_build/src/github.com/openshift/logshifter/shifter.go:66 +0xf8
main.main()
	/builddir/build/BUILD/openshift-origin-logshifter-1.8.2.1/_build/src/github.com/openshift/logshifter/main.go:124 +0xaf1

goroutine 3 [syscall]:
os/signal.loop()
	/usr/lib64/golang/src/pkg/os/signal/signal_unix.go:21 +0x1e
created by os/signal.init·1
	/usr/lib64/golang/src/pkg/os/signal/signal_unix.go:27 +0x31

goroutine 4 [chan receive]:
main.func·002()
	/builddir/build/BUILD/openshift-origin-logshifter-1.8.2.1/_build/src/github.com/openshift/logshifter/main.go:28 +0xbe
created by main.main
	/builddir/build/BUILD/openshift-origin-logshifter-1.8.2.1/_build/src/github.com/openshift/logshifter/main.go:31 +0x8a

goroutine 5 [syscall]:
runtime.goexit()
	/usr/lib64/golang/src/pkg/runtime/proc.c:1394

This causes gears on the node to fail silently without producing any logs when created/restarted.

Expected results:
Logshifter is able to parse the config properly

Additional info:
Sample "broken" config looks like this

hexdump -C /etc/openshift/logshifter.conf 
00000000  71 75 65 75 65 73 69 7a  65 20 3d 20 31 30 30 30  |queuesize = 1000|
00000010  0a 69 6e 70 75 74 62 75  66 66 65 72 73 69 7a 65  |.inputbuffersize|
00000020  20 3d 20 34 30 39 36 0a  6f 75 74 70 75 74 74 79  | = 4096.outputty|
00000030  70 65 20 3d 20 6d 75 6c  74 69 0a 73 79 73 6c 6f  |pe = multi.syslo|
00000040  67 62 75 66 66 65 72 73  69 7a 65 20 3d 20 34 30  |gbuffersize = 40|
00000050  39 36 0a 66 69 6c 65 62  75 66 66 65 72 73 69 7a  |96.filebuffersiz|
00000060  65 20 3d 20 34 30 39 36  0a 6f 75 74 70 75 74 74  |e = 4096.outputt|
00000070  79 70 65 66 72 6f 6d 65  6e 76 69 72 6f 6e 20 3d  |ypefromenviron =|
00000080  20 66 61 6c 73 65 0a 66  69 6c 65 77 72 69 74 65  | false.filewrite|
00000090  72 64 69 72 20 3d 20 7e  2f 61 70 70 2d 72 6f 6f  |rdir = ~/app-roo|
000000a0  74 2f 6c 6f 67 73                                 |t/logs|
000000a6

this one will work (note the 0A line feed symbol)

hexdump -C /etc/openshift/logshifter.conf 
00000000  71 75 65 75 65 73 69 7a  65 20 3d 20 31 30 30 30  |queuesize = 1000|
00000010  0a 69 6e 70 75 74 62 75  66 66 65 72 73 69 7a 65  |.inputbuffersize|
00000020  20 3d 20 34 30 39 36 0a  6f 75 74 70 75 74 74 79  | = 4096.outputty|
00000030  70 65 20 3d 20 6d 75 6c  74 69 0a 73 79 73 6c 6f  |pe = multi.syslo|
00000040  67 62 75 66 66 65 72 73  69 7a 65 20 3d 20 34 30  |gbuffersize = 40|
00000050  39 36 0a 66 69 6c 65 62  75 66 66 65 72 73 69 7a  |96.filebuffersiz|
00000060  65 20 3d 20 34 30 39 36  0a 6f 75 74 70 75 74 74  |e = 4096.outputt|
00000070  79 70 65 66 72 6f 6d 65  6e 76 69 72 6f 6e 20 3d  |ypefromenviron =|
00000080  20 66 61 6c 73 65 0a 66  69 6c 65 77 72 69 74 65  | false.filewrite|
00000090  72 64 69 72 20 3d 20 7e  2f 61 70 70 2d 72 6f 6f  |rdir = ~/app-roo|
000000a0  74 2f 6c 6f 67 73 0a                              |t/logs.|
000000a6

Comment 2 Timothy Williams 2015-09-21 19:55:09 UTC
The fix was shipped in openshift-origin-logshifter-1.9.1.1-1.el6op with openshift enterprise 2.2.6: https://rhn.redhat.com/errata/RHBA-2015-1463.html

Comment 3 Timothy Williams 2015-09-21 20:58:52 UTC
Even with the aforementioned fix, it is possible for the last line of the configuration file not to be included if the file does not end with a EOL or '\n'.

Comment 4 Timothy Williams 2015-09-21 21:14:05 UTC
https://github.com/openshift/origin-server/pull/6243

Comment 5 Josep 'Pep' Turro Mauri 2015-09-22 15:50:51 UTC
For QA:

(In reply to Timothy Williams from comment #3)
> Even with the aforementioned fix, it is possible for the last line of the
> configuration file not to be included if the file does not end with a EOL or
> '\n'.

Just to clarify the reproducing steps accordingly:

(in reply to Evgheni Dereveanchin from comment #0)
> Steps to Reproduce:
> 1. open /etc/openshift/logshifter.conf on a node and remove the last empty
> line

The problem actually happens when the last line in the file is not empty but doesn't end with a newline.

The default /etc/openshift/logshifter.conf is set for outputtype=file and its last line specifies the log file dir (filewriterdir), so you should be able to reproduce this on a fresh install with:

 # perl -i.bak -p0e 's/\s*$//' /etc/openshift/logshifter.conf

Comment 6 openshift-github-bot 2015-09-22 19:11:33 UTC
Commit pushed to master at https://github.com/openshift/origin-server

https://github.com/openshift/origin-server/commit/d51d2e03c2c6fd0e93d9c2e6ffe65bb4af720be9
Bug 1264039: Read all lines even if file does not end in '\n' or EOL

https://bugzilla.redhat.com/show_bug.cgi?id=1264039

Ensure that all lines of a configuration file are read even if the file does not end in a newline character or EOL.

Comment 10 Gaoyun Pei 2015-09-23 09:04:27 UTC
Verify this bug with openshift-origin-logshifter-1.10.1.2-1.el6op.x86_64.

Remove the whitespace character of logshifter.conf by 
# perl -i.bak -p0e 's/\s*$//' /etc/openshift/logshifter.conf

Start logshifter:
[root@node2 yum.repos.d]# /usr/bin/logshifter -verbose -tag ruby
config: &{queueSize:1000 inputBufferSize:4096 outputType:file syslogBufferSize:4096 fileBufferSize:4096 fileWriterDir:~/app-root/logs outputTypeFromEnviron:false}
using max file size 10485760 and max files 10

Comment 12 errata-xmlrpc 2015-09-30 16:38:43 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2015-1844.html


Note You need to log in before you can comment on or make changes to this bug.