Commit graph

537 commits

Author SHA1 Message Date
Brian Goff
5a664dc87d jsonfile: more defensive reader implementation
Tonis mentioned that we can run into issues if there is more error
handling added here. This adds a custom reader implementation which is
like io.MultiReader except it does not cache EOF's.
What got us into trouble in the first place is `io.MultiReader` will
always return EOF once it has received an EOF, however the error
handling that we are going for is to recover from an EOF because the
underlying file is a file which can have more data added to it after
EOF.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2021-03-18 18:44:46 +00:00
Brian Goff
4be98a38e7 Fix handling for json-file io.UnexpectedEOF
When the multireader hits EOF, we will always get EOF from it, so we
cannot store the multrireader fro later error handling, only for the
decoder.

Thanks @tobiasstadler for pointing this error out.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2021-03-11 20:01:03 +00:00
Xia Wu
d10046f228 Add an option to skip create log stream for awslogs driver
Added an option `awslogs-create-stream` to allow skipping log stream
creation for awslogs log driver. The default value is still true to
keep the behavior be consistent with before.

Signed-off-by: Xia Wu <xwumzn@amazon.com>
2021-03-09 15:49:43 -08:00
Nathan Carlson
8d73c1ad68 Check the length of the correct variable #42039
Signed-off-by: Nathan Carlson <carl4403@umn.edu>
2021-02-18 10:27:35 -06:00
Kazuyoshi Kato
bb11365e96 Handle long log messages correctly on SizedLogger
Loggers that implement BufSize() (e.g. awslogs) uses the method to
tell Copier about the maximum log line length. However loggerWithCache
and RingBuffer hide the method by wrapping loggers.

As a result, Copier uses its default 16KB limit which breaks log
lines > 16kB even the destinations can handle that.

This change implements BufSize() on loggerWithCache and RingBuffer to
make sure these logger wrappes don't hide the method on the underlying
loggers.

Fixes #41794.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2021-01-20 16:44:06 -08:00
=
b102d4637c Fix windows log file rotation with readers
This fixes the case where log rotation fails on Windows while there are
clients reading container logs.

Evicts readers if there is an error during rotation and try rotation again.
This is needed for Windows with this scenario:

1. `docker logs -f` is called
2. Log rotation occurs (log.txt -> log.txt.1, truncate and re-open
   log.txt)
3. Log rotation occurs again (rm log.txt.1, log.txt -> log.txt.1)

On step 3, before this change, the log rotation will fail with `Access
is denied`.
In this case, what we have is a reader holding a file handle to the
primary log file. The log file is then rotated, but the reader still has
a the handle open. `FILE_SHARE_DELETE` allows this to happen... but then
we try to do it again for the next rotation and it blows up.
So when it blows up we force all the readers to disconnect, close the
log file, and try rotation again, which will succeed based on the added
tests.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2020-10-29 18:38:30 +00:00
Brian Goff
bcc993b494 Fix logfile to open all files with custom openFile
This makes sure, on Windows, that all files are opened with
FILE_SHARE_DELETE.

On non-Windows this just calls the same `os.Open()`.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2020-10-28 20:36:32 +00:00
Brian Goff
56ba96b6c1 Clean up some logfile implementation
- Ignore some pointless errors (like not exist on remove)
- Consolidate error handling/logging
- Fix race condition reading last log timestamp in the compression
  goroutine. This needs to be done while holding the write lock, which
  is not (or may not be) locked while compressing a rotated log file.
- Remove some indentation and consolidate mutex unlocking in
  `compressFile`

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2020-10-28 20:36:32 +00:00
Brian Goff
3148a46657 Fix various race conditions in loggerutils
Found by running with `go test -race`

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2020-10-28 20:36:32 +00:00
Patrick Haas
ef553e14a4 Fix gcplogs memory/connection leak
The cloud logging client should be closed when the log driver is closed. Otherwise dockerd will keep a gRPC connection to the logging endpoint open indefinitely.

This results in a slow leak of tcp sockets (1) and memory (~200Kb) any time that a container using `--log-driver=gcplogs` is terminates.

Signed-off-by: Patrick Haas <patrickhaas@google.com>
2020-09-30 17:45:19 -07:00
Christian Becker
322c9e6866 add partial metadata to journald logs
add all partial metadata available to journald logs to allow easier reassembly of partial messages in downstream logging systems

fixes #41403

Signed-off-by: Christian Becker <christian.becker@sixt.com>
2020-09-01 12:54:05 +02:00
Sebastiaan van Stijn
22153d111e
Merge pull request #41239 from cpuguy83/fix_racey_logger_test
Fix log file rotation test.
2020-07-21 01:04:53 +02:00
Sebastiaan van Stijn
de5812c2a1
Merge pull request #40807 from wpjunior/plugin-feedback
Improve error feedback when plugin does not implement desired interface
2020-07-16 09:55:17 +02:00
Brian Goff
c6d860ace6 Fix log file rotation test.
The test was looking for the wrong file name.
Since compression happens asyncronously, sometimes the test would
succeed and sometimes fail.

This change makes sure to wait for the compressed version of the file
since we can't know when the compression is going to occur.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2020-07-15 11:06:07 -07:00
Wang Yumu
96556854a7 Fixes #41010 skip empty lines
Signed-off-by: Wang Yumu <37442693@qq.com>
2020-06-06 12:36:50 +08:00
Brian Goff
5ea5c02c88 Fix flakey test for log file rotate.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2020-05-18 10:27:53 -07:00
Brian Goff
75d655320e
Merge pull request #40920 from cpuguy83/log_rotate_error_handling
logfile: Check if log is closed on close error during rotate
2020-05-07 14:45:42 -07:00
Brian Goff
3989f91075 logfile: Check if log is closed on close error during rotate
This prevents getting into a situation where a container log cannot make
progress because we tried to rotate a file, got an error, and now the
file is closed. The next time we try to write a log entry it will try
and rotate again but error that the file is already closed.

I wonder if there is more we can do to beef up this rotation logic.
Found this issue while investigating missing logs with errors in the
docker daemon logs like:

```
Failed to log message for json-file: error closing file: close <file>:
file already closed
```

I'm not sure why the original rotation failed since the data was no
longer available.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2020-05-07 11:37:06 -07:00
Sebastiaan van Stijn
07d60bc257
Replace errors.Cause() with errors.Is() / errors.As()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-04-29 00:28:41 +02:00
Wilson Júnior
964731e1d3
Improve error feedback when plugin does not implement desired interface
Signed-off-by: Wilson Júnior <wilsonpjunior@gmail.com>
2020-04-21 18:06:24 -03:00
Brian Goff
933a87236f Reduce allocations for logfile reader
Before this change, the log decoder function provided by the log driver
to logfile would not be able to re-use buffers, causing undeeded
allocations and memory bloat for dockerd.

This change introduces an interface that allows the log driver to manage
it's memory usge more effectively.
This only affects json-file and local log drivers.

`json-file` still is not great just because of how the json decoder in the
stdlib works.
`local` is significantly improved.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2020-04-08 12:24:31 -07:00
Akihiro Suda
9a82a9a8ea vendor containerd, BuildKit, protobuf, grpc, and golang.org/x
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-03-03 10:25:20 +09:00
Brian Goff
750f0d1648 Support configuration of log cacher.
Configuration over the API per container is intentionally left out for
the time being, but is supported to configure the default from the
daemon config.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit cbecf48bc352e680a5390a7ca9cff53098cd16d7)
Signed-off-by: Madhu Venugopal <madhu@docker.com>
2020-02-19 17:02:34 -05:00
Brian Goff
e2ceb83a53 Support reads for all log drivers.
This supplements any log driver which does not support reads with a
custom read implementation that uses a local file cache.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit d675e2bf2b75865915c7a4552e00802feeb0847f)
Signed-off-by: Madhu Venugopal <madhu@docker.com>
2020-02-19 17:01:44 -05:00
Sebastiaan van Stijn
562880b276
Fix more goimports
```
daemon/logger/splunk/splunk_test.go:33: File is not `goimports`-ed (goimports)
        envKey:      "a",
        envRegexKey: "^foo",
        labelsKey:   "b",
        tagKey:      "c",
integration/build/build_test.go:41: File is not `goimports`-ed (goimports)
            rm:      false,
            forceRm: false,
integration/image/remove_unix_test.go:49: File is not `goimports`-ed (goimports)
        Root: d.Root,
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-11 18:56:25 +01:00
Sebastiaan van Stijn
008fc67974
Fluentd: add fluentd-request-ack option
This adds a new `fluentd-request-ack` logging option for the Fluentd
logging driver. If enabled, the server will respond with an acknowledgement.
This option improves the reliability of the message transmission. This
change is not versioned, and affects all API versions.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-11 02:13:24 +01:00
Sebastiaan van Stijn
cc1f3c750e
Fluentd: add fluentd-async option, deprecate fluentd-async-connect
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-11 02:13:22 +01:00
Sebastiaan van Stijn
a1d4a081dd
Fluentd: extract parsing config, and validate early
This extracts parsing the driver's configuration to a
function, and uses the same function both when initializing
the driver, and when validating logging options.

Doing so allows validating if the provided options are in
the correct format when calling `ValidateOpts`, instead
of resulting in an error when initializing the logging driver.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-11 02:13:20 +01:00
Sebastiaan van Stijn
8bd4aedb02
Fluentd: sort consts alphabetically
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-11 02:13:18 +01:00
Sebastiaan van Stijn
ad13a2a4ba
Fluentd: return "invalid parameter" for invalid config options
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-11 02:13:15 +01:00
Sebastiaan van Stijn
9f0b3f5609
bump gotest.tools v3.0.1 for compatibility with Go 1.14
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-11 00:06:42 +01:00
Sebastiaan van Stijn
ba6bbca89a
daemon/logger: normalize comment formatting
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-11-27 15:42:27 +01:00
Akihiro Suda
a4a0429eec
Merge pull request #40234 from Jonas-Heinrich/40232-comply-with-gelf-spec
Change gelf logger to comply with gelf spec
2019-11-26 12:06:47 +09:00
Sebastiaan van Stijn
6ee536b4a0
daemon: remove use of deprecated os.SEEK_END
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-11-25 18:53:03 +01:00
Jonas Heinrich
5c6b913ff1
logger/gelf: Skip empty lines to comply with spec
The [gelf payload specification](http://docs.graylog.org/en/2.4/pages/gelf.html#gelf-payload-specification)
demands that the field `short_message` *MUST* be set by the client library.
Since docker logging via the gelf driver sends messages line by line, it can happen that messages with an empty
`short_message` are passed on. This causes strict downstream processors (like graylog) to raise an exception.

The logger now skips messages with an empty line.

Resolves: #40232
See also: #37572

Signed-off-by: Jonas Heinrich <Jonas@JonasHeinrich.com>
2019-11-25 11:55:15 +01:00
Ziheng Liu
d7bc994a08 awslogs & archive: prevent 2 goroutine leaks in test functions
Signed-off-by: Ziheng Liu <lzhfromustc@gmail.com>
2019-10-29 17:03:38 -04:00
Justin Cormack
f681590a25
Merge pull request #40081 from thaJeztah/http_constants
Use http constants for HTTP methods and status codes
2019-10-17 11:30:26 -07:00
Sebastiaan van Stijn
133eddaee8
Merge pull request #39987 from devonestes/fix-splunk-ack
Add ability to handle index acknowledgment with splunk log driver
2019-10-14 03:02:35 +02:00
Sebastiaan van Stijn
9c590ed5c5
daemon/logger/splunk: use constants for http methods
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-13 19:11:26 +02:00
Sebastiaan van Stijn
37760f0c2b
Merge pull request #39974 from cpuguy83/fix_windows_file_handles
Use FILE_SHARE_DELETE for log files on Windows.
2019-10-03 20:10:29 +02:00
Devon Estes
cb2a36a89c Add ability to handle index acknowledgment with splunk log driver
Previously there was no way for the splunk log driver to work if index
acknowledgment was set on the HEC, and it would in fact fail silently.
This will now allow users to specify if index acknowledgment is set and
will work with that setting.

Signed-off-by: Devon Estes <devon.c.estes@gmail.com>
2019-09-25 13:37:34 +02:00
Tibor Vass
a8608b5b67 homedir: remove idtools and libcontainer's user package dependencies
About github.com/opencontainers/runc/libcontainer/user:

According to 195d8d544a
this package has two functions:
- Have a static implementation of user lookup, which is now supported in the
  os/user stdlib package with the osusergo build tag, but wasn't at the time.
- Have extra functions that os/user doesn't have, but none of those are used
  in homedir.

Since https://github.com/moby/moby/pull/11287, homedir depended directly on
libcontainer's user package for CurrentUser().
This is being replaced with os/user.Current(), because all of our static
binaries are compiled with the osusergo tag, and for dynamic libraries it
is more correct to use libc's implementation than parsing /etc/passwd.

About github.com/docker/docker/pkg/idtools:

Only dependency was from GetStatic() which uses idtools.LookupUID(uid).
The implementation of idtools.LookupUID just calls to
github.com/opencontainers/runc/libcontainer/user.LookupUid or fallbacks
to exec-ing to getent (since https://github.com/moby/moby/pull/27599).

This patch replaces calls to homedir.GetStatic by homedir.Get(), opting out
of supporting nss lookups in static binaries via exec-ing to getent for
the homedir package.

If homedir package users need to support nss lookups, they are advised
to compile dynamically instead.

Signed-off-by: Tibor Vass <tibor@docker.com>
2019-09-24 00:32:13 +00:00
Brian Goff
a5f237c2b5 Use FILE_SHARE_DELETE for log files on Windows.
This fixes issues where one goroutine tries to delete or rename a file
while another goroutine has the file open (e.g. a log reader).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2019-09-23 16:45:07 -07:00
Brian Goff
a36dfe758d
Merge pull request #39969 from kolyshkin/log-max-file-1-follow
logger: fix follow logs for max-file=1
2019-09-23 08:46:07 -07:00
Kir Kolyshkin
9cd24ba605 logger: fix follow logs for max-file=1
In case jsonlogfile is used with max-file=1 and max-size set,
the log rotation is not perfomed; instead, the log file is closed
and re-open with O_TRUNC.

This situation is not handled by the log reader in follow mode,
leading to an issue of log reader being stuck forever.

This situation (file close/reopen) could be handled in waitRead(),
but fsnotify library chose to not listen to or deliver this event
(IN_CLOSE_WRITE in inotify lingo).

So, we have to handle this by checking the file size upon receiving
io.EOF from the log reader, and comparing the size with the one received
earlier. In case the new size is less than the old one, the file was
truncated and we need to seek to its beginning.

Fixes #39235.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-09-20 16:09:39 -07:00
Samuel Karp
fd94bae0b8
awslogs: fix flaky TestLogBlocking unit test
TestLogBlocking is intended to test that the Log method blocks by
default.  It does this by mocking out the internals of the
awslogs.logStream and replacing one of its internal channels with one
that is controlled by the test.  The call to Log occurs inside a
goroutine.  Go may or may not schedule the goroutine immediately and the
blocking may or may not be observed outside the goroutine immediately
due to decisions made by the Go runtime.  This change adds a small
timeout for test failure so that the Go runtime has the opportunity to
run the goroutine before the test fails.

Signed-off-by: Samuel Karp <skarp@amazon.com>
2019-09-20 16:06:54 -07:00
Sebastiaan van Stijn
9c701fdb6b
logger/journald: U1000: field mu is unused (unused)
this looks to be a false positive, but this field is not
used if journald is not supported, which may be the cause

```
daemon/logger/journald/journald.go:21:2: U1000: field `mu` is unused (unused)
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-18 12:57:42 +02:00
Kir Kolyshkin
7b6201f032
daemon/logger/BenchmarkCopy: don't call t.Fatal from a goroutine
staticcheck go linter says:

> daemon/logger/copier_test.go:451:2: SA2002: the goroutine calls T.Fatal, which must be called in the same goroutine as the test (staticcheck)

What it doesn't say is why. The reason is, t.Fatal() calls t.FailNow(),
which is expected to stop test execution right now. It does so by
calling runtime.Goexit(), which, unless called from a main goroutine,
does not stop test execution.

Anyway, long story short, if we don't care much about stopping the test
case immediately, we can just replace t.Fatalf() with t.Errorf() which
still marks the test case as failed, but won't stop it immediately.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-09-18 12:57:38 +02:00
Kir Kolyshkin
04129678a6
jsonfilelog_test: check err from open before close
Fix warnings like this one:

> daemon/logger/jsonfilelog/jsonfilelog_test.go:191:3: SA5001: should check returned error before deferring file.Close() (staticcheck)
> 		defer file.Close()
>		^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-09-18 12:57:30 +02:00
Sebastiaan van Stijn
07ff4f1de8
goimports: fix imports
Format the source according to latest goimports.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-18 12:56:54 +02:00
Vincent Demeester
cd14846d0c
Merge pull request #39818 from thaJeztah/fix_awslogs_linting
awslogs: fix linting issues, and small refactoring
2019-09-11 09:14:38 +02:00
Sebastiaan van Stijn
6c75c86240
Windows: skip flaky TestLogBlocking
This test frequently fails on Windows RS1 (mainly), so skipping it
for now on Windows;

```
ok  	github.com/docker/docker/daemon/logger	0.525s	coverage: 43.0% of statements
time="2019-09-09T20:37:35Z" level=info msg="Trying to get region from EC2 Metadata"
time="2019-09-09T20:37:36Z" level=info msg="Log stream already exists" errorCode=ResourceAlreadyExistsException logGroupName= logStreamName= message= origError="<nil>"
--- FAIL: TestLogBlocking (0.02s)
    cloudwatchlogs_test.go:313: Expected to be able to read from stream.messages but was unable to
time="2019-09-09T20:37:36Z" level=error msg=Error
time="2019-09-09T20:37:36Z" level=error msg="Failed to put log events" errorCode=InvalidSequenceTokenException logGroupName=groupName logStreamName=streamName message="use token token" origError="<nil>"
time="2019-09-09T20:37:36Z" level=error msg="Failed to put log events" errorCode=DataAlreadyAcceptedException logGroupName=groupName logStreamName=streamName message="use token token" origError="<nil>"
time="2019-09-09T20:37:36Z" level=info msg="Data already accepted, ignoring error" errorCode=DataAlreadyAcceptedException logGroupName=groupName logStreamName=streamName message="use token token"
FAIL
coverage: 78.2% of statements
FAIL	github.com/docker/docker/daemon/logger/awslogs	0.630s
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-09 23:50:04 +02:00
Kir Kolyshkin
2e0cafb01b
awslogs: refactor create()
Get rid of too many nested if statements. Remove the redundand check for
err != nil, fixing the following lint issue:

> daemon/logger/awslogs/cloudwatchlogs.go:452:10: nilness: tautological condition: non-nil != nil (govet)
> 		if err != nil {
> 		       ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-09-03 10:39:10 +02:00
Sebastiaan van Stijn
ef2872132d
awslogs: replace deprecated session.New() with session.NewSession()
```
16:04:35 daemon/logger/awslogs/cloudwatchlogs.go:312:25: SA1019: session.New is deprecated: Use NewSession functions to create sessions instead. NewSession has the same functionality as New except an error can be returned when the func is called instead of waiting to receive an error until a request is made.  (staticcheck)
16:04:35 	return ec2metadata.New(session.New())
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-03 10:39:08 +02:00
Sebastiaan van Stijn
54d021ef8f
awslogs: remove unused eventBuffer update
We return immediately after this, so no need to update eventBuffer:

```
16:04:35 daemon/logger/awslogs/cloudwatchlogs.go:554:5: SA4006: this value of `eventBuffer` is never used (staticcheck)
16:04:35 				eventBuffer = eventBuffer[:0]
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-09-03 10:39:06 +02:00
Kir Kolyshkin
20a0e58a79 journald/read: fix/unify errors
1. Use "in-place" variables for if statements to limit their scope to
   the respectful `if` block.

2. Report the error returned from sd_journal_* by using CErr().

3. Use errors.New() instead of fmt.Errorf().

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-08-02 10:02:35 -07:00
Kir Kolyshkin
dd4bfe30a8 journald: fix for --tail 0
From the first glance, `docker logs --tail 0` does not make sense,
as it is supposed to produce no output, but `tail -n 0` from GNU
coreutils is working like that, plus there is even a test case
(`TestLogsTail` in integration-cli/docker_cli_logs_test.go).

Now, something like `docker logs --follow --tail 0` makes total
sense, so let's make it work.

(NOTE if --tail is not used, config.Tail is set to -1)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-08-02 10:02:35 -07:00
Kir Kolyshkin
b73fb8fd5d journald/read: avoid piling up open files
If we take a long time to process log messages, and during that time
journal file rotation occurs, the journald client library will keep
those rotated files open until sd_journal_process() is called.

By periodically calling sd_journal_process() during the processing
loop we shrink the window of time a client instance has open file
descriptors for rotated (deleted) journal files.

This code is modelled after that of journalctl [1]; the above explanation
as well as the value of 1024 is taken from there.

[v2: fix CErr() argument]

[1] https://github.com/systemd/systemd/blob/dc16327c48d/src/journal/journalctl.c#L2676
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-08-02 10:02:35 -07:00
Kir Kolyshkin
f091febc94 journald/read: simplify/fix followJournal()
TL;DR: simplify the code, fix --follow hanging indefinitely

Do the following to simplify the followJournal() code:

1. Use Go-native select instead of C-native polling.

2. Use Watch{Producer,Consumer}Gone(), eliminating the need
to have journald.closed variable, and an extra goroutine.

3. Use sd_journal_wait(). In the words of its own man page:

> A synchronous alternative for using sd_journal_get_fd(),
> sd_journal_get_events(), sd_journal_get_timeout() and
> sd_journal_process() is sd_journal_wait().

Unfortunately, the logic is still not as simple as it
could be; the reason being, once the container has exited,
journald might still be writing some logs from its internal
buffers onto journal file(s), and there is no way to
figure out whether it's done so we are guaranteed to
read all of it back. This bug can be reproduced with
something like

> $ ID=$(docker run -d busybox seq 1 150000); docker logs --follow $ID
> ...
> 128123
> $

(The last expected output line should be `150000`).

To avoid exiting from followJournal() early, add the
following logic: once the container is gone, keep trying
to drain the journal until there's no new data for at
least `waitTimeout` time period.

Should fix https://github.com/docker/for-linux/issues/575

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-08-02 10:02:35 -07:00
Kir Kolyshkin
981c01665b Call sd_journal_get_fd() earlier, only if needed
1. The journald client library initializes inotify watch(es)
during the first call to sd_journal_get_fd(), and it make sense
to open it earlier in order to not lose any journal file rotation
events.

2. It only makes sense to call this if we're going to use it
later on -- so add a check for config.Follow.

3. Remove the redundant call to sd_journal_get_fd().

NOTE that any subsequent calls to sd_journal_get_fd() return
the same file descriptor, so there's no real need to save it
for later use in wait_for_data_cancelable().

Based on earlier patch by Nalin Dahyabhai <nalin@redhat.com>.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-08-02 10:02:34 -07:00
Kir Kolyshkin
79039720c8 journald/read: avoid being blocked on send
In case the LogConsumer is gone, the code that sends the message can
stuck forever. Wrap the code in select case, as all other loggers do.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-08-02 10:02:34 -07:00
Kir Kolyshkin
ff3cd167ea journald/read: simplify walking backwards
In case Tail=N parameter is requested, we need to show N lines.
It does not make sense to walk backwards one by one if we can
do it at once. Now, if Since=T is also provided, make sure we
haven't jumped too far (before T), and if we did, move forward.

The primary motivation for this was to make the code simpler.

This also fixes a tiny bug in the "since" implementation.

Before this commit:
> $ docker logs -t --tail=6000 --since="2019-03-10T03:54:25.00" $ID | head
> 2019-03-10T03:54:24.999821000Z 95981

After:
> $ docker logs -t --tail=6000 --since="2019-03-10T03:54:25.00" $ID | head
> 2019-03-10T03:54:25.000013000Z 95982

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-08-02 10:02:34 -07:00
Kir Kolyshkin
e8f6166791 journald/read: simplify code
Minor code simplification.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2019-08-02 10:02:34 -07:00
Nalin Dahyabhai
1ada3e85bf Small journal cleanup
Clean up a deferred function call in the journal reading logic.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-08-02 10:02:34 -07:00
Deep Debroy
a5c420ac54 Be more conservative for Windows in TestFrequency for Splunk
Signed-off-by: Deep Debroy <ddebroy@docker.com>
2019-07-17 13:13:50 -07:00
Justin Cormack
2df693e533
Entropy cannot be saved
Remove non cryptographic randomness.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
2019-06-07 11:54:45 +01:00
Yong Tang
9a2c263743
Merge pull request #38586 from robin-thoni/labels-regex
Use a regex to match labels
2019-04-29 12:25:21 -07:00
Sebastiaan van Stijn
688e67e1d3
bump fluent/fluent-logger-golang v1.4.0
- Add RequestAck to enable at-least-once message transferring
- Add Async option to update sending message in asynchronous way
- Deprecate AsyncConnect (Use Async instead)

full diff: https://github.com/fluent/fluent-logger-golang/compare/v1.3.0...v1.4.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-04-16 11:06:30 +02:00
Sebastiaan van Stijn
c524e15f30
Merge pull request #38952 from alexei38/master
fluentd log driver. failed parse last partial message in fluentd #38951
2019-04-15 20:40:57 +02:00
Alexei Margasov
4a9836a20b Adds PartialLogMetadata to encode protobuf for logger plugins
Signed-off-by: Alexei Margasov <alexei38@yandex.ru>
2019-04-09 16:14:33 +05:00
Alexei Margasov
8997b90c2c fluentd log driver. failed parse last partial message in fluentd #38951
Signed-off-by: Alexei Margasov <alexei38@yandex.ru>
2019-04-09 15:21:08 +05:00
Sebastiaan van Stijn
3449b12cc7
Use assert.NilError() instead of assert.Assert()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-01-21 13:16:02 +01:00
Robin THONI
bc709991b3 Use a regex to match labels
Signed-off-by: Robin THONI <robin@rthoni.com>
2019-01-16 22:17:16 +00:00
Yong Tang
0281db99a9 Follow up to PR 38407
This fix is a follow up to PR 38407 to use assert.Error
and assert.NilError when appropriate

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2019-01-03 01:23:24 +00:00
Yong Tang
626022d0f6
Merge pull request #38407 from maximilianomaccanti/master
Add two configurable options to awslogs driver
2019-01-03 08:48:25 +08:00
Joao Trindade
a7020454ca
Add options validation to syslog logger test
Adds the following validations to the syslog logger test:

 1. Only supported options are valid
 2. Log option syslog-address has to be a valid URI
 3. Log option syslog-address if is file has to exist
 4. Log option syslog-address if udp/tcp scheme, default to port 513
 5. Log-option syslog-facility has to be a valid facility
 6. Log-option syslog-format has to be a valid format

Signed-off-by: Joao Trindade <trindade.joao@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-12-24 20:43:41 +01:00
Maximiliano Maccanti
ad8a8e8a9e NewStreamConfig UTest fixes
Signed-off-by: Maximiliano Maccanti <maccanti@amazon.com>
2018-12-21 22:24:40 +00:00
Maximiliano Maccanti
687cbfa739 Split StreamConfig from New, Utest table driven
Signed-off-by: Maximiliano Maccanti <maccanti@amazon.com>
2018-12-21 20:45:11 +00:00
Maximiliano Maccanti
512ac778bf Add two configurable options to awslogs driver
Add awslogs-force-flush-interval-seconds and awslogs-max-buffered-events configurable options to aswlogs driver to replace hardcoded values of repsectively 5 seconds and 4K.

Signed-off-by: Maximiliano Maccanti <maccanti@amazon.com>
2018-12-21 20:45:11 +00:00
Yong Tang
fa6dabf876 Add zero padding for RFC5424 syslog format
This fix tries to address the issue raised in 38258
where current RFC5424 sys log format does not zero pad
the time (trailing zeros are removed)

This fix apply the patch to fix the issue. This fix fixes 38258.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2018-12-08 22:40:02 +00:00
Sebastiaan van Stijn
758255791e
Merge pull request #38177 from mooncak/fix_duplicate
Cleanup duplication in daemon files
2018-11-13 09:55:51 +01:00
mooncake
345d1fd089 Cleanup duplication in daemon files
Signed-off-by: Bily Zhang <xcoder@tenxcloud.com>
2018-11-13 10:42:57 +08:00
Sebastiaan van Stijn
b48bf39a79
Merge pull request #37944 from IRCody/awslogs_error_context
Return more context on awslogs create failure
2018-10-24 21:00:15 +02:00
Anusha Ragunathan
6611ab1c6f
Merge pull request #37986 from samuelkarp/moby/moby-37747
awslogs: account for UTF-8 normalization in limits
2018-10-18 10:17:24 -07:00
Yong Tang
533e07afbe
Merge pull request #38032 from RohitK89/21497-log-image-name
Add IMAGE_NAME attribute to journald log events
2018-10-17 12:18:05 -07:00
Colin Panisset
5cd2bb315a Only add CONTAINER_PARTIAL_MESSAGE if not the last partial
Addresses #38045

Signed-off-by: Colin Panisset <colin.panisset@cevo.com.au>
2018-10-17 07:51:59 +11:00
Cody Roseborough
7a5c813d9c Return more context on awslogs create failure
Signed-off-by: Cody Roseborough <crrosebo@amazon.com>
2018-10-16 11:36:52 -07:00
Rohit Kapur
5f7e102df7 Add IMAGE_NAME as a key to journald log messages
Signed-off-by: Rohit Kapur <rkapur@flatiron.com>
2018-10-12 16:16:31 -04:00
Samuel Karp
1e8ef38627 awslogs: account for UTF-8 normalization in limits
The CloudWatch Logs API defines its limits in terms of bytes, but its
inputs in terms of UTF-8 encoded strings.  Byte-sequences which are not
valid UTF-8 encodings are normalized to the Unicode replacement
character U+FFFD, which is a 3-byte sequence in UTF-8.  This replacement
can cause the input to grow, exceeding the API limit and causing failed
API calls.

This commit adds logic for counting the effective byte length after
normalization and splitting input without splitting valid UTF-8
byte-sequences into two invalid byte-sequences.

Fixes https://github.com/moby/moby/issues/37747

Signed-off-by: Samuel Karp <skarp@amazon.com>
2018-10-10 14:45:06 -07:00
mooncake
ea60a87fcf Remove duplicated words in daemon files
Signed-off-by: mooncake <xcoder@tenxcloud.com>
2018-10-06 00:06:38 +08:00
Kir Kolyshkin
b2b169f13f daemon/logger/journald: simplify readers field
As in other similar drivers (jsonlog, local), use a set
(i.e. `map[whatever]struct{}`), making the code simpler.

While at it, make sure we remove the reader from the set
after calling `ProducerGone()` on it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-09-10 16:17:05 -07:00
Sebastiaan van Stijn
77faf158f5
Merge pull request #37576 from kolyshkin/logs-f-leak
daemon.ContainerLogs(): fix resource leak on follow
2018-09-10 14:26:43 +02:00
Kir Kolyshkin
9b0097a699 Format code with gofmt -s from go-1.11beta1
This should eliminate a bunch of new (go-1.11 related) validation
errors telling that the code is not formatted with `gofmt -s`.

No functional change, just whitespace (i.e.
`git show --ignore-space-change` shows nothing).

Patch generated with:

> git ls-files | grep -v ^vendor/ | grep .go$ | xargs gofmt -s -w

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-09-06 15:24:16 -07:00
Kir Kolyshkin
f845d76d04 TestFollowLogsProducerGone: add
This should test that
 - all the messages produced are delivered (i.e. not lost)
 - followLogs() exits

Loosely based on the test having the same name by Brian Goff, see
https://gist.github.com/cpuguy83/e538793de18c762608358ee0eaddc197

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-09-06 11:48:37 -07:00
Kir Kolyshkin
916eabd459 daemon.ContainerLogs(): fix resource leak on follow
When daemon.ContainerLogs() is called with options.follow=true
(as in "docker logs --follow"), the "loggerutils.followLogs()"
function never returns (even then the logs consumer is gone).
As a result, all the resources associated with it (including
an opened file descriptor for the log file being read, two FDs
for a pipe, and two FDs for inotify watch) are never released.

If this is repeated (such as by running "docker logs --follow"
and pressing Ctrl-C a few times), this results in DoS caused by
either hitting the limit of inotify watches, or the limit of
opened files. The only cure is daemon restart.

Apparently, what happens is:

1. logs producer (a container) is gone, calling (*LogWatcher).Close()
for all its readers (daemon/logger/jsonfilelog/jsonfilelog.go:175).

2. WatchClose() is properly handled by a dedicated goroutine in
followLogs(), cancelling the context.

3. Upon receiving the ctx.Done(), the code in followLogs()
(daemon/logger/loggerutils/logfile.go#L626-L638) keeps to
send messages _synchronously_ (which is OK for now).

4. Logs consumer is gone (Ctrl-C is pressed on a terminal running
"docker logs --follow"). Method (*LogWatcher).Close() is properly
called (see daemon/logs.go:114). Since it was called before and
due to to once.Do(), nothing happens (which is kinda good, as
otherwise it will panic on closing a closed channel).

5. A goroutine (see item 3 above) keeps sending log messages
synchronously to the logWatcher.Msg channel. Since the
channel reader is gone, the channel send operation blocks forever,
and resource cleanup set up in defer statements at the beginning
of followLogs() never happens.

Alas, the fix is somewhat complicated:

1. Distinguish between close from logs producer and logs consumer.
To that effect,
 - yet another channel is added to LogWatcher();
 - {Watch,}Close() are renamed to {Watch,}ProducerGone();
 - {Watch,}ConsumerGone() are added;

*NOTE* that ProducerGone()/WatchProducerGone() pair is ONLY needed
in order to stop ConsumerLogs(follow=true) when a container is stopped;
otherwise we're not interested in it. In other words, we're only
using it in followLogs().

2. Code that was doing (logWatcher*).Close() is modified to either call
ProducerGone() or ConsumerGone(), depending on the context.

3. Code that was waiting for WatchClose() is modified to wait for
either ConsumerGone() or ProducerGone(), or both, depending on the
context.

4. followLogs() are modified accordingly:
 - context cancellation is happening on WatchProducerGone(),
and once it's received the FileWatcher is closed and waitRead()
returns errDone on EOF (i.e. log rotation handling logic is disabled);
 - due to this, code that was writing synchronously to logWatcher.Msg
can be and is removed as the code above it handles this case;
 - function returns once ConsumerGone is received, freeing all the
resources -- this is the bugfix itself.

While at it,

1. Let's also remove the ctx usage to simplify the code a bit.
It was introduced by commit a69a59ffc7 ("Decouple removing the
fileWatcher from reading") in order to fix a bug. The bug was actually
a deadlock in fsnotify, and the fix was just a workaround. Since then
the fsnofify bug has been fixed, and a new fsnotify was vendored in.
For more details, please see
https://github.com/moby/moby/pull/27782#issuecomment-416794490

2. Since `(*filePoller).Close()` is fixed to remove all the files
being watched, there is no need to explicitly call
fileWatcher.Remove(name) anymore, so get rid of the extra code.

Should fix https://github.com/moby/moby/issues/37391

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-09-06 11:47:42 -07:00
Brian Goff
d37a11bfba daemon/logger/loggerutils: add TestFollowLogsClose
This test case checks that followLogs() exits once the reader is gone.
Currently it does not (i.e. this test is supposed to fail) due to #37391.

[kolyshkin@: test case Brian Goff, changelog and all bugs are by me]
Source: https://gist.github.com/cpuguy83/e538793de18c762608358ee0eaddc197

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-09-06 11:46:34 -07:00
SeungUkLee
a79f8b48d4 fixed typo (becuase -> because)
Signed-off-by: SeungUkLee <lsy931106@gmail.com>
2018-08-26 17:30:40 +09:00
Phil Estes
f962bd06ed
Fix incorrect spelling in error message
Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
2018-08-22 11:28:11 -04:00
Brian Goff
5da8bc2e5b Remove now unused multireader.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-08-20 09:42:19 -07:00
Sebastiaan van Stijn
e0ad6d045c
Merge pull request #37092 from cpuguy83/local_logger
Add "local" log driver
2018-08-20 07:01:41 +01:00
Brian Goff
a351b38e72 Add new local log driver
This driver uses protobuf to store log messages and has better defaults
for log file handling (e.g. compression and file rotation enabled by
default).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-08-17 09:36:56 -07:00
Sebastiaan van Stijn
678d4b3a6d
Merge pull request #37412 from AzureCR/naduggar/logissue
Select polling based watcher for docker log file watcher on Windows
2018-08-14 14:40:44 +02:00
Brian Goff
94a10150f6 Decouple logfile from tailfile.
This makes it so consumers of `LogFile` should pass in how to get an
io.Reader to the requested number of lines to tail.

This is also much more efficient when tailing a large number of lines.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-08-10 21:02:19 -07:00
Kir Kolyshkin
2c6fbd864a loggerutils: fix a typo
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-07-31 15:44:46 +03:00
Kir Kolyshkin
09ad434f10
loggerutils: build fixes, improve errors
There are two build errors when using go-1.11beta1:

> daemon/logger/loggerutils/logfile.go:367: Warningf format %q arg f.Name is a func value, not called
> daemon/logger/loggerutils/logfile.go:564: Debug call has possible formatting directive %v

In the first place, the file name is actually not required as error
message already includes it.

While at it, fix a couple of other places for more correct messages, and
make sure to not add a file name if an error already has it.

Fixes: f69f09f44c
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-07-11 15:52:25 +02:00
Tejaswini Duggaraju
df84cdd091 Select polling based watcher for Windows log watcher
Signed-off-by: Tejaswini Duggaraju <naduggar@microsoft.com>
2018-07-10 10:20:10 -07:00
haikuoliu
998478d369 Pass endpoint to the CloudWatch Logs logging driver
Signed-off-by: haikuoliu <haikuo@amazon.com>
2018-06-29 11:27:37 -07:00
Vincent Demeester
3845728524
Update tests to use gotest.tools 👼
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-13 09:04:30 +02:00
Brian Goff
7c77df8acc Move plugin client to separate interface
This makes it a bit simpler to remove this interface for v2 plugins
and not break external projects (libnetwork and swarmkit).

Note that before we remove the `Client()` interface from `CompatPlugin`
libnetwork and swarmkit must be updated to explicitly check for the v1
client interface as is done int his PR.

This is just a minor tweak that I realized is needed after trying to
implement the needed changes on libnetwork.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-05-30 15:22:10 -04:00
Brian Goff
f51a96c016 Move plugin client creation to the extension point
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-05-25 15:18:53 -04:00
Sebastiaan van Stijn
f23c00d870
Various code-cleanup
remove unnescessary import aliases, brackets, and so on.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-05-23 17:50:54 +02:00
Sebastiaan van Stijn
55bebbaecf
Replace deprecated testutil.ErrorContains()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-05-21 00:13:04 +02:00
Anusha Ragunathan
59698778fe
Merge pull request #37084 from nwneisen/update-ring-buffer-documents
Update documentation for RingLogger's ring buffer
2018-05-17 12:10:44 -07:00
Nick Neisen
3521d534e5 Update documentation for RingLogger's ring buffer
Signed-off-by: Nick Neisen <nwneisen@gmail.com>
2018-05-16 18:52:50 -06:00
Sebastiaan van Stijn
6821ffd1a1
Merge pull request #37028 from cpuguy83/log_plugin_broken_pipe
Fix logging plugin crash unrecoverable
2018-05-15 13:57:01 +02:00
Brian Goff
e7479e3ab8 Fix logging plugin crash unrecoverable
In cases where a logging plugin has crashed when the daemon tries to
copy the container stdio to the logging plugin it returns a broken pipe
error and any log entries that occurr while the plugin is down are lost.

Fix this by opening read+write in the daemon so logs are not lost while
the plugin is down.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-05-14 16:51:56 -04:00
Brian Goff
e87e9e6ad6 Fix some issues in logfile reader and rotation
- Check errors.Cause(err) when comparing errors
- Fix bug where oldest log file is not actually removed. This in
particular causes issues when compression is enabled. On rotate it just
overwrites the data in the log file corrupting it.
- Use O_TRUNC to open new gzip files to ensure we don't corrupt log
files as happens without the above fix.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-05-14 15:52:18 -04:00
Brian Goff
673dd28e7e Add metrics for log failures/partials
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-05-10 17:22:37 -04:00
Sebastiaan van Stijn
daaef83cd2
Fix fluentd partial detection
The Partial property of the Logger message
was replaced by PLogMetaData, causing the build to fail.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-05-10 01:55:27 +02:00
Sebastiaan van Stijn
fff01bc14d
Merge pull request #36159 from cosmo0920/add-partial-flag-into-record
Fluentd Log Driver: Add partial flag into record
2018-05-09 21:01:05 +02:00
Brian Goff
fe2d3a1551
Merge pull request #36522 from IRCody/awslogs-non-blocking
Allow awslogs to use non-blocking mode
2018-05-01 16:30:52 -04:00
Cody Roseborough
c7e379988c Allow awslogs to use non-blocking mode
When then non-blocking mode is specified, awslogs will:

- No longer potentially block calls to logstream.Log(), instead will
  return an error if the awslogs buffer is full. This has the effect of
  dropping log messages sent to awslogs.Log() that are made while the
  buffer is full.
- Wait to initialize the log stream until the first Log() call instead of in
  New(). This has the effect of allowing the container to start in
  the case where Cloudwatch Logs is unreachable.

Both of these changes require the --log-opt mode=non-blocking to be
explicitly set and do not modify the default behavior.

Signed-off-by: Cody Roseborough <crrosebo@amazon.com>
2018-04-27 17:59:03 +00:00
Kir Kolyshkin
7d62e40f7e Switch from x/net/context -> context
Since Go 1.7, context is a standard package. Since Go 1.9, everything
that is provided by "x/net/context" is a couple of type aliases to
types in "context".

Many vendored packages still use x/net/context, so vendor entry remains
for now.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-04-23 13:52:44 -07:00
Tibor Vass
61138fb5fc
Merge pull request #35739 from thaJeztah/bump-go-1.10
Bump Golang to 1.10.1
2018-04-13 13:56:38 -10:00
Derek McGowan
c208f1c8a8
Update logger adapter test to avoid race
Add synchronization around adding logs to a plugin
and reading those logs. Without the follow configuration,
a race occurs between go routines to add the logs into
the plugin and read the logs out of the plugin. This
adds a function to synchronize the action to avoid the
race.
Removes use of file for buffering, instead buffering whole
messages so log count can be checked discretely.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-04-12 13:35:15 -07:00
Anusha Ragunathan
0b4b0a7b5d Improve partial message support in logger
Docker daemon has a 16K buffer for log messages. If a message length
exceeds 16K, it should be split by the logger and merged at the
endpoint.

This change adds `PartialLogMetaData` struct for enhanced partial support
- LastPartial (bool) : indicates if this is the last of all partials.
- ID (string)        : unique 32 bit ID. ID is same across all partials.
- Ordinal (int starts at 1) : indicates the position of msg in the series of partials.
Also, the timestamps across partials in the same.

Signed-off-by: Anusha Ragunathan <anusha.ragunathan@docker.com>
2018-04-11 13:26:28 -07:00
Brian Goff
c4e93da8a6
Merge pull request #29932 from miaoyq/container-log-add-archive
add support for compressibility of log file
2018-03-19 15:20:17 -04:00
Daniel Nephin
c9e52bd0da Post migration assertion fixes
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-16 11:03:46 -04:00
Daniel Nephin
6be0f70983 Automated migration using
gty-migrate-from-testify --ignore-build-tags

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-16 11:03:43 -04:00
Daniel Nephin
ef01dea893 Cleanup some assertions
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-16 10:54:54 -04:00
Yanqiang Miao
f69f09f44c add compress option for 'jsonfiles' log driver
This PR adds support for compressibility of log file.
I added a new option conpression for the jsonfile log driver,
this option allows the user to specify compression algorithm to
compress the log files. By default, the log files will be
not compressed. At present, only support 'gzip'.

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>

'docker logs' can read from compressed files

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>

Add Metadata to the gzip header, optmize 'readlog'

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
2018-03-15 20:20:05 +08:00
Benjamin Yolken
d0c1287a8d
Make logfile perms configurable
Signed-off-by: Benjamin Yolken <yolken@stripe.com>
2018-03-07 15:18:51 -08:00
Cody Roseborough
a1956b5623 daemon/logger/ring.go: log error not instance
Log the error returned from logdriver.Log() instead of the logdriver
itself.

Signed-off-by: Cody Roseborough <crrosebo@amazon.com>
2018-03-03 16:29:57 +00:00
Brian Goff
a1afe38e52
Merge pull request #36272 from mnussbaum/36255-fix_log_path
Fix empty LogPath with non-blocking logging mode
2018-02-27 11:25:39 -05:00
Sebastiaan van Stijn
20028325da
Merge pull request #35829 from cpuguy83/no_private_mount_for_plugins
Perform plugin mounts in the runtime
2018-02-21 12:28:13 +01:00
junzhe and mnussbaum
20ca612a59 Fix empty LogPath with non-blocking logging mode
This fixes an issue where the container LogPath was empty when the
non-blocking logging mode was enabled. This change sets the LogPath on
the container as soon as the path is generated, instead of setting the
LogPath on a logger struct and then attempting to pull it off that
logger at a later point. That attempt to pull the LogPath off the logger
was error prone since it assumed that the logger would only ever be a
single type.

Prior to this change docker inspect returned an empty string for
LogPath. This caused issues with tools that rely on docker inspect
output to discover container logs, e.g. Kubernetes.

This commit also removes some LogPath methods that are now unnecessary
and are never invoked.

Signed-off-by: junzhe and mnussbaum <code@getbraintree.com>
2018-02-20 23:12:34 -08:00
Weerasak Chongnguluam
6e5fba98a5 Remove unused method from multireader package
Signed-off-by: Weerasak Chongnguluam <singpor@gmail.com>
2018-02-15 23:10:56 +07:00
Brian Goff
f40860c5f3 Fix log tail with empty logs
When tailing a container log, if the log file is empty it will cause the
log stream to abort with an unexpected `EOF`.
Note that this only applies to the "current" log file as rotated files
cannot be empty.

This fix just skips adding the "current" file the log tail if it is
empty.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-02-13 21:33:05 -05:00
bin liu
b00a67be6e Fix typos in daemon
Signed-off-by: bin liu <liubin0329@gmail.com>
2018-02-10 19:42:54 +08:00
Vincent Demeester
f653485e57
Merge pull request #36220 from dnephin/support-proxy-in-splunk-driver
Support a proxy in splunk log driver
2018-02-08 15:32:19 +01:00
Brian Goff
0e5eaf8ee3 Ensure plugin returns correctly scoped paths
Before this change, volume management was relying on the fact that
everything the plugin mounts is visible on the host within the plugin's
rootfs. In practice this caused some issues with mount leaks, so we
changed the behavior such that mounts are not visible on the plugin's
rootfs, but available outside of it, which breaks volume management.

To fix the issue, allow the plugin to scope the path correctly rather
than assuming that everything is visible in `p.Rootfs`.
In practice this is just scoping the `PropagatedMount` paths to the
correct host path.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-02-07 15:48:27 -05:00
Daniel Nephin
3c4537d5b3 Support a proxy in splunk log driver
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-02-07 14:52:32 -05:00
Daniel Nephin
4f0d95fa6e Add canonical import comment
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-02-05 16:51:57 -05:00
Hiroshi Hatake
3ed3b33e55 Fluentd Log Driver: Add partial flag into record
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
2018-01-31 11:52:03 +09:00
Yong Tang
a636ed5ff4
Merge pull request #36078 from mixja/multiline-max-event-processing
awslogs - don't add new lines to maximum sized events
2018-01-24 12:06:49 -08:00
Justin Menga
d3e2d55a3d Don't append new line for maximum sized events
Signed-off-by: Justin Menga <justin.menga@gmail.com>
2018-01-21 14:29:55 +13:00
Yong Tang
e77267c5a6 Carry 34248 Added tag log option to json-logger and use RawAttrs
This fix carries PR 34248: Added tag log option to json-logger

This fix changes to use RawAttrs based on review feedback.

This fix fixes 19803, this fix closes 34248.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2018-01-19 17:51:20 +00:00
bonczj
5f50f4f511 Added tag log option to json-logger
Fixes #19803
Updated the json-logger to utilize the common log option
'tag' that can define container/image information to include
as part of logging.

When the 'tag' log option is not included, there is no change
to the log content via the json-logger. When the 'tag' log option
is included, the tag will be parsed as a template and the result
will be stored within each log entry as the attribute 'tag'.

Update: Removing test added to integration_cli as those have been deprecated.
Update: Using proper test calls (require and assert) in jsonfilelog_test.go based on review.
Update: Added new unit test configs for logs with tag. Updated unit test error checking.
Update: Cleanup check in jsonlogbytes_test.go to match pending changes in PR #34946.
Update: Merging to correct conflicts from PR #34946.

Signed-off-by: bonczj <josh.bonczkowski@gmail.com>
2018-01-19 17:41:19 +00:00
Yong Tang
39faf2a3a8
Merge pull request #35509 from cpuguy83/splunk_dont_readall
Splunk: limit the reader size on error responses
2018-01-05 12:34:35 -08:00
Sebastiaan van Stijn
d80c13a541
Merge pull request #35570 from zemanlx/feature/journald-with-SYSLOG_IDENTIFIER
Add journald tag as SYSLOG_IDENTIFIER
2018-01-05 20:56:55 +01:00