[uptime-kuma] Omit trailing slash when path annotation not set

## Context

After commit f6812fe6 every external-monitor-sync run updated all ~107
monitors without any real change — because the new code always appended
`/` to the host (default path), while historical monitors had been
created with bare `https://host` URLs. Sync saw `https://host` !=
`https://host/` and re-wrote every monitor on each cycle: noisy logs,
wasted Uptime Kuma writes.

## This change

When the `uptime.viktorbarzin.me/external-monitor-path` annotation is
absent, build the URL WITHOUT a trailing slash so it matches the shape
of pre-existing monitors. When the annotation is set, append it as
before (e.g. `https://forgejo.viktorbarzin.me/api/healthz`).

Also flip the lenient/strict codes branch to trigger off the same
"annotation set?" signal instead of comparing against DEFAULT_PATH.

## Verification

Verified via two consecutive manual triggers of the CronJob against the
live stack:

    Pass 1 (migration): 0 created, 107 updated, 0 deleted, 1 unchanged
    Pass 2 (stable):    0 created,   0 updated, 0 deleted, 108 unchanged

`[External] forgejo` still probes `https://forgejo.viktorbarzin.me/api/healthz`
with strict `200-299`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Viktor Barzin 2026-04-17 22:41:02 +00:00
parent b30bfd4690
commit 99688bbb02

View file

@ -384,11 +384,14 @@ def load_from_api():
if monitor_name in seen:
continue # dedupe by final monitor name, not hostname (fixes duplicate creation)
seen.add(monitor_name)
path = anns.get(ANNOTATION_PATH) or DEFAULT_PATH
if not path.startswith("/"):
path = anns.get(ANNOTATION_PATH, "").strip()
if path and not path.startswith("/"):
path = "/" + path
statuscodes = STATUSCODES_STRICT if path != DEFAULT_PATH else STATUSCODES_LENIENT
targets.append({"name": label, "url": f"https://{host}{path}", "statuscodes": statuscodes})
# Omit trailing slash when no explicit path matches pre-existing monitor URLs
# and avoids every sync re-updating unchanged monitors.
url = f"https://{host}{path}" if path else f"https://{host}"
statuscodes = STATUSCODES_STRICT if path else STATUSCODES_LENIENT
targets.append({"name": label, "url": url, "statuscodes": statuscodes})
return targets