Add Healthchecks UUIDFile retrieval functionality#1642
Add Healthchecks UUIDFile retrieval functionality#1642mjlynden wants to merge 3 commits intocrazy-max:masterfrom
Conversation
| uuid, err := utl.GetSecret(di.cfg.Watch.Healthchecks.UUID, di.cfg.Watch.Healthchecks.UUIDFile) | ||
| if err != nil { | ||
| log.Error().Err(err).Msgf("Cannot retrieve Healthchecks UUID") | ||
| return | ||
| } |
There was a problem hiding this comment.
UUID should be resolved once during Healthchecks initialization, not separately in Start, Success, and Fail.
Right now utl.GetSecret(...) reads UUIDFile on every ping path, so the configured Healthchecks target can change mid-run if the file contents change, and a transient read failure can make later events disappear even though startup succeeded. It also duplicates the same error handling three times.
I'd move the resolution to the one-time setup in app.New(), next to the existing BaseURL handling, then store the resolved UUID. That keeps one coherent UUID for the lifetime of the app and removes the repeated file reads.
There was a problem hiding this comment.
Good call. I've moved UUID resolution to app.New() with the existing BaseURL setup. hcUUID is now stored on the Diun struct and reused across each ping method; HealthchecksStart, HealthchecksSuccess, and HealthchecksFail, removing the repeated calls and duplicated error handling.
The UUID is resolved before gohealthchecks.NewClient is called since config validation already guarantees a UUID source is present when Healthchecks is configured, the practical difference is minimal, but it felt cleaner to surface any failure before allocating the client rather than after.
With the UUID fixed at startup, all three ping methods share the same value for the duration of the run, and any misconfiguration is caught immediately rather than causing a silent failure partway through.
Move `utl.GetSecret()` from the individual ping methods into `app.New()`, storing the result on the `Diun` struct. This ensures a consistent UUID for the lifetime of the app and surfaces file read failures at startup rather than mid-run.
Retrieve a Healtchecks UUID from a file containing a Healthchecks UUID using the environment variable
DIUN_WATCH_HEALTHCHECKS_UUIDFILE.