forked from rcrowley/go-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mostly documentation and naming changes.
Undoubtedly this commit doesn't build or test but it's part of a larger series of intertwined changes.
- Loading branch information
Showing
10 changed files
with
237 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,61 @@ | ||
package metrics | ||
|
||
// Healthchecks hold an os.Error value describing an arbitrary up/down status. | ||
// | ||
// This is an interface so as to encourage other structs to implement | ||
// the Healthcheck API as appropriate. | ||
// Healthchecks hold an error value describing an arbitrary up/down status. | ||
type Healthcheck interface { | ||
Check() | ||
Error() error | ||
Healthy() | ||
Unhealthy(error) | ||
} | ||
|
||
// Create a new Healthcheck, which will use the given function to update | ||
// its status. | ||
// NewHealthcheck constructs a new Healthcheck which will use the given | ||
// function to update its status. | ||
func NewHealthcheck(f func(Healthcheck)) Healthcheck { | ||
if UseNilMetrics { | ||
return NilHealthcheck{} | ||
} | ||
return &StandardHealthcheck{nil, f} | ||
} | ||
|
||
// No-op Healthcheck. | ||
// NilHealthcheck is a no-op. | ||
type NilHealthcheck struct{} | ||
|
||
// No-op. | ||
// Check is a no-op. | ||
func (NilHealthcheck) Check() {} | ||
|
||
// No-op. | ||
// Error is a no-op. | ||
func (NilHealthcheck) Error() error { return nil } | ||
|
||
// No-op. | ||
// Healthy is a no-op. | ||
func (NilHealthcheck) Healthy() {} | ||
|
||
// No-op. | ||
func (NilHealthcheck) Unhealthy(err error) {} | ||
// Unhealthy is a no-op. | ||
func (NilHealthcheck) Unhealthy(error) {} | ||
|
||
// The standard implementation of a Healthcheck stores the status and a | ||
// function to call to update the status. | ||
// StandardHealthcheck is the standard implementation of a Healthcheck and | ||
// stores the status and a function to call to update the status. | ||
type StandardHealthcheck struct { | ||
err error | ||
f func(Healthcheck) | ||
} | ||
|
||
// Update the healthcheck's status. | ||
// Check runs the healthcheck function to update the healthcheck's status. | ||
func (h *StandardHealthcheck) Check() { | ||
h.f(h) | ||
} | ||
|
||
// Return the healthcheck's status, which will be nil if it is healthy. | ||
// Error returns the healthcheck's status, which will be nil if it is healthy. | ||
func (h *StandardHealthcheck) Error() error { | ||
return h.err | ||
} | ||
|
||
// Mark the healthcheck as healthy. | ||
// Healthy marks the healthcheck as healthy. | ||
func (h *StandardHealthcheck) Healthy() { | ||
h.err = nil | ||
} | ||
|
||
// Mark the healthcheck as unhealthy. The error should provide details. | ||
// Unhealthy marks the healthcheck as unhealthy. The error is stored and | ||
// may be retrieved by the Error method. | ||
func (h *StandardHealthcheck) Unhealthy(err error) { | ||
h.err = err | ||
} |
Oops, something went wrong.