stats

package
v1.69.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package stats implements a TestMetricsRecorder utility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MetricsData

type MetricsData struct {
	Handle *estats.MetricDescriptor

	// Only set based on the type of metric. So only one of IntIncr or FloatIncr
	// is set.
	IntIncr   int64
	FloatIncr float64

	LabelKeys []string
	LabelVals []string
}

MetricsData represents data associated with a metric.

type NoopMetricsRecorder

type NoopMetricsRecorder struct{}

NoopMetricsRecorder is a noop MetricsRecorder to be used in tests to prevent nil panics.

func (*NoopMetricsRecorder) RecordFloat64Count

func (r *NoopMetricsRecorder) RecordFloat64Count(*estats.Float64CountHandle, float64, ...string)

RecordFloat64Count is a noop implementation of RecordFloat64Count.

func (*NoopMetricsRecorder) RecordFloat64Histo

func (r *NoopMetricsRecorder) RecordFloat64Histo(*estats.Float64HistoHandle, float64, ...string)

RecordFloat64Histo is a noop implementation of RecordFloat64Histo.

func (*NoopMetricsRecorder) RecordInt64Count

func (r *NoopMetricsRecorder) RecordInt64Count(*estats.Int64CountHandle, int64, ...string)

RecordInt64Count is a noop implementation of RecordInt64Count.

func (*NoopMetricsRecorder) RecordInt64Gauge

func (r *NoopMetricsRecorder) RecordInt64Gauge(*estats.Int64GaugeHandle, int64, ...string)

RecordInt64Gauge is a noop implementation of RecordInt64Gauge.

func (*NoopMetricsRecorder) RecordInt64Histo

func (r *NoopMetricsRecorder) RecordInt64Histo(*estats.Int64HistoHandle, int64, ...string)

RecordInt64Histo is a noop implementation of RecordInt64Histo.

type TestMetricsRecorder

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

TestMetricsRecorder is a MetricsRecorder to be used in tests. It sends recording events on channels and provides helpers to check if certain events have taken place. It also persists metrics data keyed on the metrics descriptor.

func NewTestMetricsRecorder

func NewTestMetricsRecorder() *TestMetricsRecorder

NewTestMetricsRecorder returns a new TestMetricsRecorder.

func (*TestMetricsRecorder) ClearMetrics

func (r *TestMetricsRecorder) ClearMetrics()

ClearMetrics clears the metrics data store of the test metrics recorder.

func (*TestMetricsRecorder) HandleConn

HandleConn is TestMetricsRecorder's implementation of HandleConn.

func (*TestMetricsRecorder) HandleRPC

HandleRPC is TestMetricsRecorder's implementation of HandleRPC.

func (*TestMetricsRecorder) Metric added in v1.68.0

func (r *TestMetricsRecorder) Metric(name string) (float64, bool)

Metric returns the most recent data for a metric, and whether this recorder has received data for a metric.

func (*TestMetricsRecorder) RecordFloat64Count

func (r *TestMetricsRecorder) RecordFloat64Count(handle *estats.Float64CountHandle, incr float64, labels ...string)

RecordFloat64Count sends the metrics data to the floatCountCh channel and updates the internal data map with the recorded value.

func (*TestMetricsRecorder) RecordFloat64Histo

func (r *TestMetricsRecorder) RecordFloat64Histo(handle *estats.Float64HistoHandle, incr float64, labels ...string)

RecordFloat64Histo sends the metrics data to the floatHistoCh channel and updates the internal data map with the recorded value.

func (*TestMetricsRecorder) RecordInt64Count

func (r *TestMetricsRecorder) RecordInt64Count(handle *estats.Int64CountHandle, incr int64, labels ...string)

RecordInt64Count sends the metrics data to the intCountCh channel and updates the internal data map with the recorded value.

func (*TestMetricsRecorder) RecordInt64Gauge

func (r *TestMetricsRecorder) RecordInt64Gauge(handle *estats.Int64GaugeHandle, incr int64, labels ...string)

RecordInt64Gauge sends the metrics data to the intGaugeCh channel and updates the internal data map with the recorded value.

func (*TestMetricsRecorder) RecordInt64Histo

func (r *TestMetricsRecorder) RecordInt64Histo(handle *estats.Int64HistoHandle, incr int64, labels ...string)

RecordInt64Histo sends the metrics data to the intHistoCh channel and updates the internal data map with the recorded value.

func (*TestMetricsRecorder) TagConn

TagConn is TestMetricsRecorder's implementation of TagConn.

func (*TestMetricsRecorder) TagRPC

TagRPC is TestMetricsRecorder's implementation of TagRPC.

func (*TestMetricsRecorder) WaitForFloat64Count

func (r *TestMetricsRecorder) WaitForFloat64Count(ctx context.Context, metricsDataWant MetricsData) error

WaitForFloat64Count waits for a float count metric to be recorded and verifies that the recorded metrics data matches the expected metricsDataWant. Returns an error if failed to wait or received wrong data.

func (*TestMetricsRecorder) WaitForFloat64Histo

func (r *TestMetricsRecorder) WaitForFloat64Histo(ctx context.Context, metricsDataWant MetricsData) error

WaitForFloat64Histo waits for a float histo metric to be recorded and verifies that the recorded metrics data matches the expected metricsDataWant. Returns an error if failed to wait or received wrong data.

func (*TestMetricsRecorder) WaitForInt64Count

func (r *TestMetricsRecorder) WaitForInt64Count(ctx context.Context, metricsDataWant MetricsData) error

WaitForInt64Count waits for an int64 count metric to be recorded and verifies that the recorded metrics data matches the expected metricsDataWant. Returns an error if failed to wait or received wrong data.

func (*TestMetricsRecorder) WaitForInt64CountIncr added in v1.69.0

func (r *TestMetricsRecorder) WaitForInt64CountIncr(ctx context.Context, incrWant int64) error

WaitForInt64CountIncr waits for an int64 count metric to be recorded and verifies that the recorded metrics data incr matches the expected incr. Returns an error if failed to wait or received wrong data.

func (*TestMetricsRecorder) WaitForInt64Gauge

func (r *TestMetricsRecorder) WaitForInt64Gauge(ctx context.Context, metricsDataWant MetricsData) error

WaitForInt64Gauge waits for a int gauge metric to be recorded and verifies that the recorded metrics data matches the expected metricsDataWant.

func (*TestMetricsRecorder) WaitForInt64Histo

func (r *TestMetricsRecorder) WaitForInt64Histo(ctx context.Context, metricsDataWant MetricsData) error

WaitForInt64Histo waits for an int histo metric to be recorded and verifies that the recorded metrics data matches the expected metricsDataWant. Returns an error if failed to wait or received wrong data.

Jump to

Keyboard shortcuts

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