Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.x logging mem [WIP] #4713

Open
wants to merge 21 commits into
base: v2.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6a2d52f
Adding a circular buffer to MySQL_Logger
renecannao Aug 10, 2024
d92e57f
Renamed mysql-eventslog_memory_history_size to mysql-eventslog_buffer…
renecannao Aug 10, 2024
61c189b
Reimplementation of the circular buffer for Query Logging
renecannao Oct 13, 2024
a8310f4
Implemented table stats_mysql_query_events
renecannao Oct 13, 2024
754f1e5
Reimplementation of MySQL_Logger_CircularBuffer::get_all_events()
renecannao Oct 13, 2024
efb95ca
First implementation of insertMysqlEventsIntoDb()
renecannao Oct 14, 2024
d7a9254
Add history_mysql_query_events in statsdb_disk
renecannao Oct 14, 2024
23e3244
Implementation of processEvents() and DUMP EVENTSLOG commands
renecannao Oct 14, 2024
1d30d40
Added stats_mysql_eventslog_sync_buffer_to_disk
renecannao Oct 14, 2024
28982a4
Adding documentation on in memory eventslog
renecannao Oct 14, 2024
8e768f4
Improved documentation
renecannao Oct 14, 2024
56eb211
Added variable eventslog_buffer_max_query_length
renecannao Oct 14, 2024
8f0324b
MySQL_Event log buffering enhancements
renecannao Oct 21, 2024
ede0e7f
MySQL_Logger::getAllMetrics()
renecannao Oct 21, 2024
9eeed3c
Drafting handling of errors in MySQL Events log
renecannao Oct 24, 2024
234d4e6
Drafting handling of errors in MySQL Events log 2
renecannao Oct 26, 2024
223573d
Adding some errors in MySQL Events log
renecannao Oct 28, 2024
b05f6bd
Adding more errors in MySQL Events log
renecannao Oct 30, 2024
24ffd9f
Merge branch 'v2.7' into v2.x-logging_mem
renecannao Nov 6, 2024
124fb28
Adding errno into in-memory query logging
renecannao Nov 12, 2024
737f3a1
Merge branch 'v2.7' into v2.x-logging_mem
renecannao Nov 12, 2024
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
540 changes: 482 additions & 58 deletions include/MySQL_Logger.hpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions include/MySQL_Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ class MySQL_Session
* @param myds If not null, should point to a MySQL_Data_Stream (backend connection) which connection status
* should be updated, and previous query resources cleanup.
*/
void RequestEnd(MySQL_Data_Stream *);
void LogQuery(MySQL_Data_Stream *);
void RequestEnd(MySQL_Data_Stream * myds, const unsigned int myerrno = 0, const char * errmsg = nullptr);
void LogQuery(MySQL_Data_Stream * myds, const unsigned int myerrno = 0, const char * errmsg = nullptr);

void handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY___create_mirror_session();
int handler_again___status_PINGING_SERVER();
Expand Down
3 changes: 3 additions & 0 deletions include/MySQL_Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,9 @@ class MySQL_Threads_Handler
int connpoll_reset_queue_length;
char *eventslog_filename;
int eventslog_filesize;
int eventslog_buffer_history_size;
int eventslog_table_memory_size;
int eventslog_buffer_max_query_length;
int eventslog_default_log;
int eventslog_format;
char *auditlog_filename;
Expand Down
13 changes: 13 additions & 0 deletions include/ProxySQL_Statistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

#define STATSDB_SQLITE_TABLE_HISTORY_MYSQL_QUERY_DIGEST "CREATE TABLE history_mysql_query_digest (dump_time INT , hostgroup INT , schemaname VARCHAR NOT NULL , username VARCHAR NOT NULL , client_address VARCHAR NOT NULL , digest VARCHAR NOT NULL , digest_text VARCHAR NOT NULL , count_star INTEGER NOT NULL , first_seen INTEGER NOT NULL , last_seen INTEGER NOT NULL , sum_time INTEGER NOT NULL , min_time INTEGER NOT NULL , max_time INTEGER NOT NULL , sum_rows_affected INTEGER NOT NULL , sum_rows_sent INTEGER NOT NULL)"

#define STATSDB_SQLITE_TABLE_HISTORY_MYSQL_QUERY_EVENTS "CREATE TABLE history_mysql_query_events (id INTEGER PRIMARY KEY AUTOINCREMENT , thread_id INTEGER , username TEXT , schemaname TEXT , start_time INTEGER , end_time INTEGER , query_digest TEXT , query TEXT , server TEXT , client TEXT , event_type INTEGER , hid INTEGER , extra_info TEXT , affected_rows INTEGER , last_insert_id INTEGER , rows_sent INTEGER , client_stmt_id INTEGER , gtid TEXT , errno INT , error TEXT)"
class ProxySQL_Statistics {
SQLite3DB *statsdb_mem; // internal statistics DB
std::vector<table_def_t *> *tables_defs_statsdb_mem;
Expand All @@ -90,6 +91,7 @@ class ProxySQL_Statistics {
unsigned long long next_timer_MySQL_Threads_Handler;
unsigned long long next_timer_mysql_query_digest_to_disk;
unsigned long long next_timer_system_cpu;
unsigned long long last_timer_mysql_dump_eventslog_to_disk = 0;
#ifndef NOJEM
unsigned long long next_timer_system_memory;
#endif
Expand All @@ -105,6 +107,7 @@ class ProxySQL_Statistics {
int stats_mysql_query_cache;
int stats_system_cpu;
int stats_mysql_query_digest_to_disk;
int stats_mysql_eventslog_sync_buffer_to_disk;
#ifndef NOJEM
int stats_system_memory;
#endif
Expand All @@ -117,6 +120,16 @@ class ProxySQL_Statistics {
bool MySQL_Threads_Handler_timetoget(unsigned long long);
bool mysql_query_digest_to_disk_timetoget(unsigned long long);
bool system_cpu_timetoget(unsigned long long);
/**
* @brief Checks if it's time to dump the events log to disk based on the configured interval.
* @param currentTimeMicros The current time in microseconds.
* @return True if it's time to dump the events log, false otherwise.
*
* This function checks if the current time exceeds the last dump time plus the configured dump interval.
* The dump interval is retrieved from the ProxySQL configuration. If the dump interval is 0, no dumping is performed.
*/
bool MySQL_Logger_dump_eventslog_timetoget(unsigned long long currentTimeMicros);

#ifndef NOJEM
bool system_memory_timetoget(unsigned long long);
#endif
Expand Down
1 change: 1 addition & 0 deletions include/proxysql_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class ProxySQL_Admin {
int stats_mysql_connections;
int stats_mysql_query_cache;
int stats_mysql_query_digest_to_disk;
int stats_mysql_eventslog_sync_buffer_to_disk;
int stats_system_cpu;
int stats_system_memory;
int mysql_show_processlist_extended;
Expand Down
6 changes: 6 additions & 0 deletions include/proxysql_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,9 @@ __thread char * mysql_thread___ssl_p2s_crlpath;
/* variables used by events log */
__thread char * mysql_thread___eventslog_filename;
__thread int mysql_thread___eventslog_filesize;
__thread int mysql_thread___eventslog_buffer_history_size;
__thread int mysql_thread___eventslog_table_memory_size;
__thread int mysql_thread___eventslog_buffer_max_query_length;
__thread int mysql_thread___eventslog_default_log;
__thread int mysql_thread___eventslog_format;

Expand Down Expand Up @@ -1066,6 +1069,9 @@ extern __thread char * mysql_thread___ssl_p2s_crlpath;
/* variables used by events log */
extern __thread char * mysql_thread___eventslog_filename;
extern __thread int mysql_thread___eventslog_filesize;
extern __thread int mysql_thread___eventslog_buffer_history_size;
extern __thread int mysql_thread___eventslog_table_memory_size;
extern __thread int mysql_thread___eventslog_buffer_max_query_length;
extern __thread int mysql_thread___eventslog_default_log;
extern __thread int mysql_thread___eventslog_format;

Expand Down
Loading