Bug 56048 - [Kelvin] fix log rotation | http.log - entries from the same date appear in different log files
[Kelvin] fix log rotation | http.log - entries from the same date appear in d...
Status: NEW
Product: UCS@school
Classification: Unclassified
Component: HTTP-API (Kelvin)
UCS@school 5.0
Other Linux
: P5 normal (vote)
: ---
Assigned To: Julian Helms
:
Depends on:
Blocks: 56635
  Show dependency treegraph
 
Reported: 2023-05-09 13:02 CEST by Julian Helms
Modified: 2024-02-15 18:13 CET (History)
3 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 3: Simply Wrong: The implementation doesn't match the docu
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 3: A User would likely not purchase the product
User Pain: 0.103
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Helms univentionstaff 2023-05-09 13:02:13 CEST
The rotation of the `http.log` behaves in a weird way. Entries from the same date appear in different "old" logs.

Example:

```
DEV root@ucs-001:/var/log/univention/ucsschool-kelvin-rest-api# ls -lrt
[...]
-rw------- 1 root root     25501 Mai  7 02:00 http.log.2023-05-06
-rw------- 1 root root     43403 Mai  9 02:00 http.log.2023-05-07
-rw------- 1 root root    365887 Mai  9 08:25 ucs-school-validation.log.2023-05-05
-rw------- 1 root root    590863 Mai  9 10:43 http.log.2023-05-08
-rw------- 1 root root   5515993 Mai  9 12:33 ucs-school-validation.log
-rw-r----- 1 root root 305397697 Mai  9 12:36 opa.log
-rw------- 1 root root  28963364 Mai  9 12:36 http.log
DEV root@ucs-001:/var/log/univention/ucsschool-kelvin-rest-api# grep -c 2023-05-09 *
http.log:123443
http.log.2023-05-07:33
http.log.2023-05-08:3254
```
Comment 1 Daniel Tröder univentionstaff 2023-10-18 08:38:45 CEST
Fix suggestion: Follow the App Centers example in #55610 and

1. install a logrotate configuration in the host using UCRV without a service restart
2. use logging.handlers.WatchedFileHandler (https://devdocs.io/python~3.11/library/logging.handlers#logging.handlers.WatchedFileHandler) inside Docker container.

From the docs:

emit(): Outputs the record to the file, but first calls reopenIfNeeded() to reopen the file if it has changed.

reopenIfNeeded(): Checks to see if the file has changed. If it has, the existing stream is flushed and closed and the file opened again, typically as a precursor to outputting the record to the file.

So renaming the logfile (from the host) leads to the Python process - the next time it wants to write a message (!) - flushing its buffers to the renamed file and then creating a new file for the new message. If the renamed file is not compressed immediately there should be no data loss.

---

If this fixes the logrotation issue for Kelvin, apply this fix also to all other UCS@school Python Docker apps like the UCS@school APIs app and the ID-Connector.