Documentation
¶
Index ¶
- func RequireEqual(t testing.TB, expected, got []Sample, msgAndArgs ...any)
- func RequireNotEqual(t testing.TB, expected, got []Sample, msgAndArgs ...any)
- type Appendable
- func (a *Appendable) Appender(ctx context.Context) storage.Appender
- func (a *Appendable) AppenderV2(ctx context.Context) storage.AppenderV2
- func (a *Appendable) PendingSamples() []Sample
- func (a *Appendable) ResultMetadata() []Sample
- func (a *Appendable) ResultReset()
- func (a *Appendable) ResultSamples() []Sample
- func (a *Appendable) RolledbackSamples() []Sample
- func (a *Appendable) SkipRecording(skipRecording bool) *Appendable
- func (a *Appendable) String() string
- func (a *Appendable) Then(appendable compatAppendable) *Appendable
- func (a *Appendable) WithErrs(appendErrFn func(ls labels.Labels) error, ...) *Appendable
- type Option
- type Sample
- type TestStorage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequireEqual ¶ added in v0.310.0
RequireEqual is a special require equal that correctly compare Prometheus structures.
In comparison to testutil.RequireEqual, this function adds special logic for comparing []Samples.
It also ignores ordering between consecutive stale samples to avoid false negatives due to map iteration order in staleness tracking.
Types ¶
type Appendable ¶ added in v0.310.0
type Appendable struct {
// contains filtered or unexported fields
}
Appendable is a storage.Appendable mock. It allows recording all samples that were added through the appender and injecting errors. Appendable will panic if more than one Appender is open.
func NewAppendable ¶ added in v0.310.0
func NewAppendable() *Appendable
NewAppendable returns mock Appendable.
func (*Appendable) Appender ¶ added in v0.310.0
func (a *Appendable) Appender(ctx context.Context) storage.Appender
func (*Appendable) AppenderV2 ¶ added in v0.310.0
func (a *Appendable) AppenderV2(ctx context.Context) storage.AppenderV2
func (*Appendable) PendingSamples ¶ added in v0.310.0
func (a *Appendable) PendingSamples() []Sample
PendingSamples returns pending samples (samples appended without commit).
func (*Appendable) ResultMetadata ¶ added in v0.310.0
func (a *Appendable) ResultMetadata() []Sample
ResultMetadata returns resultSamples with samples only containing L and M. This is for compatibility with tests that only focus on metadata.
TODO: Rewrite tests to test metadata on resultSamples instead.
func (*Appendable) ResultReset ¶ added in v0.310.0
func (a *Appendable) ResultReset()
func (*Appendable) ResultSamples ¶ added in v0.310.0
func (a *Appendable) ResultSamples() []Sample
ResultSamples returns committed samples.
func (*Appendable) RolledbackSamples ¶ added in v0.310.0
func (a *Appendable) RolledbackSamples() []Sample
RolledbackSamples returns rolled back samples.
func (*Appendable) SkipRecording ¶ added in v0.310.0
func (a *Appendable) SkipRecording(skipRecording bool) *Appendable
SkipRecording enables or disables recording appended samples. If skipped, Appendable allocs less, but Result*() methods will give always empty results. This is useful for benchmarking.
func (*Appendable) String ¶ added in v0.310.0
func (a *Appendable) String() string
func (*Appendable) Then ¶ added in v0.310.0
func (a *Appendable) Then(appendable compatAppendable) *Appendable
Then chains another appender from the provided Appendable for the Appender calls.
func (*Appendable) WithErrs ¶ added in v0.310.0
func (a *Appendable) WithErrs(appendErrFn func(ls labels.Labels) error, appendExemplarsError, commitErr error) *Appendable
WithErrs allows injecting errors to the appender.
type Sample ¶ added in v0.310.0
type Sample struct {
MF string
L labels.Labels
M metadata.Metadata
ST, T int64
V float64
H *histogram.Histogram
FH *histogram.FloatHistogram
ES []exemplar.Exemplar
}
Sample represents test, combined sample for mocking storage.AppenderV2.
func (Sample) IsStale ¶ added in v0.310.0
IsStale returns whether the sample represents a stale sample, according to https://prometheus.io/docs/specs/native_histograms/#staleness-markers.
type TestStorage ¶
func New ¶
func New(t testing.TB, o ...Option) *TestStorage
New returns a new TestStorage for testing purposes that removes all associated files on closing.
Caller does not need to close the TestStorage after use, it's deferred via t.Cleanup.
func NewWithError ¶ added in v0.52.0
func NewWithError(o ...Option) (*TestStorage, error)
NewWithError returns a new TestStorage for user facing tests, which reports errors directly.
It's a caller responsibility to close the TestStorage after use.
func (TestStorage) Close ¶
func (s TestStorage) Close() error