@@ -274,7 +274,7 @@ def cluster_status(self, alternative_endpoints: list | None = None) -> list[Clus
274
274
if response := self .parallel_patroni_get_request (
275
275
f"/{ PATRONI_CLUSTER_STATUS_ENDPOINT } " , alternative_endpoints
276
276
):
277
- logger .debug ("Patroni cluster members : %s" , response ["members" ])
277
+ logger .debug ("API cluster_status : %s" , response ["members" ])
278
278
return response ["members" ]
279
279
raise RetryError (
280
280
last_attempt = Future .construct (1 , Exception ("Unable to reach any units" ), True )
@@ -462,6 +462,7 @@ def get_patroni_health(self) -> dict[str, str]:
462
462
timeout = API_REQUEST_TIMEOUT ,
463
463
auth = self ._patroni_auth ,
464
464
)
465
+ logger .debug ("API get_patroni_health: %s (%s)" , r , r .elapsed .total_seconds ())
465
466
466
467
return r .json ()
467
468
@@ -529,15 +530,20 @@ def is_replication_healthy(self) -> bool:
529
530
for members_ip in members_ips :
530
531
endpoint = "leader" if members_ip == primary_ip else "replica?lag=16kB"
531
532
url = self ._patroni_url .replace (self .unit_ip , members_ip )
532
- member_status = requests .get (
533
+ r = requests .get (
533
534
f"{ url } /{ endpoint } " ,
534
535
verify = self .verify ,
535
536
auth = self ._patroni_auth ,
536
537
timeout = PATRONI_TIMEOUT ,
537
538
)
538
- if member_status .status_code != 200 :
539
+ logger .debug (
540
+ "API is_replication_healthy: %s (%s)" ,
541
+ r ,
542
+ r .elapsed .total_seconds (),
543
+ )
544
+ if r .status_code != 200 :
539
545
logger .debug (
540
- f"Failed replication check for { members_ip } with code { member_status .status_code } "
546
+ f"Failed replication check for { members_ip } with code { r .status_code } "
541
547
)
542
548
raise Exception
543
549
except RetryError :
@@ -590,17 +596,22 @@ def is_member_isolated(self) -> bool:
590
596
try :
591
597
for attempt in Retrying (stop = stop_after_delay (10 ), wait = wait_fixed (3 )):
592
598
with attempt :
593
- cluster_status = requests .get (
599
+ r = requests .get (
594
600
f"{ self ._patroni_url } /{ PATRONI_CLUSTER_STATUS_ENDPOINT } " ,
595
601
verify = self .verify ,
596
602
timeout = API_REQUEST_TIMEOUT ,
597
603
auth = self ._patroni_auth ,
598
604
)
605
+ logger .debug (
606
+ "API is_member_isolated: %s (%s)" ,
607
+ r .json ()["members" ],
608
+ r .elapsed .total_seconds (),
609
+ )
599
610
except RetryError :
600
611
# Return False if it was not possible to get the cluster info. Try again later.
601
612
return False
602
613
603
- return len (cluster_status .json ()["members" ]) == 0
614
+ return len (r .json ()["members" ]) == 0
604
615
605
616
def online_cluster_members (self ) -> list [ClusterMember ]:
606
617
"""Return list of online cluster members."""
@@ -631,15 +642,21 @@ def promote_standby_cluster(self) -> None:
631
642
auth = self ._patroni_auth ,
632
643
timeout = PATRONI_TIMEOUT ,
633
644
)
645
+ logger .debug (
646
+ "API promote_standby_cluster: %s (%s)" ,
647
+ config_response ,
648
+ config_response .elapsed .total_seconds (),
649
+ )
634
650
if "standby_cluster" not in config_response .json ():
635
651
raise StandbyClusterAlreadyPromotedError ("standby cluster is already promoted" )
636
- requests .patch (
652
+ r = requests .patch (
637
653
f"{ self ._patroni_url } /config" ,
638
654
verify = self .verify ,
639
655
json = {"standby_cluster" : None },
640
656
auth = self ._patroni_auth ,
641
657
timeout = PATRONI_TIMEOUT ,
642
658
)
659
+ logger .debug ("API promote_standby_cluster patch: %s (%s)" , r , r .elapsed .total_seconds ())
643
660
for attempt in Retrying (stop = stop_after_delay (60 ), wait = wait_fixed (3 )):
644
661
with attempt :
645
662
if self .get_primary () is None :
@@ -846,6 +863,7 @@ def switchover(self, candidate: str | None = None) -> None:
846
863
auth = self ._patroni_auth ,
847
864
timeout = PATRONI_TIMEOUT ,
848
865
)
866
+ logger .debug ("API switchover: %s (%s)" , r , r .elapsed .total_seconds ())
849
867
850
868
# Check whether the switchover was unsuccessful.
851
869
if r .status_code != 200 :
@@ -1012,12 +1030,14 @@ def remove_raft_member(self, member_ip: str) -> None:
1012
1030
@retry (stop = stop_after_attempt (20 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 10 ))
1013
1031
def reload_patroni_configuration (self ):
1014
1032
"""Reload Patroni configuration after it was changed."""
1015
- requests .post (
1033
+ logger .debug ("Reloading Patroni configuration..." )
1034
+ r = requests .post (
1016
1035
f"{ self ._patroni_url } /reload" ,
1017
1036
verify = self .verify ,
1018
1037
auth = self ._patroni_auth ,
1019
1038
timeout = PATRONI_TIMEOUT ,
1020
1039
)
1040
+ logger .debug ("API reload_patroni_configuration: %s (%s)" , r , r .elapsed .total_seconds ())
1021
1041
1022
1042
def is_patroni_running (self ) -> bool :
1023
1043
"""Check if the Patroni service is running."""
@@ -1048,36 +1068,45 @@ def restart_patroni(self) -> bool:
1048
1068
@retry (stop = stop_after_attempt (3 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 10 ))
1049
1069
def restart_postgresql (self ) -> None :
1050
1070
"""Restart PostgreSQL."""
1051
- requests .post (
1071
+ logger .debug ("Restarting PostgreSQL..." )
1072
+ r = requests .post (
1052
1073
f"{ self ._patroni_url } /restart" ,
1053
1074
verify = self .verify ,
1054
1075
auth = self ._patroni_auth ,
1055
1076
timeout = PATRONI_TIMEOUT ,
1056
1077
)
1078
+ logger .debug ("API restart_postgresql: %s (%s)" , r , r .elapsed .total_seconds ())
1057
1079
1058
1080
@retry (stop = stop_after_attempt (3 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 10 ))
1059
1081
def reinitialize_postgresql (self ) -> None :
1060
1082
"""Reinitialize PostgreSQL."""
1061
- requests .post (
1083
+ logger .debug ("Reinitializing PostgreSQL..." )
1084
+ r = requests .post (
1062
1085
f"{ self ._patroni_url } /reinitialize" ,
1063
1086
verify = self .verify ,
1064
1087
auth = self ._patroni_auth ,
1065
1088
timeout = PATRONI_TIMEOUT ,
1066
1089
)
1090
+ logger .debug ("API reinitialize_postgresql: %s (%s)" , r , r .elapsed .total_seconds ())
1067
1091
1068
1092
@retry (stop = stop_after_attempt (3 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 10 ))
1069
1093
def bulk_update_parameters_controller_by_patroni (self , parameters : dict [str , Any ]) -> None :
1070
1094
"""Update the value of a parameter controller by Patroni.
1071
1095
1072
1096
For more information, check https://patroni.readthedocs.io/en/latest/patroni_configuration.html#postgresql-parameters-controlled-by-patroni.
1073
1097
"""
1074
- requests .patch (
1098
+ r = requests .patch (
1075
1099
f"{ self ._patroni_url } /config" ,
1076
1100
verify = self .verify ,
1077
1101
json = {"postgresql" : {"parameters" : parameters }},
1078
1102
auth = self ._patroni_auth ,
1079
1103
timeout = PATRONI_TIMEOUT ,
1080
1104
)
1105
+ logger .debug (
1106
+ "API bulk_update_parameters_controller_by_patroni: %s (%s)" ,
1107
+ r ,
1108
+ r .elapsed .total_seconds (),
1109
+ )
1081
1110
1082
1111
def ensure_slots_controller_by_patroni (self , slots : dict [str , str ]) -> None :
1083
1112
"""Synchronises slots controlled by Patroni with the provided state by removing unneeded slots and creating new ones.
@@ -1093,6 +1122,11 @@ def ensure_slots_controller_by_patroni(self, slots: dict[str, str]) -> None:
1093
1122
timeout = PATRONI_TIMEOUT ,
1094
1123
auth = self ._patroni_auth ,
1095
1124
)
1125
+ logger .debug (
1126
+ "API ensure_slots_controller_by_patroni: %s (%s)" ,
1127
+ current_config ,
1128
+ current_config .elapsed .total_seconds (),
1129
+ )
1096
1130
if current_config .status_code != 200 :
1097
1131
raise Exception (
1098
1132
f"Failed to get current Patroni config: { current_config .status_code } { current_config .text } "
@@ -1106,13 +1140,18 @@ def ensure_slots_controller_by_patroni(self, slots: dict[str, str]) -> None:
1106
1140
"plugin" : "pgoutput" ,
1107
1141
"type" : "logical" ,
1108
1142
}
1109
- requests .patch (
1143
+ r = requests .patch (
1110
1144
f"{ self ._patroni_url } /config" ,
1111
1145
verify = self .verify ,
1112
1146
json = {"slots" : slots_patch },
1113
1147
auth = self ._patroni_auth ,
1114
1148
timeout = PATRONI_TIMEOUT ,
1115
1149
)
1150
+ logger .debug (
1151
+ "API ensure_slots_controller_by_patroni: %s (%s)" ,
1152
+ r ,
1153
+ r .elapsed .total_seconds (),
1154
+ )
1116
1155
1117
1156
@property
1118
1157
def _synchronous_node_count (self ) -> int :
@@ -1140,6 +1179,9 @@ def update_synchronous_node_count(self) -> None:
1140
1179
auth = self ._patroni_auth ,
1141
1180
timeout = PATRONI_TIMEOUT ,
1142
1181
)
1182
+ logger .debug (
1183
+ "API update_synchronous_node_count: %s (%s)" , r , r .elapsed .total_seconds ()
1184
+ )
1143
1185
1144
1186
# Check whether the update was unsuccessful.
1145
1187
if r .status_code != 200 :
0 commit comments