[MXS-4098] maxctrl rotate logs not working Created: 2022-04-19  Updated: 2024-02-05  Resolved: 2022-04-20

Status: Closed
Project: MariaDB MaxScale
Component/s: Core
Affects Version/s: 2.5.19
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Juan Assignee: Niclas Antti
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

See https://jira.mariadb.org/browse/MXS-2895

configure maxscale qla filter:

[query_logger]
type=filter
module=qlafilter
filebase=/var/log/maxscale/query_log
log_type=unified
flush=true
log_data=date, session, user, default_db, reply_time, query
 
[Router]
.
.
filters=query_logger

configure logrotate:

vim /etc/logrotate.d/maxscale_query
 
/var/log/maxscale/query_log.unified {
	rotate 99
	size 1k
	create 700 maxscale maxscale
}

add some data to log:

for i in {1..33}
do
    for j in {1..32}
    do
        echo "x">>/var/log/maxscale/query_log.unified
    done
done

maxscale# ls -alrth
total 1.9M
-rw-r--r--  1 maxscale maxscale  35K May  7  2021 maxscale.log-20210507
-rw-r--r--  1 maxscale maxscale 1.8M Jun  1  2021 maxscale.log-20210601
-rw-r--r--  1 maxscale maxscale  48K Jul  1  2021 maxscale.log-20210701
-rw-r--r--  1 maxscale maxscale 4.2K Aug  1  2021 maxscale.log-20210801
-rw-r--r--  1 maxscale maxscale  14K Apr 18 20:12 maxscale.log-20220418
drwxr-xr-x. 9 root     root     4.0K Apr 18 20:12 ..
-rw-r--r--  1 maxscale maxscale  630 Apr 18 20:33 maxscale.log
drwxr-xr-x  2 maxscale maxscale  196 Apr 18 20:34 .
-rw-r--r--  1 root     root     2.1K Apr 18 20:34 query_log.unified

rotate the log

maxscale# logrotate -f /etc/logrotate.d/maxscale_query
maxscale# maxctrl rotate logs
OK
maxscale# 

Now run some updates:

~# for i in {1..20}
> do
> mysql -h 10.0.0.96 -u max -pmax -ABNe 'insert into simple(blah) values(now());' test
> done

rotate the log again

maxscale# logrotate -f /etc/logrotate.d/maxscale_query
maxscale# maxctrl rotate logs
OK
maxscale# 

Run another update:

~# mysql -h 10.0.0.96 -u max -pmax -ABNe 'insert into simple(blah) values(now());' test

This is the result:

maxscale# ls -alh
total 1.9M
drwxr-xr-x  2 maxscale maxscale  250 Apr 18 20:38 .
drwxr-xr-x. 9 root     root     4.0K Apr 18 20:12 ..
-rw-r--r--  1 maxscale maxscale 4.8K Apr 18 20:38 maxscale.log
-rw-r--r--  1 maxscale maxscale  35K May  7  2021 maxscale.log-20210507
-rw-r--r--  1 maxscale maxscale 1.8M Jun  1  2021 maxscale.log-20210601
-rw-r--r--  1 maxscale maxscale  48K Jul  1  2021 maxscale.log-20210701
-rw-r--r--  1 maxscale maxscale 4.2K Aug  1  2021 maxscale.log-20210801
-rw-r--r--  1 maxscale maxscale  14K Apr 18 20:12 maxscale.log-20220418
-rwx------  1 maxscale maxscale    0 Apr 18 20:38 query_log.unified
-rwx------  1 maxscale maxscale 2.0K Apr 18 20:39 query_log.unified.1
-rw-r--r--  1 root     root     2.1K Apr 18 20:34 query_log.unified.2
maxscale# tail -n 2 query_log.unified.1
20,2022-04-18 20:38:31,max@::ffff:10.0.0.95,15,insert into simple(blah) values(now()),test
21,2022-04-18 20:39:02,max@::ffff:10.0.0.95,19,insert into simple(blah) values(now()),test

Note how in this second rotation MaxScale did not release the handle to the file now named query_log.unified.1, and continues to write to it.

Even if I run maxctrl rotate logs again, MaxScale continues to write to the old file:

maxscale# tail -n 2 query_log.unified.1
21,2022-04-18 20:39:02,max@::ffff:10.0.0.95,19,insert into simple(blah) values(now()),test
22,2022-04-18 20:46:42,max@::ffff:10.0.0.95,18,insert into simple(blah) values(now()),test
maxscale# maxctrl rotate logs
OK
maxscale# tail -n 2 query_log.unified.1
22,2022-04-18 20:46:42,max@::ffff:10.0.0.95,18,insert into simple(blah) values(now()),test
23,2022-04-18 20:47:14,max@::ffff:10.0.0.95,18,insert into simple(blah) values(now()),test



 Comments   
Comment by Niclas Antti [ 2022-04-20 ]

The problem is in the rotation conf. The conf should not create the log file, only rotate existing files. This will work:

/var/log/maxscale/query_log.unified {    
    rotate 99
    size 1k
}

A more comprehensive entry that also causes maxscale to rotate (i.e. no need to run "maxctrl rotate logs"):

/var/log/maxscale/query_log.unified {
    rotate 99
    size 1k
    missingok
    nocompress
    nocreate
    postrotate
    test -r /var/run/maxscale/maxscale.pid && kill -USR1 $(cat /var/run/maxscale/maxscale.pid)
    endscript
}

Generated at Thu Feb 08 04:26:11 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.