Skip to content
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

Merged
merged 2 commits into from
Aug 21, 2019
Merged

Add a ping checker #3 #6

merged 2 commits into from
Aug 21, 2019

Conversation

eranharel
Copy link
Contributor

Added a ping checker as requested in #3

@eranharel eranharel mentioned this pull request Aug 20, 2019
checks/ping.go Outdated
return &CustomCheck{
CheckName: name,
CheckFunc: func() (details interface{}, err error) {
pingCtx, _ := context.WithTimeout(context.Background(), timeout)
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

You were faster :)

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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 ;)

Copy link
Contributor

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

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

lgtm

@eranharel eranharel merged commit 2b09f5d into master Aug 21, 2019
@eranharel eranharel deleted the add-ping-checker branch August 21, 2019 08:30
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