checkup

package module
v0.0.0-...-a2e2abe Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2017 License: MIT Imports: 13 Imported by: 0

README

Checkup

Checkup is a nice project, but it depends on a very large library for AWS that we don't use. To avoid the cost of this library, we just use a subset of checkup, by just downloading the 2 files that interest us and mocking some structs.

See https://github.com/sourcegraph/checkup

Documentation

Overview

Package checkup provides means for checking and reporting the status and performance of various endpoints in a distributed, lock-free, self-hosted fashion.

Index

Constants

View Source
const FilenameFormatString = "%d-check.json"

FilenameFormatString is the format string used by GenerateFilename to create a filename.

Variables

View Source
var DefaultConcurrentChecks = 5

DefaultConcurrentChecks is how many checks, at most, to perform concurrently.

View Source
var DefaultHTTPClient = &http.Client{
	Transport: &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		Dial: (&net.Dialer{
			Timeout:   10 * time.Second,
			KeepAlive: 0,
		}).Dial,
		TLSHandshakeTimeout:   5 * time.Second,
		ExpectContinueTimeout: 1 * time.Second,
		MaxIdleConnsPerHost:   1,
		DisableCompression:    true,
		DisableKeepAlives:     true,
		ResponseHeaderTimeout: 5 * time.Second,
	},
	CheckRedirect: func(req *http.Request, via []*http.Request) error {
		return http.ErrUseLastResponse
	},
	Timeout: 10 * time.Second,
}

DefaultHTTPClient is used when no other http.Client is specified on a HTTPChecker.

Functions

func GenerateFilename

func GenerateFilename() *string

GenerateFilename returns a filename that is ideal for storing the results file on a storage provider that relies on the filename for retrieval that is sorted by date/timeframe. It returns a string pointer to be used by the AWS SDK...

func Timestamp

func Timestamp() int64

Timestamp returns the UTC Unix timestamp in nanoseconds.

Types

type Attempt

type Attempt struct {
	RTT   time.Duration `json:"rtt"`
	Error string        `json:"error,omitempty"`
}

Attempt is an attempt to communicate with the endpoint.

type Attempts

type Attempts []Attempt

Attempts is a list of Attempt that can be sorted by RTT.

func (Attempts) Len

func (a Attempts) Len() int

func (Attempts) Less

func (a Attempts) Less(i, j int) bool

func (Attempts) Swap

func (a Attempts) Swap(i, j int)

type Checker

type Checker interface {
	Check() (Result, error)
}

Checker can create a Result.

type Checkup

type Checkup struct {
	// Checkers is the list of Checkers to use with
	// which to perform checks.
	Checkers []Checker `json:"checkers,omitempty"`

	// ConcurrentChecks is how many checks, at most, to
	// perform concurrently. Default is
	// DefaultConcurrentChecks.
	ConcurrentChecks int `json:"concurrent_checks,omitempty"`

	// Timestamp is the timestamp to force for all checks.
	// Useful if wanting to perform distributed check
	// "at the same time" even if they might actually
	// be a few milliseconds or seconds apart.
	Timestamp time.Time `json:"timestamp,omitempty"`

	// Storage is the storage mechanism for saving the
	// results of checks. Required if calling Store().
	// If Storage is also a Maintainer, its Maintain()
	// method will be called by c.CheckAndStore().
	Storage Storage `json:"storage,omitempty"`

	// Notifier is a notifier that will be passed the
	// results after checks from all checkers have
	// completed. Notifier may evaluate and choose to
	// send a notification of potential problems.
	Notifier Notifier `json:"notifier,omitempty"`
}

Checkup performs a routine checkup on endpoints or services.

func (Checkup) Check

func (c Checkup) Check() ([]Result, error)

Check performs the health checks. An error is only returned in the case of a misconfiguration or if any one of the Checkers returns an error.

func (Checkup) CheckAndStore

func (c Checkup) CheckAndStore() error

CheckAndStore performs health checks and immediately stores the results to the configured storage if there were no errors. Checks are not performed if c.Storage is nil. If c.Storage is also a Maintainer, Maintain() will be called if Store() is successful.

func (Checkup) CheckAndStoreEvery

func (c Checkup) CheckAndStoreEvery(interval time.Duration) *time.Ticker

CheckAndStoreEvery calls CheckAndStore every interval. It returns the ticker that it's using so you can stop it when you don't want it to run anymore. This function does NOT block (it runs the ticker in a goroutine). Any errors are written to the standard logger. It would not be wise to set an interval lower than the time it takes to perform the checks.

func (Checkup) MarshalJSON

func (c Checkup) MarshalJSON() ([]byte, error)

MarshalJSON marshals c into JSON with type information included on the interface values.

func (*Checkup) UnmarshalJSON

func (c *Checkup) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshales b into c. To succeed, it requires type information for the interface values.

type DNSChecker

type DNSChecker struct{}

DNSChecker is a fake struct to make checkup.go compile

func (DNSChecker) Check

func (c DNSChecker) Check() (Result, error)

Check is not implemented

type Errors

type Errors []error

Errors is an error type that concatenates multiple errors.

func (Errors) Empty

func (e Errors) Empty() bool

Empty returns whether e has any non-nil errors in it.

func (Errors) Error

func (e Errors) Error() string

Error returns a string containing all the errors in e.

type FS

type FS struct{}

FS is a fake struct to make checkup.go compile

func (FS) Store

func (fs FS) Store(results []Result) error

Store is not implemented

type HTTPChecker

type HTTPChecker struct {
	// Name is the name of the endpoint.
	Name string `json:"endpoint_name"`

	// URL is the URL of the endpoint.
	URL string `json:"endpoint_url"`

	// UpStatus is the HTTP status code expected by
	// a healthy endpoint. Default is http.StatusOK.
	UpStatus int `json:"up_status,omitempty"`

	// ThresholdRTT is the maximum round trip time to
	// allow for a healthy endpoint. If non-zero and a
	// request takes longer than ThresholdRTT, the
	// endpoint will be considered unhealthy. Note that
	// this duration includes any in-between network
	// latency.
	ThresholdRTT time.Duration `json:"threshold_rtt,omitempty"`

	// MustContain is a string that the response body
	// must contain in order to be considered up.
	// NOTE: If set, the entire response body will
	// be consumed, which has the potential of using
	// lots of memory and slowing down checks if the
	// response body is large.
	MustContain string `json:"must_contain,omitempty"`

	// MustNotContain is a string that the response
	// body must NOT contain in order to be considered
	// up. If both MustContain and MustNotContain are
	// set, they are and-ed together. NOTE: If set,
	// the entire response body will be consumed, which
	// has the potential of using lots of memory and
	// slowing down checks if the response body is large.
	MustNotContain string `json:"must_not_contain,omitempty"`

	// Attempts is how many requests the client will
	// make to the endpoint in a single check.
	Attempts int `json:"attempts,omitempty"`

	// AttemptSpacing spaces out each attempt in a check
	// by this duration to avoid hitting a remote too
	// quickly in succession. By default, no waiting
	// occurs between attempts.
	AttemptSpacing time.Duration `json:"attempt_spacing,omitempty"`

	// Client is the http.Client with which to make
	// requests. If not set, DefaultHTTPClient is
	// used.
	Client *http.Client `json:"-"`

	// Headers contains headers to added to the request
	// that is sent for the check
	Headers http.Header `json:"headers,omitempty"`
}

HTTPChecker implements a Checker for HTTP endpoints.

func (HTTPChecker) Check

func (c HTTPChecker) Check() (Result, error)

Check performs checks using c according to its configuration. An error is only returned if there is a configuration error.

type Maintainer

type Maintainer interface {
	Maintain() error
}

Maintainer can maintain a store of results by deleting old check files that are no longer needed or performing other required tasks.

type Notifier

type Notifier interface {
	Notify([]Result) error
}

Notifier can notify ops or sysadmins of potential problems. A Notifier should keep state to avoid sending repeated notices more often than the admin would like.

type ProvisionInfo

type ProvisionInfo struct {
	// The ID of a user that was created for accessing checks.
	UserID string `json:"user_id"`

	// The username of a user that was created for accessing checks.
	Username string `json:"username"`

	// The ID or name of the ID/key used to access checks. Expect
	// this value to be made public. (It should have read-only
	// access to the checks.)
	PublicAccessKeyID string `json:"public_access_key_id"`

	// The "secret" associated with the PublicAccessKeyID, but
	// expect this value to be made public. (It should provide
	// read-only access to the checks.)
	PublicAccessKey string `json:"public_access_key"`
}

ProvisionInfo contains the results of provisioning a new storage facility for check files. Its values should be used by the status page in order to obtain read-only access to the check files.

func (ProvisionInfo) String

func (i ProvisionInfo) String() string

String returns the information in i in a human-readable format along with an important notice.

type Provisioner

type Provisioner interface {
	Provision() (ProvisionInfo, error)
}

Provisioner is a type of storage mechanism that can provision itself for use with checkup. Provisioning need only happen once and is merely a convenience so that the user can get up and running with their status page more quickly. Presumably, the info returned from Provision should be used on the status page side of things ot access the check files (like a key pair that is used for read-only access).

type Result

type Result struct {
	// Title is the title (or name) of the thing that was checked.
	// It should be unique, as it acts like an identifier to users.
	Title string `json:"title,omitempty"`

	// Endpoint is the URL/address/path/identifier/locator/whatever
	// of what was checked.
	Endpoint string `json:"endpoint,omitempty"`

	// Timestamp is when the check occurred; UTC UnixNano format.
	Timestamp int64 `json:"timestamp,omitempty"`

	// Times is a list of each individual check attempt.
	Times Attempts `json:"times,omitempty"`

	// ThresholdRTT is the maximum RTT that was tolerated before
	// considering performance to be degraded. Leave 0 if irrelevant.
	ThresholdRTT time.Duration `json:"threshold,omitempty"`

	// Healthy, Degraded, and Down contain the ultimate conclusion
	// about the endpoint. Exactly one of these should be true;
	// any more or less is a bug.
	Healthy  bool `json:"healthy,omitempty"`
	Degraded bool `json:"degraded,omitempty"`
	Down     bool `json:"down,omitempty"`

	// Notice contains a description of some condition of this
	// check that might have affected the result in some way.
	// For example, that the median RTT is above the threshold.
	Notice string `json:"notice,omitempty"`

	// Message is an optional message to show on the status page.
	// For example, what you're doing to fix a problem.
	Message string `json:"message,omitempty"`
}

Result is the result of a health check.

func (Result) ComputeStats

func (r Result) ComputeStats() Stats

ComputeStats computes basic statistics about r.

func (Result) Status

func (r Result) Status() StatusText

Status returns a text representation of the overall status indicated in r.

func (Result) String

func (r Result) String() string

String returns a human-readable rendering of r.

type S3

type S3 struct{}

S3 is a fake struct to make checkup.go compile

func (S3) Store

func (s S3) Store(results []Result) error

Store is not implemented

type Stats

type Stats struct {
	Total  time.Duration `json:"total,omitempty"`
	Mean   time.Duration `json:"mean,omitempty"`
	Median time.Duration `json:"median,omitempty"`
	Min    time.Duration `json:"min,omitempty"`
	Max    time.Duration `json:"max,omitempty"`
}

Stats is a type that holds information about a Result, especially its various Attempts.

type StatusText

type StatusText string

StatusText is the textual representation of the result of a status check.

const (
	Healthy  StatusText = "healthy"
	Degraded StatusText = "degraded"
	Down     StatusText = "down"
	Unknown  StatusText = "unknown"
)

Text representations for the status of a check.

func (StatusText) PriorityOver

func (s StatusText) PriorityOver(other StatusText) bool

PriorityOver returns whether s has priority over other. For example, a Down status has priority over Degraded.

type Storage

type Storage interface {
	Store([]Result) error
}

Storage can store results.

type TCPChecker

type TCPChecker struct{}

TCPChecker is a fake struct to make checkup.go compile

func (TCPChecker) Check

func (c TCPChecker) Check() (Result, error)

Check is not implemented

Jump to

Keyboard shortcuts

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