7
7
from charms .mysql .v0 .architecture import WrongArchitectureWarningCharm , is_wrong_architecture
8
8
from ops .main import main
9
9
10
+ from log_rotation_setup import LogRotationSetup
11
+
10
12
if is_wrong_architecture () and __name__ == "__main__" :
11
13
main (WrongArchitectureWarningCharm )
12
14
@@ -184,6 +186,7 @@ def __init__(self, *args):
184
186
self .log_rotate_manager = LogRotateManager (self )
185
187
self .log_rotate_manager .start_log_rotate_manager ()
186
188
189
+ self .log_rotate_setup = LogRotationSetup (self )
187
190
self .rotate_mysql_logs = RotateMySQLLogs (self )
188
191
self .replication_offer = MySQLAsyncReplicationOffer (self )
189
192
self .replication_consumer = MySQLAsyncReplicationConsumer (self )
@@ -274,11 +277,22 @@ def is_new_unit(self) -> bool:
274
277
}
275
278
return self .unit_peer_data .keys () == _default_unit_data_keys
276
279
280
+ @property
281
+ def text_logs (self ) -> list :
282
+ """Enabled text logs."""
283
+ # slow logs isn't enabled by default
284
+ text_logs = ["error" ]
285
+
286
+ if self .config .plugin_audit_enabled :
287
+ text_logs .append ("audit" )
288
+
289
+ return text_logs
290
+
277
291
@property
278
292
def unit_initialized (self ) -> bool :
279
293
"""Return whether a unit is started.
280
294
281
- Oveerride parent class method to include container accessibility check.
295
+ Override parent class method to include container accessibility check.
282
296
"""
283
297
container = self .unit .get_container (CONTAINER_NAME )
284
298
if container .can_connect ():
@@ -536,34 +550,24 @@ def _on_config_changed(self, _: EventBase) -> None: # noqa: C901
536
550
537
551
previous_config_dict = self .mysql_config .custom_config (config_content )
538
552
539
- # render the new config
540
- memory_limit_bytes = (self .config .profile_limit_memory or 0 ) * BYTES_1MB
541
- new_config_content , new_config_dict = self ._mysql .render_mysqld_configuration (
542
- profile = self .config .profile ,
543
- audit_log_enabled = self .config .plugin_audit_enabled ,
544
- audit_log_strategy = self .config .plugin_audit_strategy ,
545
- memory_limit = memory_limit_bytes ,
546
- experimental_max_connections = self .config .experimental_max_connections ,
547
- binlog_retention_days = self .config .binlog_retention_days ,
548
- )
553
+ # always setup log rotation
554
+ self .log_rotate_setup .setup ()
549
555
556
+ logger .info ("Persisting configuration changes to file" )
557
+ new_config_dict = self ._write_mysqld_configuration ()
550
558
changed_config = compare_dictionaries (previous_config_dict , new_config_dict )
551
559
552
560
if self .mysql_config .keys_requires_restart (changed_config ):
553
561
# there are static configurations in changed keys
554
- logger .info ("Persisting configuration changes to file" )
555
-
556
- # persist config to file
557
- self ._mysql .write_content_to_file (path = MYSQLD_CONFIG_FILE , content = new_config_content )
558
562
559
563
if self ._mysql .is_mysqld_running ():
560
564
logger .info ("Configuration change requires restart" )
561
565
if "loose-audit_log_format" in changed_config :
562
566
# plugins are manipulated running daemon
563
567
if self .config .plugin_audit_enabled :
564
- self ._mysql .install_plugins (["audit_log" , "audit_log_filter" ])
568
+ self ._mysql .install_plugins (["audit_log" ])
565
569
else :
566
- self ._mysql .uninstall_plugins (["audit_log" , "audit_log_filter" ])
570
+ self ._mysql .uninstall_plugins (["audit_log" ])
567
571
# restart the service
568
572
self .on [f"{ self .restart .name } " ].acquire_lock .emit ()
569
573
return
@@ -572,7 +576,9 @@ def _on_config_changed(self, _: EventBase) -> None: # noqa: C901
572
576
# if only dynamic config changed, apply it
573
577
logger .info ("Configuration does not requires restart" )
574
578
for config in dynamic_config :
575
- self ._mysql .set_dynamic_variable (config , new_config_dict [config ])
579
+ self ._mysql .set_dynamic_variable (
580
+ config .removeprefix ("loose-" ), new_config_dict [config ]
581
+ )
576
582
577
583
def _on_leader_elected (self , _ ) -> None :
578
584
"""Handle the leader elected event.
@@ -615,18 +621,20 @@ def _open_ports(self) -> None:
615
621
except ops .ModelError :
616
622
logger .exception ("failed to open port" )
617
623
618
- def _write_mysqld_configuration (self ):
624
+ def _write_mysqld_configuration (self ) -> dict :
619
625
"""Write the mysqld configuration to the file."""
620
626
memory_limit_bytes = (self .config .profile_limit_memory or 0 ) * BYTES_1MB
621
- new_config_content , _ = self ._mysql .render_mysqld_configuration (
627
+ new_config_content , new_config_dict = self ._mysql .render_mysqld_configuration (
622
628
profile = self .config .profile ,
623
629
audit_log_enabled = self .config .plugin_audit_enabled ,
624
630
audit_log_strategy = self .config .plugin_audit_strategy ,
631
+ audit_log_policy = self .config .logs_audit_policy ,
625
632
memory_limit = memory_limit_bytes ,
626
633
experimental_max_connections = self .config .experimental_max_connections ,
627
634
binlog_retention_days = self .config .binlog_retention_days ,
628
635
)
629
636
self ._mysql .write_content_to_file (path = MYSQLD_CONFIG_FILE , content = new_config_content )
637
+ return new_config_dict
630
638
631
639
def _configure_instance (self , container ) -> None :
632
640
"""Configure the instance for use in Group Replication."""
@@ -651,7 +659,7 @@ def _configure_instance(self, container) -> None:
651
659
652
660
if self .config .plugin_audit_enabled :
653
661
# Enable the audit plugin
654
- self ._mysql .install_plugins (["audit_log" , "audit_log_filter" ])
662
+ self ._mysql .install_plugins (["audit_log" ])
655
663
656
664
# Configure instance as a cluster node
657
665
self ._mysql .configure_instance ()
@@ -717,8 +725,7 @@ def _on_mysql_pebble_ready(self, event) -> None:
717
725
container = event .workload
718
726
self ._write_mysqld_configuration ()
719
727
720
- logger .info ("Setting up the logrotate configurations" )
721
- self ._mysql .setup_logrotate_config ()
728
+ self .log_rotate_setup .setup ()
722
729
723
730
if self ._mysql .is_data_dir_initialised ():
724
731
# Data directory is already initialised, skip configuration
0 commit comments