Commit graph

143 commits

Author SHA1 Message Date
David Prevot be16bbbdc3 Update changelog for 2.0.0-1~bpo12+1 release 2024-04-18 16:16:01 +02:00
David Prévot 0f394cb80d Update changelog for 2.0.0-1 release 2024-04-14 09:38:21 +02:00
David Prévot f006a708d7 Update Standards-Version to 4.7.0 2024-04-14 09:31:02 +02:00
David Prévot f13b67af7c Update upstream source from tag 'upstream/2.0.0'
Update to upstream version '2.0.0'
with Debian dir 5ce295e1d2
2024-04-14 09:26:34 +02:00
David Prévot c52e34116d New upstream version 2.0.0 2024-04-14 09:26:34 +02:00
benoit 807f9b2071 Release V2.0.0 2024-04-09 16:45:11 +02:00
benoit e0589b97a8 Black run 2024-02-27 11:29:52 +01:00
benoit a4ed20210c Improve doc for node_is_replica
node_is_replica is using the following Patroni endpoints: replica, asynchronous
and synchronous. The first two implement the lag tag. For these endpoints
the state of a replica node doesn't reflect the replication state
(streaming or in archive recovery), we only know if it's running. The
timeline is also not checked.

Therefore, if a cluster is using asynchronous replication, it is recommended
to check for the lag to detect a divegence as soon as possible.
2024-02-26 16:02:53 +01:00
benoit 364a385a2f Fix cluster_has_leader in archive recovery tests
Since replication states are also over-ridden for standby_leaders since
the commit fixing cluster_node_count, the tests had to be adapted.
2024-01-09 06:50:00 +01:00
benoit 78ef0f6ada Fix cluster_node_count's management of replication states
The service now supports the `streaming` state.

Since we dont check for lag or timeline in this service, a healthy node
is :

* leader : in a running state
* standby_leader : running (pre Patroni 3.0.4), streaming otherwise
* standby & sync_standby : running (pre Patroni 3.0.4), streaming otherwise

Updated the tests for this service.
2024-01-09 06:50:00 +01:00
benoit 46db3e2d15 Fix the cluster_has_leader service for standby clusters
Before this patch we checked the expected standby leader state
was `running` for all versions of Patroni.

With this patch, for:
* Patroni < 3.0.4, standby leaders are in `running` state.
* Patroni >= 3.0.4, standby leaders can be in `streaming` or `in
archive recovey` state. We will raise a warning for the latter.

The tests where modified to account for this.

Co-authored-by: Denis Laxalde <denis@laxalde.org>
2023-12-18 13:17:37 +01:00
benoit ffc330f96e Mention that shell completion support is dependant on the shell version 2023-11-16 13:59:06 +01:00
benoit 8d6b8502b6 cluster_has_replica: fix the way a healthy replica is detected
For patroni >= version 3.0.4:
* the role is `replica` or `sync_standby`
* the state is `streaming` or `in archive recovery`
* the timeline is the same as the leader
* the lag is lower or equal to `max_lag`

For prio versions of patroni:
* the role is `replica` or `sync_standby`
* the state is `running`
* the timeline is the same as the leader
* the lag is lower or equal to `max_lag`

Additionnally, we now display the timeline in the perfstats. We also try
to display the perf stats of unhealthy replica as much as possible.

Update tests for cluster_has_replica:
* Fix the tests to make them work with the new algotithm
* Add a specific test for tl divergences
2023-11-11 10:50:35 +01:00
Denis Laxalde 6ee8db1df2 Avoid using requests's JSONDecodeError
This exception is only present in "recent" version of requests,
typically not in the version distributed by Debian bullseye. Since
requests' JSONDecodeError is in general a subclass of
json.JSONDecodeError, we use the latter, but also handle the plain
ValueError (which json.JSONDecodeError is a subclass of) because
requests might use simplejson (which uses its own JSONDecodeError, also
a subclass of ValueError).
2023-10-13 11:45:39 +02:00
Denis Laxalde a8c4a3125d Work around nagiosplugin issue about stdout in tests
We basically apply the change from
https://github.com/mpounsett/nagiosplugin/issues/24 as a fixture, but
only when nagiosplugin's version is old.
2023-10-13 11:45:39 +02:00
Denis Laxalde 4035f1a3da Add compat for old pytest in type hints 2023-10-13 11:45:39 +02:00
Denis Laxalde fabf3c142b Declare compatibility with click 7.1 or higher
We apparently, from the test suite, don't need version 8.x.
2023-10-13 11:45:39 +02:00
Denis Laxalde 593278206a Let Mypy check all files
From previous commit, the test suite also type-checks.
2023-10-06 10:40:29 +02:00
Denis Laxalde 903b83e211 Use fake HTTP server for the Patroni API in tests
We introduce a patroni_api fixture, defined in tests/conftest.py, which
sets up an HTTP server serving files in a temporary directory. The
server is itself defined by the PatroniAPI class; it has a 'routes()'
context manager method to be used in actual tests to setup expected
responses based on specified JSON files.

We set up some logging in order to improve debugging.

The direct advantage of this is that PatroniResource.rest_api() method
is now covered by the test suite.

Coverage before this commit:

  Name                        Stmts   Miss  Cover
  -----------------------------------------------
  check_patroni/__init__.py       3      0   100%
  check_patroni/cli.py          193     18    91%
  check_patroni/cluster.py      113      0   100%
  check_patroni/convert.py       23      5    78%
  check_patroni/node.py         146      1    99%
  check_patroni/types.py         50     23    54%
  -----------------------------------------------
  TOTAL                         528     47    91%

and after this commit:

  Name                        Stmts   Miss  Cover
  -----------------------------------------------
  check_patroni/__init__.py       3      0   100%
  check_patroni/cli.py          193     18    91%
  check_patroni/cluster.py      113      0   100%
  check_patroni/convert.py       23      5    78%
  check_patroni/node.py         146      1    99%
  check_patroni/types.py         50      9    82%
  -----------------------------------------------
  TOTAL                         528     33    94%

In actual test functions, we either invoke patroni_api.routes() to
configure which JSON file(s) should be served for each endpoint, or we
define dedicated fixtures (e.g. cluster_config_has_changed()) to
configure this for several test functions or the whole module.

The 'old_replica_state' parametrized fixture is used when needed to
adjust such fixtures, e.g. in cluster_has_replica_ok(), to modify the
JSON content using cluster_api_set_replica_running() (previously in
tests/tools.py, now in tests/__init__.py).

The dependency on pytest-mock is no longer needed.
2023-10-06 10:40:29 +02:00
Denis Laxalde 32e06f7051 Use the 'test' extra in Tox's test environment
Instead of repeating the dependencies.
2023-10-06 10:33:04 +02:00
Denis Laxalde 2d2c389bdb Configure coverage
To be run with 'pytest --cov --cov-report=html'.
2023-10-06 10:33:04 +02:00
Denis Laxalde 34f576ea0f Turn --use-old-replica-state into a parametrized fixture
Instead of requiring the user to run the test suite with and without the
--use-old-replica-state flag, we introduce an 'old_replica_state()'
parametrized fixture that is used only when needed (i.e. in
test_cluster_{has_replica,node_count}.py).
2023-10-06 10:33:04 +02:00
Denis Laxalde fea89041b8 Run pytest with --log-level=debug in tox and CI
This way, our log messages (and those from our stack) will show up in
case of errors or test failures, which makes debugging easier.
2023-10-03 09:54:13 +02:00
Denis Laxalde ea92809cb3 Introduce a 'runner' test fixture
Instead of defining the CliRunner value in each test, we use a fixture.
The CliRunner is also configured with stdout and stderr separated
because mixing them will pose problem if we use stderr for other
purposes in tests, e.g. to emit log messages from a forth-coming HTTP
server.
2023-10-03 09:54:13 +02:00
Denis Laxalde d34e597e61 Use the tmp_path fixture instead of writing files to tests/ 2023-10-03 09:54:13 +02:00
Denis Laxalde bc2d2917c3 Introduce a fake_restapi test fixture
This fixture itself uses the 'use_old_replica_state' fixture, so that
it's no longer needed to use it explicitly in test functions.
2023-10-03 09:54:13 +02:00
Denis Laxalde c3cdb8cdd4 Set a default value to status parameter of my_mock in tests
Most of the times, it's 200, so the default value simplifies usage in
actual tests.
2023-10-03 09:54:13 +02:00
Denis Laxalde 123c300911 Add type hints in tests/conftest.py 2023-10-03 09:54:13 +02:00
Denis Laxalde a0189ebba7 Fix some typos spotted by codespell 2.2.6 2023-10-03 09:53:53 +02:00
Denis Laxalde 95f21a133d Drop superfluous type annotation of 'self'
See https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#classes
> For instance methods, omit type for "self"
2023-10-03 09:39:40 +02:00
David Prévot cc1f2d5793
Initial packaging 2023-09-06 18:29:55 +05:30
David Prévot e95db55000 New upstream version 1.0.0 2023-09-06 14:20:51 +05:30
benoit de8b3daa7a Update tox.ini to run codespell on the documentation 2023-08-30 10:19:18 +02:00
benoit 82e0af8a9e Update README CONTRIBUTING RELEASE
* README: add information pertaining to shell completion;
* CONTRIBUTING: remove release information;
* RELEASE: create a dedicated file with all the relevant release
  information.
2023-08-30 10:19:18 +02:00
benoit 68b230ccb2 Release 1.0.0 2023-08-28 12:09:16 +02:00
benoit f0c2a243f0 Moving things around in README.md and CONTRIBUTING.md 2023-08-28 11:59:59 +02:00
benoit ee3837fab1 Add info and options about sync standby to cluster_has_replica
* Add `--sync-warning` and `--sync-critical`
* Add `sync_replica` to track the number of sync replica in the perf data
* Add `MEMBER-sync` to track if a member is a sync replica in the perf data
2023-08-24 17:34:08 +02:00
benoit b9fbdfdefd fix vagrant/check_patroni.sh 2023-08-24 17:30:39 +02:00
benoit fd801efa38 Revert_d39122d (move packaging to pyproject.toml)
This changes requiered python 3.7 which I overlooked at first. I would
like to be able to install the check any patroni server and Patroni
supports python 3.6.
2023-08-24 16:23:55 +02:00
benoit b69c2501fd Revert commit 20d9d48
For `node_is_alive`, it seemed to be a good idea to exit with a
`CRITICAL` when the target doesn't exist. But for all the rest, UNKNOWN
(which corresponds to a configuration error) seems better.
2023-08-23 18:35:06 +02:00
benoit 94a1388d06 Update changelog for cluster_has_scheduled_action 2023-08-23 18:35:06 +02:00
benoit 259f04587b 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.
2023-08-23 18:22:49 +02:00
benoit 8883d6bdc4 Add standby-leader as a valid leader type for cluster_has_leader 2023-08-23 18:22:49 +02:00
benoit 22bf7df3ea CHANGELOG update for node_is_replica 2023-08-23 16:05:02 +02:00
benoit 20d9d48d78 Fix the liveness check in node_is_alive
Previously if a node wasn't reachable whe would get an UNKNOWN error.
instead of a CRITICAL error.

```
NODEISALIVE UNKNOWN - Connection failed for all provided endpoints
```

We now get the correct error.

```
NODEISALIVE CRITICAL - This node is not alive (patroni is not running). | is_alive=0;;@0
```
2023-08-23 16:05:02 +02:00
benoit 46dd431775 Fix test for node_is_primary 2023-08-23 15:41:15 +02:00
benoit 2bcddf9f87 Add a --is-sync and --is-async to node_is_replica 2023-08-23 15:41:15 +02:00
benoit 99bf1c5bb5 Add new service cluster_has_scheduled_action 2023-08-23 12:08:19 +02:00
benoit 7f6a03a3cc README 2023-08-23 10:53:09 +02:00
benoit e66e49b111 Update CHANGELOG 2023-08-23 10:53:09 +02:00