Add comprehensive test cases to validate the k8s-file log rotation fix that
prevents buffer corruption during log rotation (commit 29d17be). The original
issue manifested as corrupted log entries with repeated timestamps and broken
formatting when logs exceeded the configured max_size.
New test coverage includes:
- Small log size limit validation (50-100 bytes) to trigger rotation scenarios
- Edge case testing with various rotation thresholds (1B to 10KB)
- Log file creation and content integrity validation
- Stress testing with extremely small rotation limits
- Validation that log files can handle proper k8s format content
Signed-off-by: Jindrich Novy <jnovy@redhat.com>
- Add tests for log-size-max option acceptance and validation
- Test k8s-file log driver with size limits and multiple drivers
- Verify proper log file creation and format handling
- Add WithLogSizeMax() option to conmon Go API for testing
Tests ensure the writev_buffer_flush corruption fix in commit 29d17be
works correctly and log rotation doesn't corrupt k8s log entries.
Signed-off-by: Jindrich Novy <jnovy@redhat.com>
The k8s-file log driver was corrupting log entries when the log file
reached max_size and needed rotation. This manifested as garbled output
with repeated timestamps and broken log entries.
The root cause was in writev_buffer_flush() which incorrectly handled
partial writes. When writev() returned a partial write, the function
would modify the original iovec base pointers, corrupting the buffer
state. During log rotation, this corrupted state would carry over to
the new file descriptor, causing subsequent log entries to be malformed.
Changes:
- Simplify writev_buffer_flush() to use individual write() calls instead
of complex writev() partial write handling
- Always reset buffer state after log rotation to ensure clean state
with new file descriptor
- Remove conditional buffer reset that could leave corrupted state
This fixes the issue where long-running containers (like GitLab CE)
would produce corrupted logs after reaching the configured max_size.
Fixes: Log corruption with --log-driver k8s-file --log-opt max_size=20mb
Signed-off-by: Jindrich Novy <jnovy@redhat.com>
The fix ensures each complete line in the control buffer
is processed exactly once by passing the correct line
start position to the processing function and properly
null-terminating each line.
Signed-off-by: Sohan Kunkerkar <sohank2602@gmail.com>
At present it's not possible to ship properly labeled logs when using
podman and tools like podman-compose. Container labels are lost which
makes it much harder to understand where a particular log line
originated from. Log processing and analysis is significantly more
inconvenient as well, because it's hard to group related logs, e.g.
coming from the same compose project.
This commit implements the parts necessary to annotate log messages with
container labels. Each label and value pair is specified via --log-label
LABEL=VALUE arguments.
Co-authored-by: OZoneGuy <oalkersh@protonmail.com>
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
The sole reason of having this was to produce a nice informative error
message in case of failure (and because the message was not explicitly
specified, it was entirely wrong in 1 of 2 use cases).
Let's drop it and just use git to fail the job if a tree is dirty.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This repo never had ./vendor committed, so it's of little use,
especially with modern Go caching and proxying. So, let's remove
"go mod vendor" from the make's vendor target, and also remove
"make vendor" from the integration / conmon CI job.
Instead, add a separate GHA job to check for go.mod/go.sum correctness.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Apparently, since the master branch was renamed to main a few years
back, GHA CI jobs no longer run when a PR is merged.
Fix that. While at it, add some vertical whitespace.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
The version of go-md2man is quite old, and is not really need to be in
this repository. It is only used by `make docs` which does not make
sense to run in CI, as we don't check the resulting man page.
PS if needed, it is easy to install by this one-liner:
go install github.com/cpuguy83/go-md2man/v2@latest
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Because actions/setup-go does its own caching now, adding our own:
- unnecessarily complicates things;
- results in double caching.
Remove it.
Note that a single common cache will be used between the two jobs (which
is OK).
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Apparently the code is well formatted, except for 0oNNN for octal
numbers (available since Go 1.13).
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
The testing.TempDir function is available since Go 1.15.
Since tests are written using ginkgo, use GinkgoT to obtain
*testing.T.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
The io/ioutil package is deprecated since Go 1.16,
so let's switch to os for ReadFile and WriteFile.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
The github.com/pkg/errors is frozen since November 2021, and %w for
fmt.Errorf is available since Go 1.13 (September 2019).
Switch from pkg/errors to Go native way of wrapping errors.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
While %m is GNU extension, it is also supported by alternative libc
versions (uclibc, musl) as well as by FreeBSD 12+.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
In here, error and errorf print strerror(errno), but the only case
errno is set is when malloc() fails (and the errno is invariably
ENOMEM so it doesn't make much sense to print it anyway).
1. Remove adding strerror(errno) from these macros.
2. Redefine error via errorf to simplify.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1. Use nwarn instead of pwarn since we're not interested in errno here.
2. Add some context to the message.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
If, for whatever reason, quering current time fails
then the whole log message is dropped.
This PR assures the log message is not lost and
the output is done with the default timestamp.
Signed-off-by: Jindrich Novy <jnovy@redhat.com>
Changing log permissions to 0640 would allow the administrator to
set sticky group on the log directory, and for a selected
log-users (in a specific group) without root-permissions to
read the log files.
Fixes#539
Signed-off-by: Jindrich Novy <jnovy@redhat.com>
Issue #454 is likely caused by retryable_error()
not catching all possible retriable errors from
the write(2) syscall.
This PR should be FeeBSD compatible. The only
retriable result in question is ENOBUFS which
might be bound to network latencies. Hope
these are acceptable.
Signed-off-by: Jindrich Novy <jnovy@redhat.com>