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

fix: allow for the JSON overhead when reading log lines #384

Closed tonyandrewmeyer closed 6 months ago

tonyandrewmeyer commented 6 months ago

The server caps lines at 4096 characters, but the client receives these as JSON, so when receiving there's an extra ~70 characters that make up the timestamp, service name, field names, and JSON punctuation. This means that limiting the slice size to 4096 characters there will result in buffer full errors.

Allow an extra 1024 characters for the JSON 'overhead' - this should be far more than needed, but is only used within the logs function - I wasn't able to find any maximum length for a service name, so a precise extra count is tricky. This could be lowered (I would guess 128 characters would usually be sufficient) if this might be too much memory in some Pebble use cases.

Also adds tests for the long log line cases.

Fixes #376