gose4

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

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

Go to latest
Published: Aug 19, 2015 License: MIT Imports: 8 Imported by: 0

README

Product Health gose4

Product Health gose4 is a golang implementation of Beamly se4 library to provide a simple convention for getting standard service information.

Gose4 standard service information is delivered through an HTTP interface. It can spawn its own web server on a given port or integrate to an existing one through the HandleFunc interface.

Example

package main

import (
	"github.com/ProductHealth/gose4"
	"github.com/ProductHealth/gose4/http"
)

func main() {
	healthCheckService := gose4.New()
	check, err := http.New(
		"http://example.com",
		"GET",
		200,
		gose4.NewConfiguration("Example Check", gose4.SeverityWarn, 0, 5))

	if err != nil {
		glog.Fatal(err)
	}

	healthCheckService.Register(check)

	go gose4.StartHttpServer(healthCheckService, 8081)
}

Service Status

GET /service/status will return a json document like the following:

{
  "artifact_id": "kats",
  "build_number": "dev",
  "build_machine": "emeka.local",
  "build_by": "ph",
  "build_when": "2014-10-06T12:05:29Z",
  "compiler_version": "go1.3",
  "current_time": "2014-10-06T12:05:48Z",
  "git_sha": "0e2b1d833317d70e50e92c633828f93a7f57a598",
  "machine_name": "emeka.local",
  "os_arch": "amd64",
  "os_name": "darwin",
  "os_version": "n/a",
  "runbook_uri": "",
  "up_duration": "13.955480359 seconds",
  "up_since": "2014-10-06T13:05:34Z",
  "version": "",
  "os_avgload": "1.83544921875",
  "os_numprocessors": 8
 }

Health Check

GET /service/healthcheck will return as json document like the following:

{
  "report_as_of": "2014-10-06T14:37:20Z",
  "report_duration": "",
  "tests": [
   {
    "duration_millis": 3,
    "test_name": "Kairosdb health",
    "rest_result": "passed",
    "tested_at": "2014-10-06T14:37:19Z"
   }
  ]
 }

where zero or more health check results will be returned.

Documentation

Index

Constants

View Source
const (
	SE4TimeFormat = "2006-01-02T15:04:05Z"
)

Variables

View Source
var Debugf = glog.V(2).Infof
View Source
var DefaultTestCheckConfig = Configuration{
	Severity:     SeverityWarn,
	InitialDelay: time.Second * 0,
	RunDelay:     time.Second,
	Description:  "Example config",
}
View Source
var DefaultTestCheckResult = HealthCheckResult{
	Duration:  time.Second * 5,
	Result:    CheckPassed,
	Message:   "It works!",
	LastCheck: time.Unix(1415030870, 0),
}
View Source
var (
	//
	GoodToGoFailureLevel = SeverityWarn
)
View Source
var Infof = glog.Infof

Logging wrappers

View Source
var ServiceStatus = Status{}

Empty status, should be replaced by compile

View Source
var Warningf = glog.Warningf

Functions

func GetCurrentHostName

func GetCurrentHostName() string

func HandlerFunc

func HandlerFunc(service *healthCheckService) http.HandlerFunc

func New

func New() *healthCheckService

func StartHttpServer

func StartHttpServer(service HealthCheckService, httpPort int)

Types

type Configuration

type Configuration struct {
	Severity     Severity
	InitialDelay time.Duration
	RunDelay     time.Duration
	Description  string
}

func NewConfiguration

func NewConfiguration(description string, severity Severity, initialDelay, period int) Configuration

initialDelay and period are integer representin seconds

type HealthCheck

type HealthCheck interface {
	Run() HealthCheckResult
	Configuration() Configuration
}

type HealthCheckResult

type HealthCheckResult struct {
	Duration  time.Duration
	Result    Result
	Message   string
	LastCheck time.Time
}

func Failed

func Ok

Default return helper methods

func Passed

func (HealthCheckResult) DurationMillis

func (r HealthCheckResult) DurationMillis() int64

func (HealthCheckResult) String

func (r HealthCheckResult) String() string

type HealthCheckService

type HealthCheckService interface {
	GetResults() map[HealthCheck]HealthCheckResult
	Register(h HealthCheck)
}

type Result

type Result int
const (
	CheckPassed Result = iota + 1
	CheckFailed
	CheckRunning
)

func (Result) String

func (r Result) String() string

type Severity

type Severity int
const (
	SeverityNotice Severity = iota + 1
	SeverityWarn
	SeverityFatal
)

type Status

type Status struct {
	ArtifactId         string  `json:"artifact_id"`
	BuildNumber        string  `json:"build_number"`
	BuildMachine       string  `json:"build_machine"`
	BuildBy            string  `json:"build_by"`
	BuildWhen          string  `json:"build_when"` //ISO 8601 Representation
	CompilerVersion    string  `json:"compiler_version"`
	CurrentTime        string  `json:"current_time"` //ISO 8601 Representation
	GitSha             string  `json:"git_sha"`
	MachineName        string  `json:"machine_name"`
	OsArch             string  `json:"os_arch"`
	OsName             string  `json:"os_name"`
	OsVersion          string  `json:"os_version"`
	RunbookUri         string  `json:"runbook_uri"`
	UpDuration         string  `json:"up_duration"`
	UpSince            string  `json:"up_since"` //ISO 8601 Representation
	Version            string  `json:"version"`
	OsLoad             *string `json:"os_avgload,omitempty"`
	OsNumberProcessors *int    `json:"os_numprocessors,omitempty"`
}

func (*Status) SetBuildWhen

func (s *Status) SetBuildWhen(t *time.Time)

func (*Status) SetCurrentTime

func (s *Status) SetCurrentTime(t *time.Time)

type TestCheck

type TestCheck struct {
	TestCheckResult HealthCheckResult
	TestCheckConfig Configuration
}

Simple check to use for tests around gose4 code

func NewTestCheck

func NewTestCheck() TestCheck

func (TestCheck) Configuration

func (t TestCheck) Configuration() Configuration

func (TestCheck) Run

func (t TestCheck) Run() HealthCheckResult

type TestResult

type TestResult struct {
	DurationMillis int64  `json:"duration_millis"`
	TestName       string `json:"test_name"`
	TestResult     string `json:"rest_result"`
	TestedAt       string `json:"tested_at"` //ISO 8601 Representation
}

type TestResults

type TestResults struct {
	ReportAsOf     string       `json:"report_as_of"`    //ISO 8601 Representation
	ReportDuration string       `json:"report_duration"` //
	Tests          []TestResult `json:"tests"`
}

Directories

Path Synopsis
Godeps
_workspace/src/github.com/cloudfoundry/gosigar/psnotify
Go interface to the Linux netlink process connector.
Go interface to the Linux netlink process connector.
_workspace/src/github.com/emicklei/go-restful
Package restful, a lean package for creating REST-style WebServices without magic.
Package restful, a lean package for creating REST-style WebServices without magic.
_workspace/src/github.com/emicklei/go-restful/swagger
Package swagger implements the structures of the Swagger https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md
Package swagger implements the structures of the Swagger https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md
_workspace/src/github.com/gocql/gocql
Package gocql implements a fast and robust Cassandra driver for the Go programming language.
Package gocql implements a fast and robust Cassandra driver for the Go programming language.
_workspace/src/github.com/golang/glog
Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup.
_workspace/src/github.com/golang/groupcache/lru
Package lru implements an LRU cache.
Package lru implements an LRU cache.
_workspace/src/github.com/golang/snappy
Package snappy implements the snappy block-based compression format.
Package snappy implements the snappy block-based compression format.
_workspace/src/github.com/stretchr/testify/assert
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
_workspace/src/github.com/ugorji/go/codec
High Performance, Feature-Rich Idiomatic Go codec/encoding library for binc, msgpack, cbor, json.
High Performance, Feature-Rich Idiomatic Go codec/encoding library for binc, msgpack, cbor, json.
_workspace/src/github.com/ugorji/go/codec/codecgen
codecgen generates codec.Selfer implementations for a set of types.
codecgen generates codec.Selfer implementations for a set of types.
_workspace/src/gopkg.in/inf.v0
Package inf (type inf.Dec) implements "infinite-precision" decimal arithmetic.
Package inf (type inf.Dec) implements "infinite-precision" decimal arithmetic.

Jump to

Keyboard shortcuts

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