debugstatus

package
v2.0.0-...-eedbe7b Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: LGPL-3.0 Imports: 10 Imported by: 10

Documentation

Overview

Package debugstatus provides facilities for inspecting information about a running HTTP service.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPprofConfigured = errgo.New("no pprof access configured")

ErrNoPprofConfigured is the error returned on access to endpoints when Handler.CheckPprofAllowed is nil.

View Source
var ErrNoTraceConfigured = errgo.New("no trace access configured")

ErrNoTraceConfigured is the error returned on access to endpoints when Handler.CheckTraceAllowed is nil.

View Source
var StartTime = time.Now().UTC()

StartTime holds the time that the code started running.

Functions

func Check

func Check(ctx context.Context, checkers ...CheckerFunc) map[string]CheckResult

Check collects the status check results from the given checkers.

Types

type CheckResult

type CheckResult struct {
	// Name is the human readable name for the check.
	Name string

	// Value is the check result.
	Value string

	// Passed reports whether the check passed.
	Passed bool

	// Duration holds the duration that the
	// status check took to run.
	Duration time.Duration
}

CheckResult holds the result of a single status check.

func ServerStartTime

func ServerStartTime(context.Context) (key string, result CheckResult)

ServerStartTime reports the time when the application was started.

type CheckerFunc

type CheckerFunc func(ctx context.Context) (key string, result CheckResult)

CheckerFunc represents a function returning the check machine friendly key and the result.

func Connection

func Connection(p Pinger) CheckerFunc

Connection returns a status checker reporting whether the given Pinger is connected.

func MongoCollections

func MongoCollections(c Collector) CheckerFunc

MongoCollections returns a status checker checking that all the expected Mongo collections are present in the database.

func Rename

func Rename(newKey, newName string, check CheckerFunc) CheckerFunc

Rename changes the key and/or result name returned by the given check. It is possible to pass an empty string to avoid changing one of the values. This means that if both key are name are empty, this closure is a no-op.

type Collector

type Collector interface {
	// Collections returns the Mongo collections that we expect to exist in
	// the Mongo database.
	Collections() []*mgo.Collection

	// CollectionNames returns the names of the collections actually present in
	// the Mongo database.
	CollectionNames() ([]string, error)
}

Collector is an interface that groups the methods used to check that a Mongo database has the expected collections. It is usually implemented by types extending mgo.Database to add the Collections() method.

type DebugEventsRequest

type DebugEventsRequest struct {
	httprequest.Route `httprequest:"GET /debug/events"`
}

DebugEventsRequest describes the /debug/events endpoint.

type DebugInfoRequest

type DebugInfoRequest struct {
	httprequest.Route `httprequest:"GET /debug/info"`
}

DebugInfoRequest describes the /debug/info endpoint.

type DebugPprofEndpointsRequest

type DebugPprofEndpointsRequest struct {
	httprequest.Route `httprequest:"GET /debug/pprof/:name"`
	Name              string `httprequest:"name,path"`
}

DebugPprofEndpointsRequest describes the endpoints under /debug/prof.

type DebugPprofRequest

type DebugPprofRequest struct {
	httprequest.Route `httprequest:"GET /debug/pprof/"`
}

DebugPprofRequest describes the /debug/pprof/ endpoint.

type DebugRequestsRequest

type DebugRequestsRequest struct {
	httprequest.Route `httprequest:"GET /debug/requests"`
}

DebugRequestsRequest describes the /debug/requests endpoint.

type DebugStatusRequest

type DebugStatusRequest struct {
	httprequest.Route `httprequest:"GET /debug/status"`
}

DebugStatusRequest describes the /debug/status endpoint.

type Handler

type Handler struct {
	// Check will be called to obtain the current health of the
	// system. It should return a map as returned from the
	// Check function. If this is nil, an empty result will
	// always be returned from /debug/status.
	Check func(context.Context) map[string]CheckResult

	// Version should hold the current version
	// of the binary running the server, served
	// from the /debug/info endpoint.
	Version Version

	// CheckPprofAllowed will be used to check whether the
	// given pprof request should be allowed.
	// It should return an error if not, which will not be masked.
	// If this is nil, no access will be allowed to any
	// of the endpoints under /debug/pprof - the
	// error returned will be ErrNoPprofConfigured.
	CheckPprofAllowed func(req *http.Request) error

	// CheckTraceAllowed will be used to check whether the given
	// trace request should be allowed. It should return an error if
	// not, which will not be masked. If this is nil, no access will
	// be allowed to either /debug/events or /debug/requests - the
	// error returned will be ErrNoTraceConfigured. If access is
	// allowed, the sensitive value specifies whether sensitive trace
	// events will be shown.
	CheckTraceAllowed func(req *http.Request) (sensitive bool, err error)
}

Handler implements a type that can be used with httprequest.Handlers to serve a standard set of /debug endpoints, including the version of the system, its current health status the runtime profiling information.

func (*Handler) DebugEvents

func (h *Handler) DebugEvents(p httprequest.Params, r *DebugEventsRequest) error

DebugEvents serves the /debug/events endpoint.

func (*Handler) DebugInfo

func (h *Handler) DebugInfo(*DebugInfoRequest) (Version, error)

DebugInfo returns version information on the current server.

func (*Handler) DebugPprof

func (h *Handler) DebugPprof(p httprequest.Params, _ *DebugPprofRequest) error

DebugPprof serves index information on the available pprof endpoints.

func (*Handler) DebugPprofEndpoints

func (h *Handler) DebugPprofEndpoints(p httprequest.Params, r *DebugPprofEndpointsRequest) error

DebugPprofEndpoints serves all the endpoints under DebugPprof.

func (*Handler) DebugRequests

func (h *Handler) DebugRequests(p httprequest.Params, r *DebugRequestsRequest) error

DebugRequests serves the /debug/requests endpoint.

func (*Handler) DebugStatus

func (h *Handler) DebugStatus(p httprequest.Params, _ *DebugStatusRequest) (map[string]CheckResult, error)

DebugStatus returns the current status of the server.

type Pinger

type Pinger interface {
	Ping() error
}

Pinger is an interface that wraps the Ping method. It is implemented by mgo.Session.

type Version

type Version struct {
	GitCommit string
	Version   string
}

Version describes the current version of the code being run.

Jump to

Keyboard shortcuts

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