Documentation ¶
Overview ¶
Package states is an observability tool to observe a system state, we can speak about app database connection, app readiness, or everything else which is not identified as a numeric value.
Example ¶
High-level example for an app
package main import ( "net/http" ) // Our custom state // The best way to have enums in Go type MyState string // Implement fmt.Stringer func (m MyState) String() string { return string(m) } // Well defined state names const ( READY = MyState("ready") ERROR = MyState("error") PENDING = MyState("pending") ) // High-level example for an app func main() { // Create a new state mystate := NewState(StateOptions{ Namespace: "my.app", System: "http.server", Name: "state", }, PENDING) // Register the new state to the default registry MustRegister(mystate) // later in the code mystate.Set(READY) //http.Handle("/states", stateshttp.Handler()) // http.Handle("/metrics", promhttp.Handler()) err := http.ListenAndServe(":8080", nil) if err != nil { panic(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultRegistry is ... DefaultRegistry = NewRegistry() // DefaultStateValue is used when the state is not known DefaultStateValue = defaultStateValue{} Separator = "." )
View Source
var AlreadyExistsErr = errors.Errorf("this state already exists")
AlreadyExistsErr is throw when you try to register two identical states
Functions ¶
func MustRegister ¶
func MustRegister(state State)
MustRegister register a state to the default Registry Panic if the state already exists
Types ¶
type Registry ¶
type Registry interface { // Register a new state to this registry // Can fail if another state with the same namespace/system/name exists Register(State) error // Register a new state to this registry // Panic if another state with the same namespace/system/name exists MustRegister(State) // Gather a list of all states timeseries Gather() warp10.GTSList }
Registry collect a set of app states
type State ¶
type State interface { // Metric return a timeseries Metric() *warp10.GTS // String pretty print the namespace, system, name and value of the state String() string // Set update the current state Set(fmt.Stringer) // Print informations about this state Help() string }
State give the current state of a system
Click to show internal directories.
Click to hide internal directories.