base

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PtrSize = int(8)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AtomicBucketWrapArray

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

atomic BucketWrap array to resolve race condition AtomicBucketWrapArray can not append or delete element after initializing

func NewAtomicBucketWrapArray

func NewAtomicBucketWrapArray(len int, bucketLengthInMs uint32, generator BucketGenerator) *AtomicBucketWrapArray

New AtomicBucketWrapArray with initializing field data Default, automatically initialize each BucketWrap len: length of array bucketLengthInMs: bucket length of BucketWrap generator: generator to generate bucket

func NewAtomicBucketWrapArrayWithTime

func NewAtomicBucketWrapArrayWithTime(len int, bucketLengthInMs uint32, now uint64, generator BucketGenerator) *AtomicBucketWrapArray

type BucketGenerator

type BucketGenerator interface {
	// called when timestamp entry a new slot interval
	NewEmptyBucket() interface{}

	// reset the BucketWrap, clear all data of BucketWrap
	ResetBucketTo(bw *BucketWrap, startTime uint64) *BucketWrap
}

Generic interface to generate bucket

type BucketLeapArray

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

The implementation of sliding window based on LeapArray (as the sliding window infrastructure) and MetricBucket (as the data type). The MetricBucket is used to record statistic metrics per minimum time unit (i.e. the bucket time span).

func NewBucketLeapArray

func NewBucketLeapArray(sampleCount uint32, intervalInMs uint32) *BucketLeapArray

sampleCount is the number of slots intervalInMs is the time length of sliding window

func (*BucketLeapArray) AddCount

func (bla *BucketLeapArray) AddCount(event base.MetricEvent, count int64)

Write method It might panic

func (*BucketLeapArray) BucketLengthInMs

func (bla *BucketLeapArray) BucketLengthInMs() uint32

func (*BucketLeapArray) Count

func (bla *BucketLeapArray) Count(event base.MetricEvent) int64

Read method, need to adapt upper application it might panic

func (*BucketLeapArray) CountWithTime

func (bla *BucketLeapArray) CountWithTime(now uint64, event base.MetricEvent) int64

func (*BucketLeapArray) DataType

func (bla *BucketLeapArray) DataType() string

func (*BucketLeapArray) GetIntervalInSecond

func (bla *BucketLeapArray) GetIntervalInSecond() float64

func (*BucketLeapArray) IntervalInMs

func (bla *BucketLeapArray) IntervalInMs() uint32

func (*BucketLeapArray) MinRt

func (bla *BucketLeapArray) MinRt() int64

func (*BucketLeapArray) NewEmptyBucket

func (bla *BucketLeapArray) NewEmptyBucket() interface{}

func (*BucketLeapArray) ResetBucketTo

func (bla *BucketLeapArray) ResetBucketTo(bw *BucketWrap, startTime uint64) *BucketWrap

func (*BucketLeapArray) SampleCount

func (bla *BucketLeapArray) SampleCount() uint32

func (*BucketLeapArray) Values

func (bla *BucketLeapArray) Values(now uint64) []*BucketWrap

Read method, get all BucketWrap.

func (*BucketLeapArray) ValuesConditional

func (bla *BucketLeapArray) ValuesConditional(now uint64, predicate base.TimePredicate) []*BucketWrap

type BucketWrap

type BucketWrap struct {
	// The start timestamp of this statistic bucket wrapper.
	BucketStart uint64
	// The actual data structure to record the metrics (e.g. MetricBucket).
	Value atomic.Value
}

BucketWrap represent a slot to record metrics In order to reduce the usage of memory, BucketWrap don't hold length of BucketWrap The length of BucketWrap could be seen in LeapArray. The scope of time is [startTime, startTime+bucketLength) The size of BucketWrap is 24(8+16) bytes

type LeapArray

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

The BucketWrap leap array, sampleCount represent the number of BucketWrap intervalInMs represent the interval of LeapArray. For example, bucketLengthInMs is 200ms, intervalInMs is 1000ms, so sampleCount is 5. Give a diagram to illustrate Suppose current time is 888, bucketLengthInMs is 200ms, intervalInMs is 1000ms, LeapArray will build the below windows

 B0       B1      B2     B3      B4
 |_______|_______|_______|_______|_______|
1000    1200    1400    1600    800    (1000)
                                      ^
                                    time=888

func NewLeapArray

func NewLeapArray(sampleCount uint32, intervalInMs uint32, generator BucketGenerator) (*LeapArray, error)

func (*LeapArray) CurrentBucket

func (la *LeapArray) CurrentBucket(bg BucketGenerator) (*BucketWrap, error)

func (*LeapArray) Values

func (la *LeapArray) Values() []*BucketWrap

Get all BucketWrap between [current time -1000ms, current time]

func (*LeapArray) ValuesConditional

func (la *LeapArray) ValuesConditional(now uint64, predicate base.TimePredicate) []*BucketWrap

type MetricBucket

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

MetricBucket represents the entity to record metrics per minimum time unit (i.e. the bucket time span). Note that all operations of the MetricBucket are required to be thread-safe.

func NewMetricBucket

func NewMetricBucket() *MetricBucket

func (*MetricBucket) Add

func (mb *MetricBucket) Add(event base.MetricEvent, count int64)

Add statistic count for the given metric event.

func (*MetricBucket) AddRt

func (mb *MetricBucket) AddRt(rt int64)

func (*MetricBucket) Get

func (mb *MetricBucket) Get(event base.MetricEvent) int64

Get current statistic count of the given metric event.

func (*MetricBucket) MinRt

func (mb *MetricBucket) MinRt() int64

type SlidingWindowMetric

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

SlidingWindowMetric represents the sliding window metric wrapper. It does not store any data and is the wrapper of BucketLeapArray to adapt to different internal bucket SlidingWindowMetric is used for SentinelRules and BucketLeapArray is used for monitor BucketLeapArray is per resource, and SlidingWindowMetric support only read operation.

func NewSlidingWindowMetric

func NewSlidingWindowMetric(sampleCount, intervalInMs uint32, real *BucketLeapArray) *SlidingWindowMetric

It must pass the parameter point to the real storage entity

func (*SlidingWindowMetric) AvgRT

func (m *SlidingWindowMetric) AvgRT() float64

func (*SlidingWindowMetric) GetMaxOfSingleBucket

func (m *SlidingWindowMetric) GetMaxOfSingleBucket(event base.MetricEvent) int64

func (*SlidingWindowMetric) GetPreviousQPS

func (m *SlidingWindowMetric) GetPreviousQPS(event base.MetricEvent) float64

func (*SlidingWindowMetric) GetQPS

func (m *SlidingWindowMetric) GetQPS(event base.MetricEvent) float64

func (*SlidingWindowMetric) GetSum

func (m *SlidingWindowMetric) GetSum(event base.MetricEvent) int64

func (*SlidingWindowMetric) MinRT

func (m *SlidingWindowMetric) MinRT() float64

func (*SlidingWindowMetric) SecondMetricsOnCondition

func (m *SlidingWindowMetric) SecondMetricsOnCondition(predicate base.TimePredicate) []*base.MetricItem

SecondMetricsOnCondition aggregates metric items by second on condition that the startTime of the statistic buckets satisfies the time predicate.

Jump to

Keyboard shortcuts

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