metrt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOptions

func AddOptions(opts ...Option)

func SetOptions

func SetOptions(opts ...Option)

Types

type Assert

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

func (Assert) Sum

func (a Assert) Sum(expected IntOrFloat, msgAndArgs ...any) bool

func (Assert) SumGreater

func (a Assert) SumGreater(expected IntOrFloat, msgAndArgs ...any) bool

func (Assert) SumGreaterOrEqual

func (a Assert) SumGreaterOrEqual(expected IntOrFloat, msgAndArgs ...any) bool

func (Assert) SumLess

func (a Assert) SumLess(expected IntOrFloat, msgAndArgs ...any) bool

func (Assert) SumLessOrEqual

func (a Assert) SumLessOrEqual(expected IntOrFloat, msgAndArgs ...any) bool

func (Assert) Value

func (a Assert) Value(expected IntOrFloat, msgAndArgs ...any) bool

func (Assert) ValueGreater

func (a Assert) ValueGreater(expected IntOrFloat, msgAndArgs ...any) bool

func (Assert) ValueGreaterOrEqual

func (a Assert) ValueGreaterOrEqual(expected IntOrFloat, msgAndArgs ...any) bool

func (Assert) ValueLess

func (a Assert) ValueLess(expected IntOrFloat, msgAndArgs ...any) bool

func (Assert) ValueLessOrEqual

func (a Assert) ValueLessOrEqual(expected IntOrFloat, msgAndArgs ...any) bool

type AssertGroup

type AssertGroup[K comparable] struct {
	// contains filtered or unexported fields
}

func (AssertGroup[K]) Sum

func (a AssertGroup[K]) Sum(expected map[K]int64) bool

type Group

type Group[K comparable] struct {
	T MetrT `chaingen:"-"`
	// contains filtered or unexported fields
}

func (Group[K]) Aggregate

func (g Group[K]) Aggregate(fn genq.AggregationFunc[float64]) map[K]metrq.Metric

func (Group[K]) AggregateFlat

func (g Group[K]) AggregateFlat(fn genq.AggregationFunc[float64]) metrq.Metrics

func (Group[K]) Assert

func (g Group[K]) Assert() AssertGroup[K]

func (Group[K]) Float

func (g Group[K]) Float(fn genq.AggregationFunc[float64]) map[K]float64

func (Group[K]) FloatSum

func (g Group[K]) FloatSum() map[K]float64

func (Group[K]) Int

func (g Group[K]) Int(fn genq.AggregationFunc[float64]) map[K]int64

func (Group[K]) IntSum

func (g Group[K]) IntSum() map[K]int64

func (Group[K]) Require

func (g Group[K]) Require() RequireGroup[K]

type IntOrFloat

type IntOrFloat any

type MetrT

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

MetrT stands for Metrics Testing. In your test code, use `mt` variable name for it of a `MetrT` type (no pointer!). All modifier functions of MetrT return a new copy of MetrT, making it thread safe, and easy to reuse. If you want to persist changes, reassign the result of modifier function back to the variable. Example: mt = mt.WithCollectFilter(mcqold.Prefix("my_awesome_app")).Start() You can store and access multiple copies of MetrT, which will contain their own snapshots, so you can mix and match different sets of metrics.

func New

func New(t *testing.T, opts ...Option) MetrT

New creates new MetrT.

func Start

func Start(t *testing.T, opts ...Option) MetrT

Start creates MetrT and starts it immediately

func (MetrT) Collect

func (t MetrT) Collect(filters ...metrq.FilterFunc) Metrics

Collect collects all metrics from the collector. If collection filter is set, it will ignore metrics that don't match the filter.

func (MetrT) Finish

func (t MetrT) Finish() Metrics

Finish returns difference between metrics snapshot and newly collected metrics.

func (MetrT) Scope

func (t MetrT) Scope(fn func(mt MetrT)) Metrics

Scope runs provided function, and returns metrics changes that happened during its execution. This is a shorthand for: mt = mt.Start() .. do something delta := mt.Finish()

func (MetrT) Snapshot

func (t MetrT) Snapshot() Metrics

Snapshot returns metrics snapshot, taken earlier using Start.

func (MetrT) Start

func (t MetrT) Start() MetrT

Start collects metrics, and puts the result as current snapshot

func (MetrT) T

func (t MetrT) T() *testing.T

T returns *testing.T

func (MetrT) WithCollectFilter

func (t MetrT) WithCollectFilter(filter ...metrq.FilterFunc) MetrT

WithCollectFilter sets collector filter, which affects which metrics are visible to MetrT.

func (MetrT) WithOptions

func (t MetrT) WithOptions(opts ...Option) MetrT

WithOptions sets new options to MetrT.

func (MetrT) WithSnapshot

func (t MetrT) WithSnapshot(metrics metrq.Metrics) MetrT

WithSnapshot sets new snapshot to MetricsT

func (MetrT) WithT

func (t MetrT) WithT(tt *testing.T) MetrT

WithT sets new T to MetrT.

func (MetrT) WithoutSnapshot

func (t MetrT) WithoutSnapshot() MetrT

WithoutSnapshot sets empty snapshot.

type Metrics

type Metrics struct {
	T MetrT `chaingen:"-"`
	// contains filtered or unexported fields
}

func Scope

func Scope(t *testing.T, fn func(mt MetrT), opts ...Option) Metrics

func (Metrics) And

func (f Metrics) And(operands ...genq.FilterFunc[metrq.Metric]) Metrics

func (Metrics) Assert

func (f Metrics) Assert() Assert

func (Metrics) Group

func (Metrics) Metrics

func (f Metrics) Metrics() metrq.Metrics

func (Metrics) Or

func (f Metrics) Or(operands ...genq.FilterFunc[metrq.Metric]) Metrics

func (Metrics) Require

func (f Metrics) Require() Require

func (Metrics) Resolve

func (f Metrics) Resolve() []metrq.Metric

func (Metrics) Where

func (f Metrics) Where(operands ...genq.FilterFunc[metrq.Metric]) Metrics

type Option

type Option func(o *options)

func WithCollectFilter

func WithCollectFilter(fn ...metrq.FilterFunc) Option

WithCollectFilter sets collector filter, which affects which metrics are visible toe MetrT.

func WithCollector

func WithCollector(collector metrcollect.Collector) Option

WithCollector sets a collector for MetrT. Collector is required for MetrT to function.

type Require

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

func (Require) Sum

func (r Require) Sum(expected IntOrFloat, msgAndArgs ...any)

func (Require) SumGreater

func (r Require) SumGreater(expected IntOrFloat, msgAndArgs ...any)

func (Require) SumGreaterOrEqual

func (r Require) SumGreaterOrEqual(expected IntOrFloat, msgAndArgs ...any)

func (Require) SumLess

func (r Require) SumLess(expected IntOrFloat, msgAndArgs ...any)

func (Require) SumLessOrEqual

func (r Require) SumLessOrEqual(expected IntOrFloat, msgAndArgs ...any)

func (Require) Value

func (r Require) Value(expected IntOrFloat, msgAndArgs ...any)

func (Require) ValueGreater

func (r Require) ValueGreater(expected IntOrFloat, msgAndArgs ...any)

func (Require) ValueGreaterOrEqual

func (r Require) ValueGreaterOrEqual(expected IntOrFloat, msgAndArgs ...any)

func (Require) ValueLess

func (r Require) ValueLess(expected IntOrFloat, msgAndArgs ...any)

func (Require) ValueLessOrEqual

func (r Require) ValueLessOrEqual(expected IntOrFloat, msgAndArgs ...any)

type RequireGroup

type RequireGroup[K comparable] struct {
	// contains filtered or unexported fields
}

func (RequireGroup[K]) Sum

func (r RequireGroup[K]) Sum(expected map[K]int64)

Jump to

Keyboard shortcuts

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