Skip to content

Commit

Permalink
Go stable (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpetersen authored Oct 14, 2021
1 parent ef04235 commit 47e765f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2021-10-14
### Added
- Stable release.

## [0.1.0] - 2021-10-14
### Added
- Godoc examples.
Expand Down
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resources asynchronously with built-in caching and timeouts. Only what you absol
## Quickstart
Install the package:
```sh
go get github.com/jaredpetersen/go-health/health@latest
go get github.com/jaredpetersen/go-health/health
```

Example:
Expand Down Expand Up @@ -54,20 +54,19 @@ health check endpoints in an attempt to abuse and take down multiple systems in
The best defense against this is to perform those checks on your schedule asynchronously, not the caller's schedule.
Results from those checks should be cached and returned upon request.

This package spins up a goroutine for each configured health check that polls each check function. Each check has its
This package spins up a goroutine for each configured health check that polls the check function. Each check has its
own, individually configurable Time To Live (TTL) that dictates the duration between those polls. For example, if you
specify a check with a TTL of two seconds, the check will execute, wait two seconds, and then execute again and again
until the context is closed.
specify a check with a TTL of two seconds, the check will execute, wait two seconds, and then execute again. This will
go on forever until the context is closed.

By default, all checks created via `health.NewCheck()` are configured with a default TTL of one second.

## Timeouts
You can optionally configure a timeout for each check. If set, the context provided to the function defined on the
check will have a deadline set. When the deadline expires, the context will close the Done channel, just like the
normal context behavior. go-health does not automatically kill the check execution, it only leverages the context
to communicate that the configured timeout deadline has been exceeded. It is your responsibility to handle the context
appropriately. For more information on context with deadline, see the
[context documentation](https://pkg.go.dev/context#WithDeadline).
You can optionally configure a timeout for each check. If set, the context provided to the check function will have a
deadline set. When the deadline expires, the context will close the Done channel, just like the normal context
behavior. go-health does not kill the check function execution, it only leverages the context to communicate that
the configured timeout deadline has been exceeded. It is your responsibility to handle the context appropriately. For
more information on context with deadline, see the [context documentation](https://pkg.go.dev/context#WithDeadline).

## Additional Information
The return type of the health check function supports adding arbitrary information to the status. This could be
Expand Down
8 changes: 4 additions & 4 deletions health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"
)

// State represents the health of the resource being checked as a simple value.
// State represents the health of the resource being checked as a simple indicator.
type State int

// States must be ordered from most degraded to least degraded here so that checks work their way up to the best state.
Expand All @@ -31,15 +31,15 @@ type MonitorStatus struct {
CheckStatuses map[string]CheckStatus
}

// CheckStatus indicates the health of an individual check and when that information was retrieved.
// CheckStatus indicates the health of an individual check and when that information was determined.
type CheckStatus struct {
// Status of the resource.
Status Status
// Timestamp is the time the status was determined.
Timestamp time.Time
}

// Status indicates resource health state and contains any additional, arbitrary details that may be relevant.
// Status indicates resource health state and may contain any additional, arbitrary details that are relevant.
type Status struct {
// State is a high level indicator for resource health.
State State
Expand Down Expand Up @@ -103,7 +103,7 @@ func (mtr *Monitor) setCheckStatus(checkName string, checkStatus CheckStatus) {
mtr.mtx.Unlock()
}

// Monitor starts a goroutine for each check the executes the check's function and caches the result. This goroutine
// Monitor starts a goroutine for each check that executes the check's function and caches the result. This goroutine
// will wait between polls as defined by check's TTL to avoid spamming the resource being evaluated. If a timeout is
// set on the check, the context provided to Monitor will be wrapped in a deadline context and provided to the check
// function to facilitate early termination.
Expand Down

0 comments on commit 47e765f

Please sign in to comment.