-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a node_is_leader service to check for the leader states
It's possible to check for any kind of leader of specifically for a standby leader.
- Loading branch information
Showing
10 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"state": "running", | ||
"postmaster_start_time": "2021-08-11 07:02:20.732 UTC", | ||
"role": "master", | ||
"server_version": 110012, | ||
"cluster_unlocked": false, | ||
"xlog": { | ||
"location": 1174407088 | ||
}, | ||
"timeline": 58, | ||
"replication": [ | ||
{ | ||
"usename": "replicator", | ||
"application_name": "srv1", | ||
"client_addr": "10.20.199.3", | ||
"state": "streaming", | ||
"sync_state": "async", | ||
"sync_priority": 0 | ||
} | ||
], | ||
"database_system_identifier": "6965971025273547206", | ||
"patroni": { | ||
"version": "2.0.2", | ||
"scope": "patroni-demo" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"state": "running", | ||
"postmaster_start_time": "2023-08-23 14:30:50.201691+00:00", | ||
"role": "standby_leader", | ||
"server_version": 140009, | ||
"xlog": { | ||
"received_location": 889192448, | ||
"replayed_location": 889192448, | ||
"replayed_timestamp": null, | ||
"paused": false | ||
}, | ||
"timeline": 1, | ||
"dcs_last_seen": 1692805971, | ||
"database_system_identifier": "7270495803765492571", | ||
"patroni": { | ||
"version": "3.1.0", | ||
"scope": "patroni-demo-sb" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"state": "running", | ||
"postmaster_start_time": "2021-08-11 07:02:20.732 UTC", | ||
"role": "master", | ||
"server_version": 110012, | ||
"cluster_unlocked": false, | ||
"xlog": { | ||
"location": 1174407088 | ||
}, | ||
"timeline": 58, | ||
"replication": [ | ||
{ | ||
"usename": "replicator", | ||
"application_name": "srv1", | ||
"client_addr": "10.20.199.3", | ||
"state": "streaming", | ||
"sync_state": "async", | ||
"sync_priority": 0 | ||
} | ||
], | ||
"database_system_identifier": "6965971025273547206", | ||
"patroni": { | ||
"version": "2.0.2", | ||
"scope": "patroni-demo" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"state": "running", | ||
"postmaster_start_time": "2023-08-23 14:30:50.201691+00:00", | ||
"role": "standby_leader", | ||
"server_version": 140009, | ||
"xlog": { | ||
"received_location": 889192448, | ||
"replayed_location": 889192448, | ||
"replayed_timestamp": null, | ||
"paused": false | ||
}, | ||
"timeline": 1, | ||
"dcs_last_seen": 1692805971, | ||
"database_system_identifier": "7270495803765492571", | ||
"patroni": { | ||
"version": "3.1.0", | ||
"scope": "patroni-demo-sb" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from click.testing import CliRunner | ||
from pytest_mock import MockerFixture | ||
|
||
from check_patroni.cli import main | ||
|
||
from .tools import my_mock | ||
|
||
|
||
def test_node_is_leader_ok(mocker: MockerFixture, use_old_replica_state: bool) -> None: | ||
runner = CliRunner() | ||
|
||
my_mock(mocker, "node_is_leader_ok", 200) | ||
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_leader"]) | ||
assert result.exit_code == 0 | ||
assert ( | ||
result.stdout | ||
== "NODEISLEADER OK - This node is a leader node. | is_leader=1;;@0\n" | ||
) | ||
|
||
my_mock(mocker, "node_is_leader_ok_standby_leader", 200) | ||
result = runner.invoke( | ||
main, | ||
["-e", "https://10.20.199.3:8008", "node_is_leader", "--is-standby-leader"], | ||
) | ||
print(result.stdout) | ||
assert result.exit_code == 0 | ||
assert ( | ||
result.stdout | ||
== "NODEISLEADER OK - This node is a standby leader node. | is_leader=1;;@0\n" | ||
) | ||
|
||
|
||
def test_node_is_leader_ko(mocker: MockerFixture, use_old_replica_state: bool) -> None: | ||
runner = CliRunner() | ||
|
||
my_mock(mocker, "node_is_leader_ko", 503) | ||
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_leader"]) | ||
assert result.exit_code == 2 | ||
assert ( | ||
result.stdout | ||
== "NODEISLEADER CRITICAL - This node is not a leader node. | is_leader=0;;@0\n" | ||
) | ||
|
||
my_mock(mocker, "node_is_leader_ko_standby_leader", 503) | ||
result = runner.invoke( | ||
main, | ||
["-e", "https://10.20.199.3:8008", "node_is_leader", "--is-standby-leader"], | ||
) | ||
assert result.exit_code == 2 | ||
assert ( | ||
result.stdout | ||
== "NODEISLEADER CRITICAL - This node is not a standby leader node. | is_leader=0;;@0\n" | ||
) |