timer

package
v0.0.0-...-6637ac4 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package timer implements a simple timing utility that can be used to capture end to end timings, plus any subtimings of interests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contributor

type Contributor struct {
	sync.RWMutex
	Name     string
	Duration time.Duration
	Error    string

	ServiceCalls []*ServiceCall
	// contains filtered or unexported fields
}

Contributor is used to capture sub-timings of note that contribute to the end to end time.

func (*Contributor) End

func (c *Contributor) End(err error)

End stops the clock for a contributor. Any errors of note that occur during the contributor should be pass along in the err argument, otherwise pass nil.

func (*Contributor) StartServiceCall

func (c *Contributor) StartServiceCall(name string, endpoint string) *ServiceCall

StartServiceCall create a ServiceCall timer. ServiceCall timers are used to capture the times of calls to services/backends made within a Contributor timing. Note that while an error can be denoted when ending the call, it is not assumed an error in a call to a service causes the end to end timing to fail.

type EndToEndTimer

type EndToEndTimer struct {
	sync.RWMutex
	Name             string
	Tags             map[string]string
	Duration         time.Duration
	LoggingTimestamp time.Time `json:"time"`
	TxnId            string
	Contributors     []*Contributor
	ErrorFree        bool
	Error            string
	// contains filtered or unexported fields
}

EndToEndTimer is used to capture an end to end timing. Subtimings can be added to an end to end time using StartContributor. Note logging timestamp is serialized as time so we can have a single logging time index in elasticsearch

func NewEndToEndTimer

func NewEndToEndTimer(name string) *EndToEndTimer

NewEndToEndTimer creates a new EndToEndTimer. Note that the clock starts when an EndToEndTimer is created.

func (*EndToEndTimer) ContributorErrors

func (t *EndToEndTimer) ContributorErrors() bool

ContributorErrors returns true if any subtiming has been stopped with an error indication

func (*EndToEndTimer) StartContributor

func (t *EndToEndTimer) StartContributor(name string) *Contributor

StartContributor creates a Contributor for capturing a sub timing, starting the clock on the subtimer.

func (*EndToEndTimer) Stop

func (t *EndToEndTimer) Stop(err error)

Stop stops the clock for an EndToEndTimer. If an error occurred in the timing path, it should be noted by passing an error object to Stop, otherwise pass nil. The JSON representation of the timing data will reflect if an error occurred during the timing.

func (*EndToEndTimer) ToJSONString

func (t *EndToEndTimer) ToJSONString() string

ToJSONString produces a JSON string representation of an EndToEndTimer, including all of its contributors.

type ServiceCall

type ServiceCall struct {
	sync.RWMutex
	Name     string
	Endpoint string
	Duration time.Duration
	Error    string
	// contains filtered or unexported fields
}

ServiceCall is used to capture a service call made in the context of a Contributor timing.

func (*ServiceCall) End

func (sc *ServiceCall) End(err error)

End stops the clock for a ServiceCall

Jump to

Keyboard shortcuts

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