canonical / pebble

Pebble is a lightweight Linux service manager with layered configuration and an HTTP API.
https://canonical-pebble.readthedocs-hosted.com/
GNU General Public License v3.0
146 stars 54 forks source link

pebble logs fails when there is a long line (over 4k characters) #376

Closed javierdelapuente closed 6 months ago

javierdelapuente commented 7 months ago

When running pebble logs, when there is a line with a log over 4KiB, it fails with the error (and does not show next lines):

$ PEBBLE_SOCKET=~/pebble/.pebble.socket go run ./cmd/pebble logs srv1
error: cannot read log line: bufio: buffer full
exit status 1

This is easily reproducible with a plan like this one:

summary: Simple layer

description: |
    A better description for a simple layer.

services:
    srv1:
        override: replace
        summary: logs more than 4k characters
        command: bash -c "echo {1..1100}; echo "not available in logs"; sleep 10;"
        startup: enabled

Although long, this line size is not uncommon for a log. https://github.com/canonical/pebble/blob/95b73bb24eafa386ad4924abb57ffae9b5ef4501/client/logs.go#L30

An alternative to a bigger constant could be to print up to a fixed number of characters and skip the rest of the line.

benhoyt commented 7 months ago

Thanks for the report.

Yes, it does seem a bit brutal to error out and fail in this case. It should at least try/truncate/skip (and print a warning?). The error is from the ReadSlice call in client/logs.go returning bufio.ErrBufferFull, so we'll need to handle that case specially (for comparison, the bufio.ErrBufferFull case is handled specially in servicelog.Parser).