Fix liveness check
The liveness probe used to return something. It looks like it doesn't do it anymore and it breaks the `node_is_alive` check. Issue: #31
This commit is contained in:
parent
a01a535680
commit
77722f40c1
|
@ -60,14 +60,16 @@ class PatroniResource(nagiosplugin.Resource):
|
||||||
_log.debug(e)
|
_log.debug(e)
|
||||||
continue
|
continue
|
||||||
# The status code is already displayed by urllib3
|
# The status code is already displayed by urllib3
|
||||||
_log.debug("api call data: %(data)s", {"data": r.text})
|
_log.debug(
|
||||||
|
"api call data: %(data)s", {"data": r.text if r.text else "<Empty>"}
|
||||||
|
)
|
||||||
|
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise APIError(
|
raise APIError(
|
||||||
f"Failed to connect to {endpoint}/{service} status code {r.status_code}"
|
f"Failed to connect to {endpoint}/{service} status code {r.status_code}"
|
||||||
)
|
)
|
||||||
|
|
||||||
return r.json()
|
return r.json() if r.text else None
|
||||||
raise nagiosplugin.CheckError("Connection failed for all provided endpoints")
|
raise nagiosplugin.CheckError("Connection failed for all provided endpoints")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
{
|
|
||||||
"state": "running",
|
|
||||||
"postmaster_start_time": "2021-08-11 07:57:51.693 UTC",
|
|
||||||
"role": "replica",
|
|
||||||
"server_version": 110012,
|
|
||||||
"cluster_unlocked": false,
|
|
||||||
"xlog": {
|
|
||||||
"received_location": 1174407088,
|
|
||||||
"replayed_location": 1174407088,
|
|
||||||
"replayed_timestamp": null,
|
|
||||||
"paused": false
|
|
||||||
},
|
|
||||||
"timeline": 58,
|
|
||||||
"database_system_identifier": "6965971025273547206",
|
|
||||||
"patroni": {
|
|
||||||
"version": "2.0.2",
|
|
||||||
"scope": "patroni-demo"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,7 +9,7 @@ from .tools import my_mock
|
||||||
def test_node_is_alive_ok(mocker: MockerFixture) -> None:
|
def test_node_is_alive_ok(mocker: MockerFixture) -> None:
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
|
|
||||||
my_mock(mocker, "node_is_alive", 200)
|
my_mock(mocker, None, 200)
|
||||||
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_alive"])
|
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_alive"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
@ -17,6 +17,6 @@ def test_node_is_alive_ok(mocker: MockerFixture) -> None:
|
||||||
def test_node_is_alive_ko(mocker: MockerFixture) -> None:
|
def test_node_is_alive_ko(mocker: MockerFixture) -> None:
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
|
|
||||||
my_mock(mocker, "node_is_alive", 404)
|
my_mock(mocker, None, 404)
|
||||||
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_alive"])
|
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_alive"])
|
||||||
assert result.exit_code == 2
|
assert result.exit_code == 2
|
||||||
|
|
|
@ -22,7 +22,7 @@ def my_mock(mocker: MockerFixture, json_file: str, status: int) -> None:
|
||||||
def mock_rest_api(self: PatroniResource, service: str) -> Any:
|
def mock_rest_api(self: PatroniResource, service: str) -> Any:
|
||||||
if status != 200:
|
if status != 200:
|
||||||
raise APIError("Test en erreur pour status code 200")
|
raise APIError("Test en erreur pour status code 200")
|
||||||
return getjson(json_file)
|
return getjson(json_file) if json_file else None
|
||||||
|
|
||||||
mocker.resetall()
|
mocker.resetall()
|
||||||
mocker.patch("check_patroni.types.PatroniResource.rest_api", mock_rest_api)
|
mocker.patch("check_patroni.types.PatroniResource.rest_api", mock_rest_api)
|
||||||
|
|
Loading…
Reference in a new issue