Documentation ¶
Overview ¶
Package internal contains healthchecks.io HTTP API client implementation for cmd/runitor's use.
It is not intended to be used as a standalone client package.
Index ¶
Constants ¶
const ( // Default Healthchecks API address. DefaultBaseURL = "https://hc-ping.com" // Default HTTP client timeout. DefaultTimeout = 5 * time.Second // Default number of retries. DefaultRetries = 2 )
Variables ¶
var ( ErrNonRetriable = errors.New("nonretriable error response") ErrMaxTries = errors.New("max tries reached") )
var ErrReadOnly = errors.New("read only")
ErrReadOnly is the error returned by Write to indicate the ring buffer is in read only mode and will not accept further writes.
Functions ¶
func NewDefaultTransportWithResumption ¶ added in v0.8.0
NewDefaultTransportWithResumption returns an http.Transport based on http.DefaultTransport with a TLS Client Session Cache, to enable TLS session resumption.
Types ¶
type APIClient ¶
type APIClient struct { // BaseURL is the base URL of Healthchecks API instance BaseURL string // BaseURL of the Healthchecks API // Retries is the number of times the pinger will retry an API request // if it fails with a timeout or temporary kind of error, or an HTTP // status of 408 or 5XX. Retries int // UserAgent, when non-empty, is the value of 'User-Agent' HTTP header // for outgoing requests. UserAgent string // Backoff is the duration used as the unit of linear backoff. Backoff time.Duration // Embed *http.Client }
APIClient holds API endpoint URL, client behavior configuration, and embeds http.Client.
func (*APIClient) PingFailure ¶
PingFailure sends a Fail Ping for the check with passed uuid and attaches body as the logged context.
func (*APIClient) PingStart ¶
PingStart sends a Start Ping for the check with passed uuid and attaches body as the logged context.
func (*APIClient) PingSuccess ¶
PingSuccess sends a Success Ping for the check with passed uuid and attaches body as the logged context.
func (*APIClient) Post ¶
Post wraps embedded http.Client's Post to implement simple retry logic and custom User-Agent header injection.
Retries: The implementation is inspired from Curl's. Request timeouts and temporary network level errors will be retried. Responses with status codes 408 and 5XX are also retried. Unlike Curl's, the backoff implementation is linear instead of exponential. First retry waits for 1 second, second one waits for 2 seconds, and so on.
User-Agent: If c.UserAgent is not empty, it overrides http.Client's default header.
type Pinger ¶
type Pinger interface { PingStart(uuid string, body io.Reader) error PingSuccess(uuid string, body io.Reader) error PingFailure(uuid string, body io.Reader) error }
Pinger is the interface to Healthchecks.io pinging API https://healthchecks.io/docs/http_api/
type RingBuffer ¶ added in v0.7.0
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer implements io.ReadWriter interface to a []byte backed ring buffer (aka circular buffer).
Can be written to repeatedly until read from. At first read, ring buffer becomes read only, refusing further writes with ErrReadOnly error.
func NewRingBuffer ¶ added in v0.7.0
func NewRingBuffer(cap int) *RingBuffer
NewRingBuffer allocates a new RingBuffer and the backing byte array with specified capacity.
func (*RingBuffer) Cap ¶ added in v0.7.0
func (r *RingBuffer) Cap() int
Cap returns the capacity of the ring buffer.
func (*RingBuffer) Len ¶ added in v0.7.0
func (r *RingBuffer) Len() int
Len returns the length of the ring buffer.
func (*RingBuffer) Snapshot ¶ added in v0.7.0
func (r *RingBuffer) Snapshot() []byte
Snapshot returns a clone of r.buf
Currently only intended for testing.
func (*RingBuffer) Wrapped ¶ added in v0.7.0
func (r *RingBuffer) Wrapped() bool
Wrapped returns true if the ring buffer overwrote at least one byte.