se4

package module
v0.0.0-...-506a449 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

README

Build Status Go Report Card

ozzo-se4

Simple Standard Service Endpoints for Ozzo

Implementation of Simple Spec for Service Status and Health targeted for the ozzo-routing framework.

Usage

See the example

Run example:

  go run --ldflags '-X main.Version=1.1' example/example.go  

Then you can curl the endpoints, for example:

curl -s http://localhost:8080/service/status|jq ''
{
  "artifact_id": "",
  "build_number": "",
  "build_machine": "",
  "built_by": "me",
  "built_when": "",
  "git_sha1": "",
  "git_branch": "",
  "git_repo": "",
  "runbook_uri": "",
  "version": "1.1",
  "compiler_version": "gc",
  "current_time": "2017-03-18T22:15:58Z",
  "group_id": "",
  "machine_name": "6c4008a5dd24",
  "os_arch": "x86_64",
  "os_avgload": "1.58",
  "os_name": "Darwin",
  "os_numprocessors": "8",
  "os_version": "16.4.0",
  "up_duration": "1m7.675266382s",
  "up_since": "2017-03-18T22:14:50Z",
  "vm_name": "",
  "vm_vendor": "",
  "vm_version": "",
  "go_maxprocs": "8",
  "go_numroutines": "5"
}

Documentation

Overview

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	HealthResultNotRun  = "not_run"
	HealthResultRunning = "running"
	HealthResultPassed  = "passed"
	HealthResultFailed  = "failed"
)

HealthResult "not_run", "running", "passed", "failed"

View Source
const (
	MIME_TEXT_PLAIN = "text/plain"
)

Variables

View Source
var (
	DefaultHealthCheckInterval = time.Duration(10) * time.Second
)

Functions

func CreateDefaultRouterGroup

func CreateDefaultRouterGroup(router *routing.Router) *routing.RouteGroup

func DurationToMillis

func DurationToMillis(duration time.Duration) float64

func Uname

func Uname(buf *UnameInfo) (err error)

Types

type BuildInfo

type BuildInfo struct {
	ArtifactID   string `json:"artifact_id"`
	BuildNumber  string `json:"build_number"`
	BuildMachine string `json:"build_machine"`
	BuiltBy      string `json:"built_by"`
	BuiltWhen    string `json:"built_when"`
	// VCS (baked in)
	GitSha1   string `json:"git_sha1"`
	GitBranch string `json:"git_branch"` // ADDITIONAL -
	GitRepo   string `json:"git_repo"`   // ADDITIONAL -
	// runbook (baked in)
	RunbookURI string `json:"runbook_uri"`
	// version number (baked in)
	Version string `json:"version"`
}

these should be provided by the application

type ConfigSourceFunc

type ConfigSourceFunc func() interface{}

ConfigSourceFunc returns the configuration that is used by the service

func ToConfigSourceFunc

func ToConfigSourceFunc(config interface{}) ConfigSourceFunc

type GoodToGoFunc

type GoodToGoFunc func() bool

The "Good To Go" (GTG) returns a successful response in the case that the service is in an operational state and is able to receive traffic.

type HealthCheckFunc

type HealthCheckFunc func() HealthCheckResult

Healthcheck resource provides information about internal health and its perceived health of downstream dependencies.

type HealthCheckReport

type HealthCheckReport struct {
	Timestamp time.Time           `json:"report_as_of"`    // The time at which this report was generated (this may not be the current time)
	Duration  ReportDuration      `json:"report_duration"` // How long it took to generate the report
	Results   []HealthCheckResult `json:"tests"`           // array of test results
}

type HealthCheckResult

type HealthCheckResult struct {
	// To convert Duration use: DurationToMillis(..)
	DurationMillis float64   `json:"duration_millis"` // Number of milliseconds taken to run the test
	Name           string    `json:"test_name"`       // The name of the test, a name that is meaningful to supporting engineers
	Result         string    `json:"test_result"`     // The state of the test, may be "not_run", "running", "passed", "failed"
	Timestamp      time.Time `json:"tested_at"`       // The time at which this test was executed
}

type ReportDuration

type ReportDuration time.Duration

func (ReportDuration) MarshalJSON

func (r ReportDuration) MarshalJSON() ([]byte, error)

type ServiceCanaryFunc

type ServiceCanaryFunc func() bool

The "Service Canary" (ASG) returns a successful response in the case that the service is in a healthy state.

type StandardEndpoints

type StandardEndpoints struct {
	Status *Status
	// contains filtered or unexported fields
}

func NewStandardEndpoints

func NewStandardEndpoints() *StandardEndpoints

func NewStandardEndpointsWithBuildInfo

func NewStandardEndpointsWithBuildInfo(buildInfo *BuildInfo) *StandardEndpoints

func (*StandardEndpoints) RegisterDefaultEndpoints

func (s *StandardEndpoints) RegisterDefaultEndpoints(router *routing.Router)

func (*StandardEndpoints) RegisterEndpoints

func (s *StandardEndpoints) RegisterEndpoints(group *routing.RouteGroup)

func (*StandardEndpoints) SetConfigSourceFunc

func (s *StandardEndpoints) SetConfigSourceFunc(configSrc ConfigSourceFunc)

func (*StandardEndpoints) SetGoodToGoFunc

func (s *StandardEndpoints) SetGoodToGoFunc(gtgCheck GoodToGoFunc)

func (*StandardEndpoints) SetHealthCheckFuncs

func (s *StandardEndpoints) SetHealthCheckFuncs(interval time.Duration, healthchecks ...HealthCheckFunc)

Set the health check functions to run at a specified interval

func (*StandardEndpoints) SetServiceCanaryFunc

func (s *StandardEndpoints) SetServiceCanaryFunc(canaryCheck ServiceCanaryFunc)

type Status

type Status struct {
	// Build info (baked in)
	BuildInfo

	CompilerVersion string `json:"compiler_version"` // optional

	// per request
	CurrentTime string `json:"current_time"` // dynamic  - per req
	// maven group
	GroupID string `json:"group_id"` // N/A - maven

	// machine (baked in)
	MachineName    string `json:"machine_name"`     // dynamic
	OSArch         string `json:"os_arch"`          // dynamic
	OSAvgload      string `json:"os_avgload"`       // dynamic - per req
	OSName         string `json:"os_name"`          // dynamic
	OSNumProcessor string `json:"os_numprocessors"` // dynamic
	OSVersion      string `json:"os_version"`       // dynamic

	// dynamic / at startup
	UpDuration string `json:"up_duration"` // dynamic - per req
	UpSince    string `json:"up_since"`    // at startup

	// N/A
	VMName    string `json:"vm_name"`    // N/A
	VMVendor  string `json:"vm_vendor"`  // N/A
	VMVersion string `json:"vm_version"` // N/A
	// go additions
	GoMaxProcs    string `json:"go_maxprocs"`    // ADDITIONAL -
	GoNumRoutines string `json:"go_numroutines"` // ADDITIONAL - dynamic

	UpSinceTime time.Time `json:"-"`
}

type TextPlainDataWriter

type TextPlainDataWriter struct{}

func (*TextPlainDataWriter) SetHeader

func (w *TextPlainDataWriter) SetHeader(res http.ResponseWriter)

func (*TextPlainDataWriter) Write

func (w *TextPlainDataWriter) Write(res http.ResponseWriter, data interface{}) error

type UnameInfo

type UnameInfo struct {
	Sysname  string
	Nodename string
	Release  string
	Version  string
	Machine  string
}

Directories

Path Synopsis
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.

Jump to

Keyboard shortcuts

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