internal

package
v0.8.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2021 License: 0BSD Imports: 7 Imported by: 0

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

View Source
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

View Source
var (
	ErrNonRetriable = errors.New("nonretriable error response")
	ErrMaxTries     = errors.New("max tries reached")
)
View Source
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

func NewDefaultTransportWithResumption() *http.Transport

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

func (c *APIClient) PingFailure(uuid string, body io.Reader) error

PingFailure sends a Fail Ping for the check with passed uuid and attaches body as the logged context.

func (*APIClient) PingStart

func (c *APIClient) PingStart(uuid string, body io.Reader) error

PingStart sends a Start Ping for the check with passed uuid and attaches body as the logged context.

func (*APIClient) PingSuccess

func (c *APIClient) PingSuccess(uuid string, body io.Reader) error

PingSuccess sends a Success Ping for the check with passed uuid and attaches body as the logged context.

func (*APIClient) Post

func (c *APIClient) Post(url, contentType string, body io.Reader) (resp *http.Response, err error)

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) Read added in v0.7.0

func (r *RingBuffer) Read(p []byte) (n int, err error)

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.

func (*RingBuffer) Write added in v0.7.0

func (r *RingBuffer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL