Commit Graph

19 Commits

Author SHA1 Message Date
Shijiang Wei b1594c59f5 use pubsub instead of filenotify to follow json logs
inotify event is trigged immediately there's data written to disk.
But at the time that the inotify event is received, the json line might
not fully saved to disk. If the json decoder tries to decode in such
case, an io.UnexpectedEOF will be trigged.
We used to retry for several times to mitigate the io.UnexpectedEOF error.
But there are still flaky tests caused by the partial log entries.

The daemon knows exactly when there are new log entries emitted. We can
use the pubsub package to notify all the log readers instead of inotify.

Signed-off-by: Shijiang Wei <mountkin@gmail.com>

try to fix broken test. will squash once tests pass

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
2016-02-15 19:25:16 +08:00
Ingo Gottwald f8c5420080 Fix race condition in JSONFileLogger.Log
Signed-off-by: Ingo Gottwald <in.gottwald@gmail.com>
2016-01-03 22:45:56 +01:00
David Calavera 4fef42ba20 Replace pkg/units with docker/go-units.
Signed-off-by: David Calavera <david.calavera@gmail.com>
2015-12-16 12:26:49 -05:00
David Calavera 27220ecc6b Move timeutils functions to the only places where they are used.
- Move time json marshaling to the jsonlog package: this is a docker
  internal hack that we should not promote as a library.
- Move Timestamp encoding/decoding functions to the API types: This is
  only used there. It could be a standalone library but I don't this
it's worth having a separated repo for this. It could introduce more
complexity than it solves.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2015-12-15 14:56:14 -05:00
daehyeok mun 086c0b4a66 Extract rotate file writer from json log driver
Signed-off-by: Daehyeok Mun <daehyeok@gmail.com>
2015-11-14 16:15:44 -07:00
Brian Goff c136a33c5b Fallback to file polling for jsonlog reader on err
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2015-11-05 10:05:05 -05:00
Shijiang Wei a82f9ac819 increase the maxJSONDecodeRetry in json log reader
Signed-off-by: Shijiang Wei <mountkin@gmail.com>
2015-11-02 17:51:22 +08:00
Shijiang Wei e41eae8b42 fix a race in json logger reader
The json decoder starts to decode immediately an inotify event is
received.
But at the time the inotify event is trigged, the json log
entry might haven't been fully written to the disk.
In this case the decoder will return an "io.UnexpectedEOF" error, but
there is still data remaining in the decoder's buffer. And the data
should be passed to the decoder when the next inotify event is
triggered.

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
2015-10-31 02:28:23 +08:00
Daniel Dao 0083f6e984 add labels/env log option for jsonfile
this allows jsonfile logger to collect extra metadata from containers with
`--log-opt labels=label1,label2 --log-opt env=env1,env2`.

Extra attributes are saved into `attrs` attributes for each log data.

Signed-off-by: Daniel Dao <dqminh@cloudflare.com>
2015-10-12 21:12:46 +02:00
Alexander Morozov cde607108b Fix error message in max-file validation
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
2015-08-17 15:34:39 -07:00
Lei Jitang 5220f3b535 Enable golint in pkg/jsonlog and pkg/jsonmessage.
Signed-off-by: Lei Jitang <leijitang@huawei.com>
2015-08-08 11:28:22 +08:00
Brian Goff c57faa91e2 Ensure reader position is at the end after tailing
After tailing a file, if the number of lines requested is > the number
of lines in the file, this would cause a json unmarshalling error to
occur when we later try to go follow the file.
So brute force set it to the end if any tailing occurred.

There is potential that there could be some missing log messages if logs
are being written very quickly, however I was not able to make this
happen even with `while true; do echo hello; done`, so this is probably
acceptable.

While testing this I also found a panic in LogWatcher.Close can be
called twice due to a race. Fix channel close to only close when there
has been no signal to the channel.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2015-08-01 08:00:28 -04:00
Morgan Bauer ccbe539e86
golint fixes for daemon/logger/*
- downcase and privatize exported variables that were unused
 - make accurate an error message
 - added package comments
 - remove unused var ReadLogsNotSupported
 - enable linter
 - some spelling corrections

Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
2015-07-29 13:09:39 -07:00
Brian Goff c0391bf554 Split reader interface from logger interface
Implement new reader interface on jsonfile.
Moves jsonlog decoding from daemon to jsonfile logger.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2015-07-21 20:47:31 -04:00
wlan0 9b782d3af3 add support for maximum log size, and max number of log files
Signed-off-by: wlan0 <sidharthamn@gmail.com>
2015-07-02 06:26:06 -07:00
Ahmet Alp Balkan 3a8728b431 daemon: Logging drivers refactoring
- noplog driver pkg for '--log-driver=none' (null object pattern)
- centralized factory for log drivers (instead of case/switch)
- logging drivers registers themselves to factory upon import
  (easy plug/unplug of drivers in daemon/logdrivers.go)
- daemon now doesn't start with an invalid log driver
- Name() method of loggers is actually now their cli names (made it useful)
- generalized Read() logic, made it unsupported except json-file (preserves
  existing behavior)

Spotted some duplication code around processing of legacy json-file
format, didn't touch that and refactored in both places.

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
2015-05-12 19:11:52 +00:00
unclejack 132da3f036 daemon/logger/jsonfilelog: avoid some allocations
Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
2015-04-02 18:33:23 +03:00
Alexander Morozov bd8661e8fa Protect jsonfilelog writes with mutex
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
2015-03-18 13:00:53 -07:00
Alexander Morozov 47a6afb93f Default 'json-file' logging driver and none logging driver
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
2015-03-13 12:13:21 -07:00