@@ -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,20 @@ 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)" , r ["members" ], r .elapsed .total_seconds ()
607
+ )
599
608
except RetryError :
600
609
# Return False if it was not possible to get the cluster info. Try again later.
601
610
return False
602
611
603
- return len (cluster_status .json ()["members" ]) == 0
612
+ return len (r .json ()["members" ]) == 0
604
613
605
614
def online_cluster_members (self ) -> list [ClusterMember ]:
606
615
"""Return list of online cluster members."""
@@ -631,15 +640,21 @@ def promote_standby_cluster(self) -> None:
631
640
auth = self ._patroni_auth ,
632
641
timeout = PATRONI_TIMEOUT ,
633
642
)
643
+ logger .debug (
644
+ "API promote_standby_cluster: %s (%s)" ,
645
+ config_response ,
646
+ config_response .elapsed .total_seconds (),
647
+ )
634
648
if "standby_cluster" not in config_response .json ():
635
649
raise StandbyClusterAlreadyPromotedError ("standby cluster is already promoted" )
636
- requests .patch (
650
+ r = requests .patch (
637
651
f"{ self ._patroni_url } /config" ,
638
652
verify = self .verify ,
639
653
json = {"standby_cluster" : None },
640
654
auth = self ._patroni_auth ,
641
655
timeout = PATRONI_TIMEOUT ,
642
656
)
657
+ logger .debug ("API promote_standby_cluster patch: %s (%s)" , r , r .elapsed .total_seconds ())
643
658
for attempt in Retrying (stop = stop_after_delay (60 ), wait = wait_fixed (3 )):
644
659
with attempt :
645
660
if self .get_primary () is None :
@@ -846,6 +861,7 @@ def switchover(self, candidate: str | None = None) -> None:
846
861
auth = self ._patroni_auth ,
847
862
timeout = PATRONI_TIMEOUT ,
848
863
)
864
+ logger .debug ("API switchover: %s (%s)" , r , r .elapsed .total_seconds ())
849
865
850
866
# Check whether the switchover was unsuccessful.
851
867
if r .status_code != 200 :
@@ -1012,12 +1028,14 @@ def remove_raft_member(self, member_ip: str) -> None:
1012
1028
@retry (stop = stop_after_attempt (20 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 10 ))
1013
1029
def reload_patroni_configuration (self ):
1014
1030
"""Reload Patroni configuration after it was changed."""
1015
- requests .post (
1031
+ logger .debug ("Reloading Patroni configuration..." )
1032
+ r = requests .post (
1016
1033
f"{ self ._patroni_url } /reload" ,
1017
1034
verify = self .verify ,
1018
1035
auth = self ._patroni_auth ,
1019
1036
timeout = PATRONI_TIMEOUT ,
1020
1037
)
1038
+ logger .debug ("API reload_patroni_configuration: %s (%s)" , r , r .elapsed .total_seconds ())
1021
1039
1022
1040
def is_patroni_running (self ) -> bool :
1023
1041
"""Check if the Patroni service is running."""
@@ -1048,36 +1066,45 @@ def restart_patroni(self) -> bool:
1048
1066
@retry (stop = stop_after_attempt (3 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 10 ))
1049
1067
def restart_postgresql (self ) -> None :
1050
1068
"""Restart PostgreSQL."""
1051
- requests .post (
1069
+ logger .debug ("Restarting PostgreSQL..." )
1070
+ r = requests .post (
1052
1071
f"{ self ._patroni_url } /restart" ,
1053
1072
verify = self .verify ,
1054
1073
auth = self ._patroni_auth ,
1055
1074
timeout = PATRONI_TIMEOUT ,
1056
1075
)
1076
+ logger .debug ("API restart_postgresql: %s (%s)" , r , r .elapsed .total_seconds ())
1057
1077
1058
1078
@retry (stop = stop_after_attempt (3 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 10 ))
1059
1079
def reinitialize_postgresql (self ) -> None :
1060
1080
"""Reinitialize PostgreSQL."""
1061
- requests .post (
1081
+ logger .debug ("Reinitializing PostgreSQL..." )
1082
+ r = requests .post (
1062
1083
f"{ self ._patroni_url } /reinitialize" ,
1063
1084
verify = self .verify ,
1064
1085
auth = self ._patroni_auth ,
1065
1086
timeout = PATRONI_TIMEOUT ,
1066
1087
)
1088
+ logger .debug ("API reinitialize_postgresql: %s (%s)" , r , r .elapsed .total_seconds ())
1067
1089
1068
1090
@retry (stop = stop_after_attempt (3 ), wait = wait_exponential (multiplier = 1 , min = 2 , max = 10 ))
1069
1091
def bulk_update_parameters_controller_by_patroni (self , parameters : dict [str , Any ]) -> None :
1070
1092
"""Update the value of a parameter controller by Patroni.
1071
1093
1072
1094
For more information, check https://patroni.readthedocs.io/en/latest/patroni_configuration.html#postgresql-parameters-controlled-by-patroni.
1073
1095
"""
1074
- requests .patch (
1096
+ r = requests .patch (
1075
1097
f"{ self ._patroni_url } /config" ,
1076
1098
verify = self .verify ,
1077
1099
json = {"postgresql" : {"parameters" : parameters }},
1078
1100
auth = self ._patroni_auth ,
1079
1101
timeout = PATRONI_TIMEOUT ,
1080
1102
)
1103
+ logger .debug (
1104
+ "API bulk_update_parameters_controller_by_patroni: %s (%s)" ,
1105
+ r ,
1106
+ r .elapsed .total_seconds (),
1107
+ )
1081
1108
1082
1109
def ensure_slots_controller_by_patroni (self , slots : dict [str , str ]) -> None :
1083
1110
"""Synchronises slots controlled by Patroni with the provided state by removing unneeded slots and creating new ones.
@@ -1093,6 +1120,11 @@ def ensure_slots_controller_by_patroni(self, slots: dict[str, str]) -> None:
1093
1120
timeout = PATRONI_TIMEOUT ,
1094
1121
auth = self ._patroni_auth ,
1095
1122
)
1123
+ logger .debug (
1124
+ "API ensure_slots_controller_by_patroni: %s (%s)" ,
1125
+ current_config ,
1126
+ current_config .elapsed .total_seconds (),
1127
+ )
1096
1128
if current_config .status_code != 200 :
1097
1129
raise Exception (
1098
1130
f"Failed to get current Patroni config: { current_config .status_code } { current_config .text } "
@@ -1106,13 +1138,18 @@ def ensure_slots_controller_by_patroni(self, slots: dict[str, str]) -> None:
1106
1138
"plugin" : "pgoutput" ,
1107
1139
"type" : "logical" ,
1108
1140
}
1109
- requests .patch (
1141
+ r = requests .patch (
1110
1142
f"{ self ._patroni_url } /config" ,
1111
1143
verify = self .verify ,
1112
1144
json = {"slots" : slots_patch },
1113
1145
auth = self ._patroni_auth ,
1114
1146
timeout = PATRONI_TIMEOUT ,
1115
1147
)
1148
+ logger .debug (
1149
+ "API ensure_slots_controller_by_patroni: %s (%s)" ,
1150
+ r ,
1151
+ r .elapsed .total_seconds (),
1152
+ )
1116
1153
1117
1154
@property
1118
1155
def _synchronous_node_count (self ) -> int :
@@ -1140,6 +1177,9 @@ def update_synchronous_node_count(self) -> None:
1140
1177
auth = self ._patroni_auth ,
1141
1178
timeout = PATRONI_TIMEOUT ,
1142
1179
)
1180
+ logger .debug (
1181
+ "API update_synchronous_node_count: %s (%s)" , r , r .elapsed .total_seconds ()
1182
+ )
1143
1183
1144
1184
# Check whether the update was unsuccessful.
1145
1185
if r .status_code != 200 :
0 commit comments