Skip to content

Commit 40f80f0

Browse files
Sync docs from Discourse (#577)
Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 84deb1f commit 40f80f0

File tree

2 files changed

+32
-60
lines changed

2 files changed

+32
-60
lines changed

docs/explanation/e-audit-logs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ It's recommended to integrate the charm with [COS](/t/9900), from where the logs
2525
```
2626
Valid value are `false` and `true`. By setting it to false, existing logs are still kept in the `archive_audit` directory.
2727

28+
1. `logs_audit_policy` - Audit log policy:
29+
30+
```bash
31+
juju config mysql-k8s logs_audit_policy=queries
32+
```
33+
Valid values are: "all", "logins" (default), "queries"
34+
2835
1. `plugin-audit-strategy` - By default the audit plugin writes logs in asynchronous mode for better performance.
2936
To ensure logs are written to disk on more timely fashion, this configuration can be set to semi-synchronous mode:
3037

docs/explanation/e-logs.md

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,39 @@
22

33
This explanation goes over the types of logging in MySQL and the configuration parameters for log rotation.
44

5-
The charm currently has audit, error and general logs enabled by default, while slow query logs are disabled by default. All of these files are rotated if present into a separate dedicated archive folder under the logs directory.
5+
The charm currently has audit and error logs enabled by default. All of these files are rotated if present into a separate dedicated archive folder under the logs directory. We do not yet support the rotation of binary logs (binlog, relay log, undo log, redo log, etc).
66

77
We do not yet support the rotation of binary logs (binlog, relay log, undo log, redo log, etc).
88

99
## Summary
1010
* [Log types](#log-types)
1111
* [Audit logs](#audit-logs)
1212
* [Error logs](#error-logs)
13-
* [General logs](#general-logs)
14-
* [Slowquery logs](#slowquery-logs)
1513
* [Log rotation configuration](#log-rotation-configuration)
1614
* [High Level Design](#high-level-design)
1715

1816
---
1917

2018
## Log types
2119

22-
The charm stores its logs in `/var/snap/charmed-mysql/common/var/log/mysql`.
20+
The charm stores its logs in `/var/log/mysql`.
2321

2422
```shell
25-
$ ls -lahR /var/snap/charmed-mysql/common/var/log/mysql
23+
$ ls -lahR /var/log/mysql
2624

2725
/var/log/mysql:
2826
drwxrwx--- 2 mysql mysql 4.0K Oct 23 20:46 archive_audit
2927
drwxrwx--- 2 mysql mysql 4.0K Oct 23 20:46 archive_error
30-
drwxrwx--- 2 mysql mysql 4.0K Oct 23 20:46 archive_general
31-
drwxrwx--- 2 mysql mysql 4.0K Oct 23 20:45 archive_slowquery
3228
-rw-r----- 1 mysql mysql 1.1K Oct 23 20:46 audit.log
3329
-rw-r----- 1 mysql mysql 1.1K Oct 23 20:46 error.log
34-
-rw-r----- 1 mysql mysql 1.7K Oct 23 20:46 general.log
3530

36-
/var/snap/charmed-mysql/common/var/log/mysql/archive_audit:
37-
-rw-r----- 1 snap_daemon root 43K Sep 3 01:24 audit.log-20240903_0124
38-
-rw-r----- 1 snap_daemon root 109K Sep 3 01:25 audit.log-20240903_0125
31+
/var/log/mysql/archive_audit:
32+
-rw-r----- 1 snap_daemon root 43K Sep 3 01:24 audit.log-20240903_0124.gz
33+
-rw-r----- 1 snap_daemon root 109K Sep 3 01:25 audit.log-20240903_0125.gz
3934

40-
/var/snap/charmed-mysql/common/var/log/mysql/archive_error:
41-
-rw-r----- 1 mysql mysql 8.7K Oct 23 20:44 error.log-43_2045
42-
-rw-r----- 1 mysql mysql 2.3K Oct 23 20:45 error.log-43_2046
43-
44-
/var/snap/charmed-mysql/common/var/log/mysql/archive_general:
45-
-rw-r----- 1 mysql mysql 8.0M Oct 23 20:45 general.log-43_2045
46-
-rw-r----- 1 mysql mysql 4.6K Oct 23 20:46 general.log-43_2046
47-
48-
/var/snap/charmed-mysql/common/var/log/mysql/archive_slowquery:
35+
/var/log/mysql/archive_error:
36+
-rw-r----- 1 mysql mysql 8.7K Oct 23 20:44 error.log-43_2045.gz
37+
-rw-r----- 1 mysql mysql 2.3K Oct 23 20:45 error.log-43_2046.gz
4938
```
5039

5140
It is recommended to set up a [COS integration] so that these log files can be streamed to Loki. This leads to better persistence and security of the logs.
@@ -112,51 +101,27 @@ For more details, see the [Audit Logs explanation].
112101
```
113102
</details>
114103
115-
### General logs
116-
117-
<details>
118-
<summary>Example of general logs, with format <code>time thread_id command_type query_body</code></summary>
119-
```shell
120-
Time Id Command Argument
121-
2023-10-23T20:50:02.023329Z 94 Quit
122-
2023-10-23T20:50:02.667063Z 95 Connect
123-
2023-10-23T20:50:02.667436Z 95 Query /* xplugin authentication */ SELECT /*+ SET_VAR(SQL_MODE = 'TRADITIONAL') */ @@require_secure_transport, `authentication_string`, `plugin`, (`account_locked
124-
`='Y') as is_account_locked, (`password_expired`!='N') as `is_password_expired`, @@disconnect_on_expired_password as `disconnect_on_expired_password`, @@offline_mode and (`Super_priv`='N') as `is_offline_
125-
mode_and_not_super_user`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject` FROM mysql.user WHERE 'serverconfig' = `user` AND '%' = `host`
126-
2023-10-23T20:50:02.668277Z 95 Query /* xplugin authentication */ SELECT /*+ SET_VAR(SQL_MODE = 'TRADITIONAL') */ @@require_secure_transport, `authentication_string`, `plugin`, (`account_locked
127-
`='Y') as is_account_locked, (`password_expired`!='N') as `is_password_expired`, @@disconnect_on_expired_password as `disconnect_on_expired_password`, @@offline_mode and (`Super_priv`='N') as `is_offline_
128-
mode_and_not_super_user`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject` FROM mysql.user WHERE 'serverconfig' = `user` AND '%' = `host`
129-
2023-10-23T20:50:02.668778Z 95 Query select @@lower_case_table_names, @@version, connection_id(), variable_value from performance_schema.session_status where variable_name = 'mysqlx_ssl_cipher'
130-
2023-10-23T20:50:02.669991Z 95 Query SET sql_log_bin = 0
131-
2023-10-23T20:50:02.670389Z 95 Query FLUSH SLOW LOGS
132-
2023-10-23T20:50:02.670924Z 95 Quit
133-
```
134-
</details>
104+
## Log rotation configuration
135105
136-
### Slowquery logs
106+
Following the configuration options exposed by the charm:
137107
138-
<details>
139-
<summary>Example of a slowquery log</summary>
140-
```shell
141-
Time Id Command Argument
142-
# Time: 2023-10-23T22:22:47.564327Z
143-
# User@Host: serverconfig[serverconfig] @ localhost [127.0.0.1] Id: 21
144-
# Query_time: 15.000332 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 1
145-
SET timestamp=1698099752;
146-
do sleep(15);
147-
```
148-
</details>
108+
| Configuration option | Description | Default value |
109+
| --- | --- | --- |
110+
| `plugin-audit-enabled` | Enable or disable the audit log | `true` |
111+
| `logs_audit_policy` | The audit log policy ("all", "logins", "queries") | `logins` |
112+
| `logs_retention_period` | The number of days to keep the rotated logs | `auto` |
149113
150-
## Log rotation configuration
114+
The `logs_retention_period` option accepts an integer value of 3 or greater, or the special value
115+
`auto`. When set to "auto" (default), the retention period is 3 days, except when COS-related,
116+
where it is 1 day
151117
152-
For each log (audit, error, general and slow query):
118+
For each log (audit, error):
153119
154120
- The log file is rotated every minute (even if the log files are empty)
155121
- The rotated log file is formatted with a date suffix of `-%V-%H%M` (-weeknumber-hourminute)
156-
- The rotated log files are not compressed or mailed
122+
- The rotated log files are compressed but not mailed
157123
- The rotated log files are owned by the `snap_daemon` user and group
158-
- The rotated log files are retained for a maximum of 7 days before being deleted
159-
- The most recent 10080 rotated log files are retained before older rotated log files are deleted
124+
- By default the rotated log files are retained for 3 days before being deleted, but this can be configured.
160125
161126
The following are logrotate config values used for log rotation:
162127
@@ -171,15 +136,15 @@ The following are logrotate config values used for log rotation:
171136
| `dateformat` | -%V-%H%M |
172137
| `ifempty` | true |
173138
| `missingok` | true |
174-
| `nocompress` | true |
139+
| `compress` | true |
175140
| `nomail` | true |
176141
| `nosharedscripts` | true |
177142
| `nocopytruncate` | true |
178-
| `olddir` | archive_error / archive_general / archive_slowquery |
143+
| `olddir` | archive_<log_name> |
179144
180145
## High Level Design
181146
182-
There is a cron job on the machine where the charm exists that is triggered every minute and runs `logrotate`. The logrotate utility does *not* use `copytruncate`. Instead, the existing log file is moved into the archive directory by logrotate, and then the logrotate's postrotate script invokes `juju-run` (or `juju-exec` depending on the juju version) to dispatch a custom event. This custom event's handler flushes the MySQL log with the [FLUSH](https://dev.mysql.com/doc/refman/8.0/en/flush.html) statement that will result in a new and empty log file being created under `/var/snap/charmed-mysql/common/var/log/mysql` and the rotated file's descriptor being closed.
147+
There is a cron job on the machine where the charm exists that is triggered every minute and runs `logrotate`. The logrotate utility does *not* use `copytruncate`. Instead, the existing log file is moved into the archive directory by logrotate, and then the logrotate's postrotate script invokes `juju-run` (or `juju-exec` depending on the juju version) to dispatch a custom event. This custom event's handler flushes the MySQL log with the [FLUSH](https://dev.mysql.com/doc/refman/8.0/en/flush.html) statement that will result in a new and empty log file being created under `/var/log/mysql` and the rotated file's descriptor being closed.
183148
184149
We use a custom event in juju to execute the FLUSH statement in order to avoid storing any credentials on the disk. The charm code has a mechanism that will retrieve credentials from the peer relation databag or juju secrets backend, if available, and keep these credentials in memory for the duration of the event handler.
185150

0 commit comments

Comments
 (0)