A consumer of events essentially need to implement a subset of event tracking services.
Once such a consumer is installed, producer will use service APIs to notify it about given set of events that the consumer is interested in.
In order to simplify writing the core part of the functionality, we have helper headers with skeleton implementation of each class of events.
Following is an example of a consumer that implements various event tracking services, increments simple counters for each event and then displays them through status variables.
#include "mysql/components/util/event_tracking_authentication_consumer_helper.h"
#include "mysql/components/util/event_tracking_command_consumer_helper.h"
#include "mysql/components/util/event_tracking_connection_consumer_helper.h"
#include "mysql/components/util/event_tracking_general_consumer_helper.h"
#include "mysql/components/util/event_tracking_global_variable_consumer_helper.h"
#include "mysql/components/util/event_tracking_lifecycle_consumer_helper.h"
#include "mysql/components/util/event_tracking_message_consumer_helper.h"
#include "mysql/components/util/event_tracking_parse_consumer_helper.h"
#include "mysql/components/util/event_tracking_query_consumer_helper.h"
#include "mysql/components/util/event_tracking_stored_program_consumer_helper.h"
#include "mysql/components/util/event_tracking_table_access_consumer_helper.h"
mysql_status_var_service);
enum class Event_types {
};
unsigned long g_counters[static_cast<unsigned int>(Event_types::LAST)] = {0};
if (event_type < Event_types::LAST) {
++g_counters[static_cast<unsigned int>(event_type)];
}
}
{"component_event_tracking_example.counter_event_tracking_authentication",
(char
)&g_counters[static_cast<unsigned int>(Event_types::AUTHENTICATION)],
{"component_event_tracking_example.counter_event_tracking_command",
(char
)&g_counters[static_cast<unsigned int>(Event_types::COMMAND)],
{"component_event_tracking_example.counter_event_tracking_connection",
(char
)&g_counters[static_cast<unsigned int>(Event_types::CONNECTION)],
{"component_event_tracking_example.counter_event_tracking_general",
(char
{"component_event_tracking_example.counter_event_tracking_global_"
"variable",
(char
)&g_counters[static_cast<unsigned int>(Event_types::GLOBAL_VARIABLES)],
{"component_event_tracking_example.counter_event_tracking_message",
(char
)&g_counters[static_cast<unsigned int>(Event_types::MESSAGE)],
{"component_event_tracking_example.counter_event_tracking_parse",
(char
)&g_counters[static_cast<unsigned int>(Event_types::PARSE)],
{"component_event_tracking_example.counter_event_tracking_query",
(char
)&g_counters[static_cast<unsigned int>(Event_types::QUERY)],
{"component_event_tracking_example.counter_event_tracking_"
"shutdown",
(char
{"component_event_tracking_example.counter_event_tracking_"
"startup",
(char
)&g_counters[static_cast<unsigned int>(Event_types::STARTUP)],
{"component_event_tracking_example.counter_event_tracking_stored_"
"program",
(char
)&g_counters[static_cast<unsigned int>(Event_types::STORED_PROGRAM)],
{"component_event_tracking_example.counter_event_track_table_"
"access",
(char
)&g_counters[static_cast<unsigned int>(Event_types::TABLE_ACCESS)],
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
if ((variables_registered =
mysql_status_var_service->register_variable(
status_vars))) {
return 1;
}
return 0;
}
if (mysql_status_var_service->unregister_variable(
status_vars))
return 1;
return 0;
}
}
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example);
component_event_tracking_example),
component_event_tracking_example),
component_event_tracking_example),
component_event_tracking_example),
component_event_tracking_example),
component_event_tracking_example),
component_event_tracking_example),
component_event_tracking_example),
component_event_tracking_example),
component_event_tracking_example),
component_event_tracking_example),
METADATA(
"mysql.author",
"Oracle Corporation"),
METADATA(
"component_event_tracking_example",
"1"),
"component_event_tracking_example")
Event_tracking_consumer_a::
init,
static mysql_service_status_t deinit()
Component deinitialization.
Definition: audit_api_message_emit.cc:580
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:571
static void increment_counter(volatile int *counter)
Definition: audit_null.cc:165
static mysql_event_tracking_authentication_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_authentication_consumer_helper.h:86
static bool callback(const mysql_event_tracking_authentication_data *data)
Callback function - To be implemented by component to handle an event.
static bool callback(const mysql_event_tracking_command_data *data)
Callback function - To be implemented by component to handle an event.
static mysql_event_tracking_command_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_command_consumer_helper.h:85
static bool callback(const mysql_event_tracking_connection_data *data)
Callback function - To be implemented by component to handle an event.
static mysql_event_tracking_connection_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_connection_consumer_helper.h:86
static bool callback(const mysql_event_tracking_general_data *data)
Callback function - To be implemented by component to handle an event.
static mysql_event_tracking_general_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_general_consumer_helper.h:85
static bool callback(const mysql_event_tracking_global_variable_data *data)
Callback function - To be implemented by component to handle an event.
static mysql_event_tracking_global_variable_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_global_variable_consumer_helper.h:86
static bool callback(const mysql_event_tracking_startup_data *data)
Callback function - To be implemented by component to handle an event.
static mysql_event_tracking_shutdown_subclass_t shutdown_filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_lifecycle_consumer_helper.h:100
static mysql_event_tracking_startup_subclass_t startup_filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_lifecycle_consumer_helper.h:97
static mysql_event_tracking_message_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_message_consumer_helper.h:85
static bool callback(const mysql_event_tracking_message_data *data)
Callback function - To be implemented by component to handle an event.
static bool callback(mysql_event_tracking_parse_data *data)
Callback function - To be implemented by component to handle an event.
static mysql_event_tracking_parse_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_parse_consumer_helper.h:85
static bool callback(const mysql_event_tracking_query_data *data)
Callback function - To be implemented by component to handle an event.
static mysql_event_tracking_query_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_query_consumer_helper.h:85
static bool callback(const mysql_event_tracking_stored_program_data *data)
Callback function - To be implemented by component to handle an event.
static mysql_event_tracking_stored_program_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_stored_program_consumer_helper.h:86
static mysql_event_tracking_table_access_subclass_t filtered_sub_events
Sub-events to be filtered/ignored - To be defined by the component.
Definition: event_tracking_table_access_consumer_helper.h:86
static bool callback(const mysql_event_tracking_table_access_data *data)
Callback function - To be implemented by component to handle an event.
#define END_DECLARE_LIBRARY_COMPONENTS
A macro to end the last declaration started with the DECLARE_LIBRARY_COMPONENTS.
Definition: component_implementation.h:453
#define END_COMPONENT_REQUIRES()
A macro to end the last declaration started with the BEGIN_COMPONENT_REQUIRES.
Definition: component_implementation.h:387
#define DECLARE_LIBRARY_COMPONENTS
Creates a list of component implementations included in this dynamic library.
Definition: component_implementation.h:447
#define BEGIN_COMPONENT_REQUIRES(name)
A macro to specify requirements of the component.
Definition: component_implementation.h:223
#define REQUIRES_SERVICE_PLACEHOLDER_AS(service, name)
Create a service placeholder, with an arbitrary name.
Definition: component_implementation.h:296
#define REQUIRES_SERVICE_AS(service, name)
Adds a Service requirement with a pointer to placeholder to the list of components.
Definition: component_implementation.h:337
#define BEGIN_COMPONENT_METADATA(name)
A macro to specify metadata of the component.
Definition: component_implementation.h:398
#define END_COMPONENT_METADATA()
A macro to end the last declaration started with the BEGIN_COMPONENT_METADATA.
Definition: component_implementation.h:413
#define COMPONENT_REF(name)
Defines a reference to the specified Component data info structure.
Definition: component_implementation.h:463
#define DECLARE_COMPONENT(source_name, name)
Declares a component.
Definition: component_implementation.h:165
#define END_COMPONENT_PROVIDES()
A macro to end the last declaration started with the BEGIN_COMPONENT_PROVIDES.
Definition: component_implementation.h:204
#define METADATA(key, value)
Adds a Service requirement with a pointer to placeholder to the list of components.
Definition: component_implementation.h:407
#define END_DECLARE_COMPONENT()
A macro to end the last declaration of a Component.
Definition: component_implementation.h:173
#define BEGIN_COMPONENT_PROVIDES(name)
Creates a service implementation list that are provided by specified component.
Definition: component_implementation.h:183
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_AUTHENTICATION(component)
Definition: event_tracking_authentication_consumer_helper.h:75
#define PROVIDES_SERVICE_EVENT_TRACKING_AUTHENTICATION(component)
Definition: event_tracking_authentication_consumer_helper.h:72
unsigned long mysql_event_tracking_authentication_subclass_t
Events for Authentication event tracking.
Definition: event_tracking_authentication_defs.h:72
#define PROVIDES_SERVICE_EVENT_TRACKING_COMMAND(component)
Definition: event_tracking_command_consumer_helper.h:72
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_COMMAND(component)
Definition: event_tracking_command_consumer_helper.h:75
unsigned long mysql_event_tracking_command_subclass_t
Events for Command event tracking.
Definition: event_tracking_command_defs.h:47
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_CONNECTION(component)
Definition: event_tracking_connection_consumer_helper.h:75
#define PROVIDES_SERVICE_EVENT_TRACKING_CONNECTION(component)
Definition: event_tracking_connection_consumer_helper.h:72
unsigned long mysql_event_tracking_connection_subclass_t
Events for Connection event tracking.
Definition: event_tracking_connection_defs.h:53
#define PROVIDES_SERVICE_EVENT_TRACKING_GENERAL(component)
Definition: event_tracking_general_consumer_helper.h:72
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_GENERAL(component)
Definition: event_tracking_general_consumer_helper.h:75
unsigned long mysql_event_tracking_general_subclass_t
Events for the General event tracking.
Definition: event_tracking_general_defs.h:52
#define PROVIDES_SERVICE_EVENT_TRACKING_GLOBAL_VARIABLE(component)
Definition: event_tracking_global_variable_consumer_helper.h:78
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_GLOBAL_VARIABLE(component)
Definition: event_tracking_global_variable_consumer_helper.h:72
unsigned long mysql_event_tracking_global_variable_subclass_t
Events for Global variable event tracking.
Definition: event_tracking_global_variable_defs.h:47
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_LIFECYCLE(component)
Definition: event_tracking_lifecycle_consumer_helper.h:84
#define PROVIDES_SERVICE_EVENT_TRACKING_LIFECYCLE(component)
Definition: event_tracking_lifecycle_consumer_helper.h:81
unsigned long mysql_event_tracking_shutdown_subclass_t
Events for Shutdown event tracking.
Definition: event_tracking_lifecycle_defs.h:68
unsigned long mysql_event_tracking_startup_subclass_t
Events for Startup event tracking.
Definition: event_tracking_lifecycle_defs.h:42
#define PROVIDES_SERVICE_EVENT_TRACKING_MESSAGE(component)
Definition: event_tracking_message_consumer_helper.h:72
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_MESSAGE(component)
Definition: event_tracking_message_consumer_helper.h:75
unsigned long mysql_event_tracking_message_subclass_t
Events for Message event tracking.
Definition: event_tracking_message_defs.h:47
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_PARSE(component)
Definition: event_tracking_parse_consumer_helper.h:75
#define PROVIDES_SERVICE_EVENT_TRACKING_PARSE(component)
Definition: event_tracking_parse_consumer_helper.h:72
unsigned long mysql_event_tracking_parse_subclass_t
Events for Parse event tracking.
Definition: event_tracking_parse_defs.h:47
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_QUERY(component)
Definition: event_tracking_query_consumer_helper.h:75
#define PROVIDES_SERVICE_EVENT_TRACKING_QUERY(component)
Definition: event_tracking_query_consumer_helper.h:72
unsigned long mysql_event_tracking_query_subclass_t
Events for Query event tracking.
Definition: event_tracking_query_defs.h:52
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_STORED_PROGRAM(component)
Definition: event_tracking_stored_program_consumer_helper.h:75
#define PROVIDES_SERVICE_EVENT_TRACKING_STORED_PROGRAM(component)
Definition: event_tracking_stored_program_consumer_helper.h:72
unsigned long mysql_event_tracking_stored_program_subclass_t
Events for Stored program event tracking.
Definition: event_tracking_stored_program_defs.h:44
#define PROVIDES_SERVICE_EVENT_TRACKING_TABLE_ACCESS(component)
Definition: event_tracking_table_access_consumer_helper.h:72
#define IMPLEMENTS_SERVICE_EVENT_TRACKING_TABLE_ACCESS(component)
Definition: event_tracking_table_access_consumer_helper.h:75
unsigned long mysql_event_tracking_table_access_subclass_t
Events for Table access event tracking.
Definition: event_tracking_table_access_defs.h:52
SHOW_VAR status_vars[]
Definition: mysqld.cc:11445
Definition: event_tracking_authentication_consumer_helper.h:81
constexpr char LAST[]
Definition: json_path.cc:64
int mysql_service_status_t
Specific type for the service status return values.
Definition: service.h:34
#define SHUTDOWN
Definition: sql_yacc.h:1374
#define GENERAL
Definition: sql_yacc.h:1070
@ SHOW_LONG
shown as unsigned long
Definition: status_var.h:34
@ SHOW_UNDEF
Definition: status_var.h:31
@ SHOW_SCOPE_GLOBAL
Definition: status_var.h:70
@ SHOW_SCOPE_UNDEF
Definition: status_var.h:69
SHOW STATUS Server status variable.
Definition: status_var.h:79
Structure for Authentication event tracking.
Definition: event_tracking_authentication_defs.h:79
Structure for Command event tracking.
Definition: event_tracking_command_defs.h:55
Structure for Connection event tracking.
Definition: event_tracking_connection_defs.h:60
Structure for General event tracking.
Definition: event_tracking_general_defs.h:59
Structure for Global variable event tracking.
Definition: event_tracking_global_variable_defs.h:50
Structure for Message event tracking.
Definition: event_tracking_message_defs.h:86
Structure for the Parse event tracking.
Definition: event_tracking_parse_defs.h:68
Structure for Query event tracking.
Definition: event_tracking_query_defs.h:59
Structure for Shutdown event tracking.
Definition: event_tracking_lifecycle_defs.h:87
Structure for Startup event tracking.
Definition: event_tracking_lifecycle_defs.h:49
Structure for Stored program event tracking.
Definition: event_tracking_stored_program_defs.h:51
Structure for Table access event tracking.
Definition: event_tracking_table_access_defs.h:59