window

package
v0.0.50-alpha.110 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Avg

func Avg(iterator Iterator) float64

Avg computes the average of values within the window

func Count

func Count(iterator Iterator) float64

Count computes the total number of data points within the window

func Max

func Max(iterator Iterator) float64

Max computes the maximum value within the window

func Min

func Min(iterator Iterator) float64

Min computes the minimum value within the window

func Sum

func Sum(iterator Iterator) float64

Sum computes the total sum of values within the window

Types

type Aggregation

type Aggregation interface {
	// Min finds the min value within the window.
	Min() float64
	// Max finds the max value within the window.
	Max() float64
	// Avg computes average value within the window.
	Avg() float64
	// Sum computes sum value within the window.
	Sum() float64
}

Aggregation contains some common aggregation function. Each aggregation can compute summary statistics of window.

type Bucket

type Bucket struct {
	Points []float64 // stores individual data points
	Count  int64     // number of data points in this bucket
	// contains filtered or unexported fields
}

Bucket is a basic structure that stores multiple float64 data points

func NewBucket

func NewBucket() *Bucket

NewBucket creates a new bucket

func (*Bucket) Add

func (b *Bucket) Add(offset int, val float64)

Add adds the value at the specified offset

func (*Bucket) Append

func (b *Bucket) Append(val float64)

Append adds the given value to the bucket

func (*Bucket) Next

func (b *Bucket) Next() *Bucket

Next return next bucket

func (*Bucket) Reset

func (b *Bucket) Reset()

Reset clears the bucket

type Iterator

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

Iterator is an iterator for traversing buckets in the window

func (*Iterator) Bucket

func (i *Iterator) Bucket() Bucket

Bucket returns the current bucket

func (*Iterator) Next

func (i *Iterator) Next() bool

Next returns true if there are still buckets left to iterate

type Metric

type Metric interface {
	// Add adds the given value to the counter.
	Add(int64)
	// Value gets the current value.
	// If the metric's type is PointGauge, RollingCounter, RollingGauge,
	// it returns the sum value within the window.
	Value() int64
}

Metric is a sample interface. Implementations of Metrics in metric package are Counter, Gauge, PointGauge, RollingCounter and RollingGauge.

type Options

type Options struct {
	Size int
}

type RollingCounter

type RollingCounter interface {
	Metric
	Aggregation

	Timespan() int
	// Reduce applies the reduction function to all buckets within the window.
	Reduce(func(Iterator) float64) float64
}

RollingCounter represents a ring window based on time duration. e.g. [[1], [3], [5]]

func NewRollingCounter

func NewRollingCounter(opts RollingCounterOpts) RollingCounter

NewRollingCounter creates a new RollingCounter bases on RollingCounterOpts.

type RollingCounterOpts

type RollingCounterOpts struct {
	Size           int
	BucketDuration time.Duration
}

RollingCounterOpts contains the arguments for creating RollingCounter.

type RollingGauge

type RollingGauge interface {
	Metric
	Aggregation

	// Latest returns the latest value.
	Latest() float64
	Timespan() int
	// Reduce applies the reduction function to all buckets within the window.
	Reduce(func(Iterator) float64) float64
}

RollingGauge represents a ring window based on time duration.

func NewRollingGauge

func NewRollingGauge(opts RollingGaugeOpts) RollingGauge

NewRollingGauge creates a new RollingGauge based on RollingGaugeOpts.

type RollingGaugeOpts

type RollingGaugeOpts struct {
	Size           int
	BucketDuration time.Duration
}

RollingGaugeOpts contains the arguments for creating RollingGauge.

type RollingWindow

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

RollingWindow is a time-based rolling window

func NewRollingWindow

func NewRollingWindow(opts RollingWindowOptions) *RollingWindow

NewRollingWindow creates a new rolling window

func (*RollingWindow) Add

func (r *RollingWindow) Add(val float64)

Add adds a value to the current bucket and rolls the window according to time

func (*RollingWindow) Reduce

func (r *RollingWindow) Reduce(f func(Iterator) float64) float64

Reduce applies an aggregation function to the data in the window

type RollingWindowOptions

type RollingWindowOptions struct {
	Size           int           // Window size (number of buckets)
	BucketDuration time.Duration // Duration of each bucket
}

RollingWindowOptions contains parameters for creating a rolling window

type Window

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

window implements a sliding time window

func NewWindow

func NewWindow(opt Options) *Window

func (*Window) Add

func (w *Window) Add(offset int, val float64)

Add adds a value to the latest point in the bucket at the specified offset

func (*Window) Append

func (w *Window) Append(offset int, val float64)

Append appends a value to the bucket at the specified offset

func (*Window) Bucket

func (w *Window) Bucket(offset int) Bucket

Bucket returns the bucket at the specified offset

func (*Window) Iterator

func (w *Window) Iterator(offset int, count int) Iterator

Iterator returns an iterator over count buckets starting from the specified offset

func (*Window) ResetBucket

func (w *Window) ResetBucket(offset int)

ResetBucket resets the bucket at the specified offset

func (*Window) ResetBuckets

func (w *Window) ResetBuckets(offset int, count int)

ResetBuckets resets count buckets starting from offset

func (*Window) ResetWindow

func (w *Window) ResetWindow()

ResetWindow resets all buckets in the window

func (*Window) Size

func (w *Window) Size() int

Size returns the window size

Jump to

Keyboard shortcuts

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