Documentation ¶
Overview ¶
Package stats implements a TestMetricsRecorder utility.
Index ¶
- type MetricsData
- type NoopMetricsRecorder
- func (r *NoopMetricsRecorder) RecordFloat64Count(*estats.Float64CountHandle, float64, ...string)
- func (r *NoopMetricsRecorder) RecordFloat64Histo(*estats.Float64HistoHandle, float64, ...string)
- func (r *NoopMetricsRecorder) RecordInt64Count(*estats.Int64CountHandle, int64, ...string)
- func (r *NoopMetricsRecorder) RecordInt64Gauge(*estats.Int64GaugeHandle, int64, ...string)
- func (r *NoopMetricsRecorder) RecordInt64Histo(*estats.Int64HistoHandle, int64, ...string)
- type TestMetricsRecorder
- func (r *TestMetricsRecorder) ClearMetrics()
- func (r *TestMetricsRecorder) HandleConn(context.Context, stats.ConnStats)
- func (r *TestMetricsRecorder) HandleRPC(context.Context, stats.RPCStats)
- func (r *TestMetricsRecorder) Metric(name string) (float64, bool)
- func (r *TestMetricsRecorder) RecordFloat64Count(handle *estats.Float64CountHandle, incr float64, labels ...string)
- func (r *TestMetricsRecorder) RecordFloat64Histo(handle *estats.Float64HistoHandle, incr float64, labels ...string)
- func (r *TestMetricsRecorder) RecordInt64Count(handle *estats.Int64CountHandle, incr int64, labels ...string)
- func (r *TestMetricsRecorder) RecordInt64Gauge(handle *estats.Int64GaugeHandle, incr int64, labels ...string)
- func (r *TestMetricsRecorder) RecordInt64Histo(handle *estats.Int64HistoHandle, incr int64, labels ...string)
- func (r *TestMetricsRecorder) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
- func (r *TestMetricsRecorder) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context
- func (r *TestMetricsRecorder) WaitForFloat64Count(ctx context.Context, metricsDataWant MetricsData) error
- func (r *TestMetricsRecorder) WaitForFloat64Histo(ctx context.Context, metricsDataWant MetricsData) error
- func (r *TestMetricsRecorder) WaitForInt64Count(ctx context.Context, metricsDataWant MetricsData) error
- func (r *TestMetricsRecorder) WaitForInt64Gauge(ctx context.Context, metricsDataWant MetricsData) error
- func (r *TestMetricsRecorder) WaitForInt64Histo(ctx context.Context, metricsDataWant MetricsData) error
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 ¶
func (r *TestMetricsRecorder) HandleConn(context.Context, stats.ConnStats)
HandleConn is TestMetricsRecorder's implementation of HandleConn.
func (*TestMetricsRecorder) HandleRPC ¶
func (r *TestMetricsRecorder) HandleRPC(context.Context, stats.RPCStats)
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 ¶
func (r *TestMetricsRecorder) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
TagConn is TestMetricsRecorder's implementation of TagConn.
func (*TestMetricsRecorder) TagRPC ¶
func (r *TestMetricsRecorder) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context
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) 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.