Healthchecks: do not ping "[successful] finish" state after warning/error occured #888

Closed
opened 2024-06-25 16:16:20 +00:00 by chrisblech · 3 comments

What I'm trying to do and why

I'm using healthchecks.io (and its status-badge PNG) to monitor the success of my backups.

When where is an error/warning during backup, borgmatic pings the healthchecks "fail" endpoint. This is correct: healthchecks sends an alert, and its status-badge turns to red. This is exactly how it should work.

Some seconds later, when the backup task completes, borgmatic pings healthchecks again, now to the "finish" endpoint. This makes healthchecks think the failure-state has recovered: it sends an "recovered" alert, and the status-badge PNG turns back to green.

Steps to reproduce

location:
    source_directories:
        - /var/discourse
        - /var/backup-docker-volumes
    repositories:
        - ssh://[redacted].your-storagebox.de:23/./borg
storage:
    encryption_passphrase: [redacted]
retention:
    keep_daily: 7
    keep_weekly: 4
    keep_monthly: 12
consistency:
    checks:
        - name: data
hooks:
    before_everything:
        - backup-docker-volumes.sh all
    healthchecks:
        ping_url: https://hc.hosrv.de/ping/[redacted]
        ping_body_limit: 0

Actual behavior

Ping #305 (received via the /fail endpoint)
2024-06-20T02:20:52.294315+00:00:

ssh://[redacted].your-storagebox.de:23/./borg: Error running actions for repository
Command 'borg prune --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --glob-archives {hostname}-* ssh://[redacted].your-storagebox.de:23/./borg' returned non-zero exit status 2

Ping #306: OK
2024-06-20T02:53:35.110450+00:00

Expected behavior

After an error occured (and healthchecks "fail" endpoint was pinged), bormatic should not ping healthchecks after the backup finished, or include status code in finish endpoint (see https://healthchecks.io/docs/signaling_failures/ )

Other notes / implementation ideas

No response

borgmatic version

1.7.7

borgmatic installation method

Debian package

Borg version

borg 1.2.4

Python version

Python 3.11.2

Database version (if applicable)

No response

Operating system and version

Debian GNU/Linux 12 (bookworm)

### What I'm trying to do and why I'm using healthchecks.io (and its status-badge PNG) to monitor the success of my backups. When where is an error/warning during backup, borgmatic pings the healthchecks "fail" endpoint. This is correct: healthchecks sends an alert, and its status-badge turns to red. This is exactly how it should work. Some seconds later, when the backup task completes, borgmatic pings healthchecks again, now to the "finish" endpoint. This makes healthchecks think the failure-state has recovered: it sends an "recovered" alert, and the status-badge PNG turns back to green. ### Steps to reproduce ``` location: source_directories: - /var/discourse - /var/backup-docker-volumes repositories: - ssh://[redacted].your-storagebox.de:23/./borg storage: encryption_passphrase: [redacted] retention: keep_daily: 7 keep_weekly: 4 keep_monthly: 12 consistency: checks: - name: data hooks: before_everything: - backup-docker-volumes.sh all healthchecks: ping_url: https://hc.hosrv.de/ping/[redacted] ping_body_limit: 0 ``` ### Actual behavior Ping #305 (received via the /fail endpoint) 2024-06-20T02:20:52.294315+00:00: ssh://[redacted].your-storagebox.de:23/./borg: Error running actions for repository Command 'borg prune --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --glob-archives {hostname}-* ssh://[redacted].your-storagebox.de:23/./borg' returned non-zero exit status 2 Ping #306: OK 2024-06-20T02:53:35.110450+00:00 ### Expected behavior After an error occured (and healthchecks "fail" endpoint was pinged), bormatic should not ping healthchecks after the backup finished, or include status code in finish endpoint (see https://healthchecks.io/docs/signaling_failures/ ) ### Other notes / implementation ideas _No response_ ### borgmatic version 1.7.7 ### borgmatic installation method Debian package ### Borg version borg 1.2.4 ### Python version Python 3.11.2 ### Database version (if applicable) _No response_ ### Operating system and version Debian GNU/Linux 12 (bookworm)
Owner

Interesting... I've looked at the code in question from borgmatic 1.7.7, and the behavior you're seeing shouldn't be possible. However there is a theoretical code path where the following related scenario can happen:

  1. borgmatic finishes normally and pings the Healthchecks "finish" endpoint.
  2. borgmatic encounters an error in the act of pinging that "finish" endpoint. (Network error, etc.)
  3. borgmatic pings the Healthchecks "fail" endpoint.

(Note that this same scenario does not work the same way in newer versions of borgmatic.)

So are you sure about the "fail" then "finish" ordering?

Also can I get a look at your (redacted) borgmatic logs? That might help pinpoint what's going on. Thanks!

Interesting... I've looked at the code in question from borgmatic 1.7.7, and the behavior you're seeing _shouldn't_ be possible. However there is a theoretical code path where the following related scenario can happen: 1. borgmatic finishes normally and pings the Healthchecks "finish" endpoint. 2. borgmatic encounters an error in the act of pinging that "finish" endpoint. (Network error, etc.) 3. borgmatic pings the Healthchecks "fail" endpoint. (Note that this same scenario does not work the same way in newer versions of borgmatic.) So are you sure about the "fail" _then_ "finish" ordering? Also can I get a look at your (redacted) borgmatic logs? That might help pinpoint what's going on. Thanks!
Author

While collecting logs (see attachment), I realized that borgmatic seemed to start twice on this host: once via /etc/crontab and once via systemd.timer.

This should explain the cause of the error (could not aquire exclusive lock) and also the order of the healthchecks ping events.

So I deleted the crontab-line and close this issue.

While collecting logs (see attachment), I realized that borgmatic seemed to start twice on this host: once via `/etc/crontab` and once via systemd.timer. This should explain the cause of the error (could not aquire exclusive lock) and also the order of the healthchecks ping events. So I deleted the crontab-line and close this issue.
Owner

Wow, good sleuthing! I'm glad to hear that resolved it.

Wow, good sleuthing! I'm glad to hear that resolved it.
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#888
No description provided.