Order of operations between normalise and override #561

Closed
opened 2022-07-05 21:05:55 +00:00 by g-a-c · 4 comments
Contributor

What I'm trying to do and why

Since commit 02781662f85bcdbab795bf67fdecf28f85cb50d7 the healthchecks configuration changed from a simple string to an object. This is backwards compatible within the configuration file because the normalize function will upgrade the configuration on-the-fly.

However this normalisation happens before overrides are applied (borgmatic/config/validate.py), so if you have an override to ping a different Healthcheck (which I currently do before I switch to ntfy) then this will fail "silently" without sending a failure ping because the Healthchecks config is invalid

Maybe it would be better to override before normalising so that these dynamic changes can apply in both cases instead of silently failing in one of them?

[borgmatic/config/validate.py](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/master/borgmatic/config/validate.py#L101-L102)

Steps to reproduce (if a bug)

hooks:
  healthchecks: https://hc-ping.com/UUID1
borgmatic check --config /etc/borgmatic/config.yaml -v 1 --override hooks.healthchecks=https://hc-ping.com/UUID2

Actual behavior (if a bug)

Jul 05 21:10:18 server borgmatic[8923]: CRITICAL An error occurred while parsing a configuration file at /etc/borgmatic/config.yaml:
    At 'hooks.healthchecks': 'https://hc-ping.com/UUID2' is not of type 'object'
Jul 05 21:10:18 server pipenv[8923]: /etc/borgmatic/config.yaml: No valid configuration files found
Jul 05 21:10:18 server borgmatic[8923]: CRITICAL /etc/borgmatic/config.yaml: No valid configuration files found       
Jul 05 21:10:18 server borgmatic[8923]: CRITICAL
Jul 05 21:10:18 server pipenv[8923]: Need some help? https://torsion.org/borgmatic/#issues
Jul 05 21:10:18 server borgmatic[8923]: CRITICAL Need some help? https://torsion.org/borgmatic/#issues
Jul 05 21:10:18 server systemd[1]: borgmatic.service: Main process exited, code=exited, status=1/FAILURE
Jul 05 21:10:18 server systemd[1]: borgmatic.service: Failed with result 'exit-code'.
Jul 05 21:10:18 server systemd[1]: Failed to start Run system-wide Borgmatic backups.

Expected behavior (if a bug)

That the command line --override is also normalised in the same way, which makes it compatible with hooks.healthchecks being an object, not a string

Other notes / implementation ideas

Environment

borgmatic version: 1.6.3

Use sudo borgmatic --version or sudo pip show borgmatic | grep ^Version

borgmatic installation method: pipenv

Borg version: 1.2.1

Use sudo borg --version

Python version: 3.9.2

Use python3 --version

Database version (if applicable): n/a

Use psql --version or mysql --version on client and server.

operating system and version: Debian 11

#### What I'm trying to do and why Since commit `02781662f85bcdbab795bf67fdecf28f85cb50d7` the `healthchecks` configuration changed from a simple string to an object. This is backwards compatible within the configuration file because the `normalize` function will upgrade the configuration on-the-fly. However this normalisation happens before overrides are applied ([`borgmatic/config/validate.py`](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/master/borgmatic/config/validate.py#L101-L102)), so if you have an override to ping a different Healthcheck (which I currently do before I switch to `ntfy`) then this will fail "silently" without sending a failure ping because the Healthchecks config is invalid Maybe it would be better to override _before_ normalising so that these dynamic changes can apply in both cases instead of silently failing in one of them? `[borgmatic/config/validate.py](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/master/borgmatic/config/validate.py#L101-L102)` #### Steps to reproduce (if a bug) ```yaml hooks: healthchecks: https://hc-ping.com/UUID1 ``` ```sh borgmatic check --config /etc/borgmatic/config.yaml -v 1 --override hooks.healthchecks=https://hc-ping.com/UUID2 ``` #### Actual behavior (if a bug) ``` Jul 05 21:10:18 server borgmatic[8923]: CRITICAL An error occurred while parsing a configuration file at /etc/borgmatic/config.yaml: At 'hooks.healthchecks': 'https://hc-ping.com/UUID2' is not of type 'object' Jul 05 21:10:18 server pipenv[8923]: /etc/borgmatic/config.yaml: No valid configuration files found Jul 05 21:10:18 server borgmatic[8923]: CRITICAL /etc/borgmatic/config.yaml: No valid configuration files found Jul 05 21:10:18 server borgmatic[8923]: CRITICAL Jul 05 21:10:18 server pipenv[8923]: Need some help? https://torsion.org/borgmatic/#issues Jul 05 21:10:18 server borgmatic[8923]: CRITICAL Need some help? https://torsion.org/borgmatic/#issues Jul 05 21:10:18 server systemd[1]: borgmatic.service: Main process exited, code=exited, status=1/FAILURE Jul 05 21:10:18 server systemd[1]: borgmatic.service: Failed with result 'exit-code'. Jul 05 21:10:18 server systemd[1]: Failed to start Run system-wide Borgmatic backups. ``` #### Expected behavior (if a bug) That the command line `--override` is also normalised in the same way, which makes it compatible with `hooks.healthchecks` being an object, not a string #### Other notes / implementation ideas #### Environment **borgmatic version:** 1.6.3 Use `sudo borgmatic --version` or `sudo pip show borgmatic | grep ^Version` **borgmatic installation method:** `pipenv` **Borg version:** 1.2.1 Use `sudo borg --version` **Python version:** 3.9.2 Use `python3 --version` **Database version (if applicable):** n/a Use `psql --version` or `mysql --version` on client and server. **operating system and version:** Debian 11
Owner

Good catch! I apologize for the breakage. I think the solution you suggest (apply overrides before normalization) makes sense. I'd just have to make sure that if you pass in old-style overrides using a new-style configuration file, the override would still replace the existing configuration.

Good catch! I apologize for the breakage. I think the solution you suggest (apply overrides before normalization) makes sense. I'd just have to make sure that if you pass in old-style overrides using a new-style configuration file, the override would still replace the existing configuration.
witten added the
bug
label 2022-07-05 23:06:34 +00:00
Author
Contributor

No need to apologise, it's a breakage of my own making since I probably didn't bother reading the release notes last time I upgraded :)

It's just an unfortunate one because the config being invalid means that borgmatic never runs, so it won't even send a failure ping. Also that second UUID I set up with Healthchecks doesn't nag every day if the maintenance (check, prune) phases don't run so I hadn't noticed they weren't running for a short while.

No need to apologise, it's a breakage of my own making since I probably didn't bother reading the release notes last time I upgraded :) It's just an unfortunate one because the config being invalid means that `borgmatic` never runs, so it won't even send a failure ping. Also that second UUID I set up with Healthchecks doesn't nag every day if the maintenance (check, prune) phases don't run so I hadn't noticed they weren't running for a short while.
Owner

This is fixed in master and will be part of the next release. Thanks again for reporting it!

This is fixed in master and will be part of the next release. Thanks again for reporting it!
Owner

This has been released in borgmatic 1.6.6!

This has been released in borgmatic 1.6.6!
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#561
No description provided.