window

package
v0.0.0-...-ad5f057 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

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

Bucket holds counts of failures and successes

func (*Bucket) Fail

func (b *Bucket) Fail()

Fail increments the failure count

func (*Bucket) Reset

func (b *Bucket) Reset()

Reset resets the counts to 0

func (*Bucket) Success

func (b *Bucket) Success()

Success increments the success count

type Window

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

Window maintains a ring of buckets and increments the failure and success counts of the current bucket. Once a specified time has elapsed, it will advance to the next bucket, reseting its counts. This allows the keeping of rolling statistics on the counts.

func New

func New(c clock, windowTime time.Duration, windowBuckets int) *Window

New creates a new window. windowTime is the time covering the entire window. windowBuckets is the number of buckets the window is divided into. An example: a 10 second window with 10 buckets will have 10 buckets covering 1 second each.

func (*Window) ErrorRate

func (w *Window) ErrorRate() float64

ErrorRate returns the error rate calculated over all buckets, expressed as a floating point number (e.g. 0.9 for 90%)

func (*Window) Fail

func (w *Window) Fail()

Fail records a failure in the current bucket.

func (*Window) Failures

func (w *Window) Failures() int64

Failures returns the total number of failures recorded in all buckets.

func (*Window) Reset

func (w *Window) Reset()

Reset resets the count of all buckets.

func (*Window) Success

func (w *Window) Success()

Success records a success in the current bucket.

func (*Window) Successes

func (w *Window) Successes() int64

Successes returns the total number of successes recorded in all buckets.

Jump to

Keyboard shortcuts

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