Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/mysql/plugin_audit.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@
extern struct thd_timezone_service_st {
my_time_t (*thd_TIME_to_gmt_sec)(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void (*thd_gmt_sec_to_TIME)(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void (*thd_TIME_to_str)(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
} *thd_timezone_service;
my_time_t thd_TIME_to_gmt_sec(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void thd_gmt_sec_to_TIME(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void thd_TIME_to_str(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
}
extern "C" {
typedef enum _thd_wait_type_e {
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_auth.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@
extern struct thd_timezone_service_st {
my_time_t (*thd_TIME_to_gmt_sec)(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void (*thd_gmt_sec_to_TIME)(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void (*thd_TIME_to_str)(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
} *thd_timezone_service;
my_time_t thd_TIME_to_gmt_sec(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void thd_gmt_sec_to_TIME(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void thd_TIME_to_str(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
}
extern "C" {
typedef enum _thd_wait_type_e {
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_data_type.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@
extern struct thd_timezone_service_st {
my_time_t (*thd_TIME_to_gmt_sec)(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void (*thd_gmt_sec_to_TIME)(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void (*thd_TIME_to_str)(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
} *thd_timezone_service;
my_time_t thd_TIME_to_gmt_sec(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void thd_gmt_sec_to_TIME(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void thd_TIME_to_str(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
}
extern "C" {
typedef enum _thd_wait_type_e {
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_encryption.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@
extern struct thd_timezone_service_st {
my_time_t (*thd_TIME_to_gmt_sec)(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void (*thd_gmt_sec_to_TIME)(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void (*thd_TIME_to_str)(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
} *thd_timezone_service;
my_time_t thd_TIME_to_gmt_sec(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void thd_gmt_sec_to_TIME(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void thd_TIME_to_str(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
}
extern "C" {
typedef enum _thd_wait_type_e {
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_ftparser.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@
extern struct thd_timezone_service_st {
my_time_t (*thd_TIME_to_gmt_sec)(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void (*thd_gmt_sec_to_TIME)(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void (*thd_TIME_to_str)(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
} *thd_timezone_service;
my_time_t thd_TIME_to_gmt_sec(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void thd_gmt_sec_to_TIME(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void thd_TIME_to_str(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
}
extern "C" {
typedef enum _thd_wait_type_e {
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_function.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@
extern struct thd_timezone_service_st {
my_time_t (*thd_TIME_to_gmt_sec)(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void (*thd_gmt_sec_to_TIME)(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void (*thd_TIME_to_str)(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
} *thd_timezone_service;
my_time_t thd_TIME_to_gmt_sec(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void thd_gmt_sec_to_TIME(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void thd_TIME_to_str(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
}
extern "C" {
typedef enum _thd_wait_type_e {
Expand Down
2 changes: 2 additions & 0 deletions include/mysql/plugin_password_validation.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,11 @@
extern struct thd_timezone_service_st {
my_time_t (*thd_TIME_to_gmt_sec)(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void (*thd_gmt_sec_to_TIME)(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void (*thd_TIME_to_str)(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
} *thd_timezone_service;
my_time_t thd_TIME_to_gmt_sec(THD* thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void thd_gmt_sec_to_TIME(THD* thd, MYSQL_TIME *ltime, my_time_t t);
void thd_TIME_to_str(THD* thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
}
extern "C" {
typedef enum _thd_wait_type_e {
Expand Down
5 changes: 5 additions & 0 deletions include/mysql/service_thd_timezone.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern "C" {
extern struct thd_timezone_service_st {
my_time_t (*thd_TIME_to_gmt_sec)(MYSQL_THD thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void (*thd_gmt_sec_to_TIME)(MYSQL_THD thd, MYSQL_TIME *ltime, my_time_t t);
void (*thd_TIME_to_str)(MYSQL_THD thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);
} *thd_timezone_service;

#ifdef MYSQL_DYNAMIC_PLUGIN
Expand All @@ -58,10 +59,14 @@ extern struct thd_timezone_service_st {
#define thd_gmt_sec_to_TIME(thd, ltime, t) \
(thd_timezone_service->thd_gmt_sec_to_TIME((thd), (ltime), (t)))

#define thd_TIME_to_str(thd, ltime, format, buf, buf_len) \
(thd_timezone_service->thd_TIME_to_str((thd), (ltime), (format), (buf), (buf_len)))

#else

my_time_t thd_TIME_to_gmt_sec(MYSQL_THD thd, const MYSQL_TIME *ltime, unsigned int *errcode);
void thd_gmt_sec_to_TIME(MYSQL_THD thd, MYSQL_TIME *ltime, my_time_t t);
void thd_TIME_to_str(MYSQL_THD thd, const MYSQL_TIME *ltime, const char *format, char *buf, unsigned int buf_len);

#endif

Expand Down
3 changes: 3 additions & 0 deletions mysql-test/suite/plugins/r/server_audit.result
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ server_audit_syslog_facility LOG_USER
server_audit_syslog_ident mysql-server_auditing
server_audit_syslog_info
server_audit_syslog_priority LOG_INFO
server_audit_timestamp_format %Y%m%d %H:%i:%s
set global server_audit_file_path=null;
set global server_audit_incl_users=null;
set global server_audit_file_path='server_audit.log';
Expand Down Expand Up @@ -104,6 +105,7 @@ server_audit_syslog_facility LOG_USER
server_audit_syslog_ident mysql-server_auditing
server_audit_syslog_info
server_audit_syslog_priority LOG_INFO
server_audit_timestamp_format %Y%m%d %H:%i:%s
set global server_audit_mode=1;
set global server_audit_events='';
create database sa_db;
Expand Down Expand Up @@ -380,6 +382,7 @@ server_audit_syslog_facility LOG_USER
server_audit_syslog_ident mysql-server_auditing
server_audit_syslog_info
server_audit_syslog_priority LOG_INFO
server_audit_timestamp_format %Y%m%d %H:%i:%s
uninstall plugin server_audit;
Warnings:
Warning 1620 Plugin is busy and will be uninstalled on shutdown
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/plugins/r/server_audit_buffering.result
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ server_audit_syslog_facility LOG_USER
server_audit_syslog_ident mysql-server_auditing
server_audit_syslog_info
server_audit_syslog_priority LOG_INFO
server_audit_timestamp_format %Y%m%d %H:%i:%s
set global server_audit_logging=on;
set global server_audit_sync_log_file=on;
Line count in file: 52
Expand Down
56 changes: 28 additions & 28 deletions mysql-test/suite/plugins/r/server_audit_query_id.result
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ DROP TABLE source, dest, dest_2;
set global server_audit_logging=off;
# Wait for audit events to be written
FOUND 1 /set global server_audit_logging=off/ in server_audit_query_id.log
TIMESTAMP,HOSTNAME,root,localhost,4,0,QUERY,test,'set global server_audit_logging=on',0
TIMESTAMP,HOSTNAME,root,localhost,4,1,QUERY,test,'USE test',0
TIMESTAMP,HOSTNAME,root,localhost,4,2,QUERY,test,'CREATE TABLE source (\nid bigint(20) NOT NULL AUTO_INCREMENT,\nPRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4',0
TIMESTAMP,HOSTNAME,root,localhost,4,3,QUERY,test,'CREATE TABLE dest (\nid bigint(20) NOT NULL,\nPRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4',0
TIMESTAMP,HOSTNAME,root,localhost,4,4,QUERY,test,'CREATE TABLE dest_2 (\nid bigint(20) NOT NULL,\nPRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4',0
TIMESTAMP,HOSTNAME,root,localhost,4,5,QUERY,test,'CREATE TRIGGER test_trigger\nAFTER INSERT ON source\nFOR EACH ROW\nINSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,6,QUERY,test,'CREATE TRIGGER test_trigger_2\nAFTER INSERT ON dest\nFOR EACH ROW\nINSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,7,QUERY,test,'CREATE PROCEDURE test_procedure (IN id bigint(20))\nNOT DETERMINISTIC MODIFIES SQL DATA\nBEGIN\nINSERT INTO source VALUES (id), (NULL);\nEND',0
TIMESTAMP,HOSTNAME,root,localhost,4,10,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,9,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,8,QUERY,test,'INSERT INTO source VALUES (NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,4,13,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,12,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,11,QUERY,test,'INSERT INTO source VALUES (NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,4,16,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,15,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,18,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,17,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,14,QUERY,test,'INSERT INTO source VALUES (NULL), (NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,4,22,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,21,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,24,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,23,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,4,20,QUERY,test,'INSERT INTO source VALUES ( NAME_CONST(\'id\',NULL)), (NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,4,19,QUERY,test,'CALL test_procedure(NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,4,25,QUERY,test,'DROP PROCEDURE test_procedure',0
TIMESTAMP,HOSTNAME,root,localhost,4,26,QUERY,test,'DROP TABLE source, dest, dest_2',0
TIMESTAMP,HOSTNAME,root,localhost,4,27,QUERY,test,'set global server_audit_logging=off',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_logging=on',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'USE test',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'CREATE TABLE source (\nid bigint(20) NOT NULL AUTO_INCREMENT,\nPRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'CREATE TABLE dest (\nid bigint(20) NOT NULL,\nPRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'CREATE TABLE dest_2 (\nid bigint(20) NOT NULL,\nPRIMARY KEY (id)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'CREATE TRIGGER test_trigger\nAFTER INSERT ON source\nFOR EACH ROW\nINSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'CREATE TRIGGER test_trigger_2\nAFTER INSERT ON dest\nFOR EACH ROW\nINSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'CREATE PROCEDURE test_procedure (IN id bigint(20))\nNOT DETERMINISTIC MODIFIES SQL DATA\nBEGIN\nINSERT INTO source VALUES (id), (NULL);\nEND',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO source VALUES (NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO source VALUES (NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO source VALUES (NULL), (NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest_2 (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO dest (id) VALUES(NEW.id)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'INSERT INTO source VALUES ( NAME_CONST(\'id\',NULL)), (NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'CALL test_procedure(NULL)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'DROP PROCEDURE test_procedure',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'DROP TABLE source, dest, dest_2',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_logging=off',0
56 changes: 56 additions & 0 deletions mysql-test/suite/plugins/r/server_audit_timestamp.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
set global server_audit_logging=on;
select 1;
1
1
set global server_audit_timestamp_format='CUSTOM-DATE %Y-%m-%d';
select 2;
2
2
set global server_audit_timestamp_format='CUSTOM-TZ %H:%i:%s %z';
select 3;
3
3
set global server_audit_timestamp_format='%Y%m%d %H:%i:%s';
select 4;
4
4
#
# Error handling for long timestamp format
#
set global server_audit_timestamp_format='%H:%i:%s';
show variables like 'server_audit_timestamp_format';
Variable_name Value
server_audit_timestamp_format %H:%i:%s
# Attempting to set an excessively long format string.
set global server_audit_timestamp_format='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
ERROR 42000: Variable 'server_audit_timestamp_format' can't be set to the value of 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
# Value should still be the old one
show variables like 'server_audit_timestamp_format';
Variable_name Value
server_audit_timestamp_format %H:%i:%s
#
# Test large expansion (many %B specifiers)
#
set global server_audit_timestamp_format='%M %M %M %M %M %M %M %M %M %M %M %M %M %M %M';
select 5;
5
5
set global server_audit_timestamp_format='%Y%m%d %H:%i:%s';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can try set global server_audit_timestamp_format=default instead

set global server_audit_logging=off;
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_logging=on',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 1',0
CUSTOM-DATE TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'CUSTOM-DATE %Y-%m-%d\'',0
CUSTOM-DATE TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 2',0
CUSTOM-TZ TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'CUSTOM-TZ %H:%i:%s %z\'',0
CUSTOM-TZ TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 3',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'%Y%m%d %H:%i:%s\'',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 4',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'%H:%i:%s\'',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'show variables like \'server_audit_timestamp_format\'',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select repeat(\'A\', 130)',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\'',1231
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'show variables like \'server_audit_timestamp_format\'',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'%M %M %M %M %M %M %M %M %M %M %M %M %M %M %M\'',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 5',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'%Y%m%d %H:%i:%s\'',0
TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_logging=off',0
3 changes: 3 additions & 0 deletions mysql-test/suite/plugins/r/thread_pool_server_audit.result
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ server_audit_syslog_facility LOG_USER
server_audit_syslog_ident mysql-server_auditing
server_audit_syslog_info
server_audit_syslog_priority LOG_INFO
server_audit_timestamp_format %Y%m%d %H:%i:%s
set global server_audit_file_path=null;
set global server_audit_incl_users=null;
set global server_audit_file_path='server_audit.log';
Expand Down Expand Up @@ -89,6 +90,7 @@ server_audit_syslog_facility LOG_USER
server_audit_syslog_ident mysql-server_auditing
server_audit_syslog_info
server_audit_syslog_priority LOG_INFO
server_audit_timestamp_format %Y%m%d %H:%i:%s
set global server_audit_mode=1;
set global server_audit_events='';
create database sa_db;
Expand Down Expand Up @@ -242,6 +244,7 @@ server_audit_syslog_facility LOG_USER
server_audit_syslog_ident mysql-server_auditing
server_audit_syslog_info
server_audit_syslog_priority LOG_INFO
server_audit_timestamp_format %Y%m%d %H:%i:%s
uninstall plugin server_audit;
Warnings:
Warning 1620 Plugin is busy and will be uninstalled on shutdown
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/plugins/t/server_audit_query_id.test
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ set global server_audit_logging=off;
--exec perl $MYSQL_TEST_DIR/suite/plugins/t/normalize_query_id.pl $SEARCH_FILE

# Output the log without heavy replacements so we can see the actual order
--replace_regex /\d\d\d\d\d\d\d\d \d\d:\d\d:\d\d/TIMESTAMP/ /,[^,]+,root,(localhost|localhost:[0-9]+),/,HOSTNAME,root,localhost,/
--replace_regex /\d\d\d\d\d\d\d\d \d\d:\d\d:\d\d/TIMESTAMP/ /,[^,]+,root,(localhost|localhost:[0-9]+),\d+,\d+,/,HOSTNAME,root,localhost,ID,ID,/

cat_file $SEARCH_FILE;
remove_file $SEARCH_FILE;
4 changes: 4 additions & 0 deletions mysql-test/suite/plugins/t/server_audit_timestamp.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--plugin-load-add=server_audit
--server_audit_file_path='server_audit_timestamp.log'
--server_audit_output_type=file
--server_audit_events='query'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's test setting of timestamp format on the command line too

58 changes: 58 additions & 0 deletions mysql-test/suite/plugins/t/server_audit_timestamp.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--source include/not_embedded.inc

if (!$SERVER_AUDIT_SO) {
skip No SERVER_AUDIT plugin;
}

--disable_ps_protocol
--disable_view_protocol

# The plugin is loaded via .opt file
let $MYSQLD_DATADIR= `SELECT @@datadir`;
let SEARCH_FILE= $MYSQLD_DATADIR/server_audit_timestamp.log;

set global server_audit_logging=on;

# Default format
select 1;

# Custom format 1: Just date
set global server_audit_timestamp_format='CUSTOM-DATE %Y-%m-%d';
select 2;

# Custom format 2: Including timezone (if supported by system strftime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can now remove references to the "system strftime" from comments

set global server_audit_timestamp_format='CUSTOM-TZ %H:%i:%s %z';
select 3;

# Revert to default
set global server_audit_timestamp_format='%Y%m%d %H:%i:%s';
select 4;

--echo #
--echo # Error handling for long timestamp format
--echo #
set global server_audit_timestamp_format='%H:%i:%s';
show variables like 'server_audit_timestamp_format';

--echo # Attempting to set an excessively long format string.
let $long_format= `select repeat('A', 130)`;
--error ER_WRONG_VALUE_FOR_VAR
eval set global server_audit_timestamp_format='$long_format';

--echo # Value should still be the old one
show variables like 'server_audit_timestamp_format';

--echo #
--echo # Test large expansion (many %B specifiers)
--echo #
set global server_audit_timestamp_format='%M %M %M %M %M %M %M %M %M %M %M %M %M %M %M';
select 5;
set global server_audit_timestamp_format='%Y%m%d %H:%i:%s';

set global server_audit_logging=off;

# We use replace_regex to mask the actual volatile parts but keep our prefixes
--replace_regex /\d{4}\d{2}\d{2} \d{2}:\d{2}:\d{2}/TIMESTAMP/ /CUSTOM-DATE \d{4}-\d{2}-\d{2}/CUSTOM-DATE TIMESTAMP/ /CUSTOM-TZ \d{2}:\d{2}:\d{2} [+-]\d{4}/CUSTOM-TZ TIMESTAMP/ /CUSTOM-TZ \d{2}:\d{2}:\d{2}/CUSTOM-TZ TIMESTAMP/ /([A-Z][a-z]+ ){10,}[A-Z][a-z]+/TIMESTAMP/ /\d{2}:\d{2}:\d{2}/TIMESTAMP/ /,[^,]+,root,(localhost|localhost:[0-9]+),(\d+),(\d+),/,HOSTNAME,root,localhost,ID,ID,/
cat_file $SEARCH_FILE;

remove_file $SEARCH_FILE;
Loading