-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a ping checker #3 #6
Conversation
checks/ping.go
Outdated
return &CustomCheck{ | ||
CheckName: name, | ||
CheckFunc: func() (details interface{}, err error) { | ||
pingCtx, _ := context.WithTimeout(context.Background(), timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-cancelled contexts are the most common forms of memory leaks in go. I would add defer cancel()
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You were faster :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit, I committed without running the build locally :P
For example, you can use it as a DB ping check (`sql.DB` implements the Pinger interface): | ||
```go | ||
db, err := sql.Open(...) | ||
dbCheck, err := checks.NewPingCheck("db.check", db, time.Millisecond*100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably add a checks.Must
function here with the func(check Check, err error)
signature, so that checks initialized in a main
function can panic. I find a commonly applied practice to interrupt application bootstrap and exit with panic if something goes wrong.
Obviously that's optional and could be part of a subsequent PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, but I need to read about this pattern. I'm still green in golang ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Added a ping checker as requested in #3