Skip to content

Add Healthchecks UUIDFile retrieval functionality#1642

Open
mjlynden wants to merge 3 commits intocrazy-max:masterfrom
mjlynden:healthchecks_uuidFile
Open

Add Healthchecks UUIDFile retrieval functionality#1642
mjlynden wants to merge 3 commits intocrazy-max:masterfrom
mjlynden:healthchecks_uuidFile

Conversation

@mjlynden
Copy link
Copy Markdown

Retrieve a Healtchecks UUID from a file containing a Healthchecks UUID using the environment variable DIUN_WATCH_HEALTHCHECKS_UUIDFILE.

Comment thread internal/app/hc.go Outdated
Comment on lines +19 to +23
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
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants