admin

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

README

moov-io/base/admin

Package admin implements an http.Server which can be used for operations and monitoring tools. It's designed to be shipped (and ran) inside an existing Go service.

Here's an example of adding admin.Server to serve Prometheus metrics:

import (
    "fmt"
    "os"

    "github.com/moov-io/base/admin"

    "github.com/go-kit/kit/log"
)

var logger log.Logger

// in main.go or cmd/server/main.go

adminServer := admin.NewServer(*adminAddr)
go func() {
	logger.Log("admin", fmt.Sprintf("listening on %s", adminServer.BindAddr()))
	if err := adminServer.Listen(); err != nil {
		err = fmt.Errorf("problem starting admin http: %v", err)
		logger.Log("admin", err)
		// errs <- err // send err to shutdown channel
	}
}()
defer adminServer.Shutdown()

Documentation

Overview

Package admin implements an http.Server which can be used for operations and monitoring tools. It's designed to be shipped (and ran) inside an existing Go service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler() http.Handler

Handler returns an http.Handler for the admin http service. This contains metrics and pprof handlers.

No metrics specific to the handler are recorded.

We only want to expose on the admin servlet because these profiles/dumps can contain sensitive info (raw memory).

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents a holder around a net/http Server which is used for admin endpoints. (i.e. metrics, healthcheck)

func NewServer

func NewServer(addr string) *Server

NewServer returns an admin Server instance that handles Prometheus metrics and pprof requests. Callers can use ':0' to bind onto a random port and call BindAddr() for the address.

func (*Server) AddHandler

func (s *Server) AddHandler(path string, hf http.HandlerFunc)

AddHandler will append an http.HandlerFunc to the admin Server

func (*Server) AddLivenessCheck

func (s *Server) AddLivenessCheck(name string, f func() error)

AddLivenessCheck will register a new health check that is executed on every HTTP request of 'GET /live' against the admin server.

Every check will timeout after 10s and return a timeout error.

These checks are designed to be unhealthy only when the application has started but a dependency is unreachable or unhealthy.

func (*Server) AddReadinessCheck

func (s *Server) AddReadinessCheck(name string, f func() error)

AddReadinessCheck will register a new health check that is executed on every HTTP request of 'GET /ready' against the admin server.

Every check will timeout after 10s and return a timeout error.

These checks are designed to be unhealthy while the application is starting.

func (*Server) AddVersionHandler

func (s *Server) AddVersionHandler(version string)

AddVersionHandler will append 'GET /version' route returning the provided version

func (*Server) BindAddr

func (s *Server) BindAddr() string

BindAddr returns the server's bind address. This is in Go's format so :8080 is valid.

func (*Server) Listen

func (s *Server) Listen() error

Listen brings up the admin HTTP server. This call blocks until the server is Shutdown or panics.

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown unbinds the HTTP server.

Jump to

Keyboard shortcuts

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