Documentation ¶
Index ¶
- type AssertOptions
- type Client
- func (c *Client) CloseConnections()
- func (c *Client) Get(t *testing.T, url string, wantStatusCode int) string
- func (c *Client) Post(t *testing.T, url, contentType string, data []byte, wantStatusCode int) string
- func (c *Client) PostForm(t *testing.T, url string, data url.Values, wantStatusCode int) string
- type ClusterOptions
- type PrometheusAPIV1QueryResponse
- type PrometheusAPIV1SeriesResponse
- type PrometheusQuerier
- type PrometheusWriteQuerier
- type PrometheusWriter
- type QueryData
- type QueryOpts
- type QueryResult
- type Sample
- type ServesMetrics
- type Stopper
- type StorageFlusher
- type TestCase
- func (tc *TestCase) Assert(opts *AssertOptions)
- func (tc *TestCase) Client() *Client
- func (tc *TestCase) Dir() string
- func (tc *TestCase) ForceFlush(apps ...*Vmstorage)
- func (tc *TestCase) MustStartCluster(opts *ClusterOptions) PrometheusWriteQuerier
- func (tc *TestCase) MustStartDefaultCluster() PrometheusWriteQuerier
- func (tc *TestCase) MustStartDefaultVmsingle() *Vmsingle
- func (tc *TestCase) MustStartVminsert(instance string, flags []string) *Vminsert
- func (tc *TestCase) MustStartVmselect(instance string, flags []string) *Vmselect
- func (tc *TestCase) MustStartVmsingle(instance string, flags []string) *Vmsingle
- func (tc *TestCase) MustStartVmstorage(instance string, flags []string) *Vmstorage
- func (tc *TestCase) Stop()
- func (tc *TestCase) StopApp(instance string)
- func (tc *TestCase) T() *testing.T
- type Trace
- type Vminsert
- func (app *Vminsert) ClusternativeListenAddr() string
- func (app Vminsert) Name() string
- func (app *Vminsert) PrometheusAPIV1ImportPrometheus(t *testing.T, records []string, opts QueryOpts)
- func (app *Vminsert) PrometheusAPIV1Write(t *testing.T, records []pb.TimeSeries, opts QueryOpts)
- func (app Vminsert) Stop()
- func (app *Vminsert) String() string
- type Vmselect
- func (app *Vmselect) ClusternativeListenAddr() string
- func (app Vmselect) Name() string
- func (app *Vmselect) PrometheusAPIV1Export(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
- func (app *Vmselect) PrometheusAPIV1Query(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
- func (app *Vmselect) PrometheusAPIV1QueryRange(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
- func (app *Vmselect) PrometheusAPIV1Series(t *testing.T, matchQuery string, opts QueryOpts) *PrometheusAPIV1SeriesResponse
- func (app Vmselect) Stop()
- func (app *Vmselect) String() string
- type Vmsingle
- func (app *Vmsingle) ForceFlush(t *testing.T)
- func (app *Vmsingle) InfluxWrite(t *testing.T, records []string, _ QueryOpts)
- func (app Vmsingle) Name() string
- func (app *Vmsingle) PrometheusAPIV1Export(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
- func (app *Vmsingle) PrometheusAPIV1ImportPrometheus(t *testing.T, records []string, _ QueryOpts)
- func (app *Vmsingle) PrometheusAPIV1Query(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
- func (app *Vmsingle) PrometheusAPIV1QueryRange(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
- func (app *Vmsingle) PrometheusAPIV1Series(t *testing.T, matchQuery string, opts QueryOpts) *PrometheusAPIV1SeriesResponse
- func (app *Vmsingle) PrometheusAPIV1Write(t *testing.T, records []pb.TimeSeries, _ QueryOpts)
- func (app Vmsingle) Stop()
- func (app *Vmsingle) String() string
- type Vmstorage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssertOptions ¶ added in v1.97.13
type AssertOptions struct { Msg string Got func() any Want any CmpOpts []cmp.Option DoNotRetry bool Retries int Period time.Duration FailNow bool }
AssertOptions hold the assertion params, such as got and wanted values as well as the message that should be included into the assertion error message in case of failure.
In VictoriaMetrics (especially the cluster version) the inserted data does not become visible for querying right away. Therefore, the first comparisons may fail. AssertOptions allow to configure how many times the actual result must be retrieved and compared with the expected one and for long to wait between the retries. If these two params (`Retries` and `Period`) are not set, the default values will be used.
If it is known that the data is available, then the retry functionality can be disabled by setting the `DoNotRetry` field.
AssertOptions are used by the TestCase.Assert() method, and this method uses cmp.Diff() from go-cmp package for comparing got and wanted values. AssertOptions, therefore, allows to pass cmp.Options to cmp.Diff() via `CmpOpts` field.
Finally the `FailNow` field controls whether the assertion should fail using `testing.T.Errorf()` or `testing.T.Fatalf()`.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is used for interacting with the apps over the network.
At the moment it only supports HTTP protocol but may be exptended to support RPCs, etc.
func (*Client) CloseConnections ¶
func (c *Client) CloseConnections()
CloseConnections closes client connections.
func (*Client) Get ¶
Get sends a HTTP GET request. Once the function receives a response, it checks whether the response status code matches the expected one and returns the response body to the caller.
func (*Client) Post ¶
func (c *Client) Post(t *testing.T, url, contentType string, data []byte, wantStatusCode int) string
Post sends a HTTP POST request. Once the function receives a response, it checks whether the response status code matches the expected one and returns the response body to the caller.
type ClusterOptions ¶ added in v1.97.15
type ClusterOptions struct { Vmstorage1Instance string Vmstorage1Flags []string Vmstorage2Instance string Vmstorage2Flags []string VminsertInstance string VminsertFlags []string VmselectInstance string VmselectFlags []string }
ClusterOptions holds the params for simple cluster configuration suitable for most tests.
The cluster consists of two vmstorages, one vminsert and one vmselect, no data replication.
Such configuration is suitable for tests that don't verify the cluster-specific behavior (such as sharding, replication, or multilevel vmselect) but instead just need a typical cluster configuration to verify some business logic (such as API surface, or MetricsQL). Such cluster tests usually come paired with corresponding vmsingle tests.
type PrometheusAPIV1QueryResponse ¶ added in v1.97.12
PrometheusAPIV1QueryResponse is an inmemory representation of the /prometheus/api/v1/query or /prometheus/api/v1/query_range response.
func NewPrometheusAPIV1QueryResponse ¶ added in v1.97.12
func NewPrometheusAPIV1QueryResponse(t *testing.T, s string) *PrometheusAPIV1QueryResponse
NewPrometheusAPIV1QueryResponse is a test helper function that creates a new instance of PrometheusAPIV1QueryResponse by unmarshalling a json string.
type PrometheusAPIV1SeriesResponse ¶
type PrometheusAPIV1SeriesResponse struct { Status string IsPartial bool Data []map[string]string Trace *Trace }
PrometheusAPIV1SeriesResponse is an inmemory representation of the /prometheus/api/v1/series response.
func NewPrometheusAPIV1SeriesResponse ¶ added in v1.97.12
func NewPrometheusAPIV1SeriesResponse(t *testing.T, s string) *PrometheusAPIV1SeriesResponse
NewPrometheusAPIV1SeriesResponse is a test helper function that creates a new instance of PrometheusAPIV1SeriesResponse by unmarshalling a json string.
func (*PrometheusAPIV1SeriesResponse) Sort ¶ added in v1.97.13
func (r *PrometheusAPIV1SeriesResponse) Sort() *PrometheusAPIV1SeriesResponse
Sort sorts the response data.
type PrometheusQuerier ¶ added in v1.97.12
type PrometheusQuerier interface { PrometheusAPIV1Export(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse PrometheusAPIV1Query(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse PrometheusAPIV1QueryRange(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse PrometheusAPIV1Series(t *testing.T, matchQuery string, opts QueryOpts) *PrometheusAPIV1SeriesResponse }
PrometheusQuerier contains methods available to Prometheus-like HTTP API for Querying
type PrometheusWriteQuerier ¶ added in v1.97.13
type PrometheusWriteQuerier interface { PrometheusWriter PrometheusQuerier StorageFlusher }
PrometheusWriteQuerier encompasses the methods for writing, flushing and querying the data.
type PrometheusWriter ¶ added in v1.97.12
type PrometheusWriter interface { PrometheusAPIV1Write(t *testing.T, records []pb.TimeSeries, opts QueryOpts) PrometheusAPIV1ImportPrometheus(t *testing.T, records []string, opts QueryOpts) }
PrometheusWriter contains methods available to Prometheus-like HTTP API for Writing new data
type QueryData ¶ added in v1.97.12
type QueryData struct { ResultType string Result []*QueryResult }
QueryData holds the query result along with its type.
type QueryOpts ¶ added in v1.97.12
type QueryOpts struct { Tenant string Timeout string Start string End string Time string Step string ExtraFilters []string ExtraLabels []string Trace string }
QueryOpts contains various params used for querying or ingesting data
type QueryResult ¶ added in v1.97.12
type QueryResult struct { Metric map[string]string Sample *Sample `json:"value"` Samples []*Sample `json:"values"` }
QueryResult holds the metric name (in the form of label name-value collection) and its samples.
Sample or Samples field is set for /prometheus/api/v1/query or /prometheus/api/v1/query_range response respectively.
type Sample ¶ added in v1.97.12
Sample is a timeseries value at a given timestamp.
func NewSample ¶ added in v1.97.12
NewSample is a test helper function that creates a new sample out of time in RFC3339 format and a value.
func (*Sample) UnmarshalJSON ¶ added in v1.97.12
UnmarshalJSON populates the sample fields from a JSON string.
type ServesMetrics ¶
type ServesMetrics struct {
// contains filtered or unexported fields
}
ServesMetrics is used to retrive the app's metrics.
This type is expected to be embdded by the apps that serve metrics.
func (*ServesMetrics) GetIntMetric ¶
func (app *ServesMetrics) GetIntMetric(t *testing.T, metricName string) int
GetIntMetric retrieves the value of a metric served by an app at /metrics URL. The value is then converted to int.
func (*ServesMetrics) GetMetric ¶
func (app *ServesMetrics) GetMetric(t *testing.T, metricName string) float64
GetMetric retrieves the value of a metric served by an app at /metrics URL.
func (*ServesMetrics) GetMetricsByPrefix ¶ added in v1.97.13
func (app *ServesMetrics) GetMetricsByPrefix(t *testing.T, prefix string) []float64
GetMetricsByPrefix retrieves the values of all metrics that start with given prefix.
type Stopper ¶ added in v1.97.12
type Stopper interface {
Stop()
}
Stopper is an interface of objects that needs to be stopped via Stop() call
type StorageFlusher ¶ added in v1.97.13
StorageFlusher defines a method that forces the flushing of data inserted into the storage, so it becomes available for searching immediately.
type TestCase ¶
type TestCase struct {
// contains filtered or unexported fields
}
TestCase holds the state and defines clean-up procedure common for all test cases.
func (*TestCase) Assert ¶ added in v1.97.13
func (tc *TestCase) Assert(opts *AssertOptions)
Assert compares the actual result with the expected one possibly multiple times in order to account for the fact that the inserted data does not become available for querying right away (especially in cluster version of VictoriaMetrics).
func (*TestCase) Client ¶
Client returns an instance of the client that can be used for interacting with the app(s) under test.
func (*TestCase) Dir ¶
Dir returns the directory name that should be used by as the -storageDataDir.
func (*TestCase) ForceFlush ¶ added in v1.97.14
ForceFlush flushes zero or more storages.
func (*TestCase) MustStartCluster ¶ added in v1.97.15
func (tc *TestCase) MustStartCluster(opts *ClusterOptions) PrometheusWriteQuerier
MustStartCluster starts a typical cluster configuration with custom flags.
func (*TestCase) MustStartDefaultCluster ¶ added in v1.97.13
func (tc *TestCase) MustStartDefaultCluster() PrometheusWriteQuerier
MustStartDefaultCluster starts a typical cluster configuration with default flags.
func (*TestCase) MustStartDefaultVmsingle ¶ added in v1.97.13
MustStartDefaultVmsingle is a test helper function that starts an instance of vmsingle with defaults suitable for most tests.
func (*TestCase) MustStartVminsert ¶ added in v1.97.12
MustStartVminsert is a test helper function that starts an instance of vminsert and fails the test if the app fails to start.
func (*TestCase) MustStartVmselect ¶ added in v1.97.12
MustStartVmselect is a test helper function that starts an instance of vmselect and fails the test if the app fails to start.
func (*TestCase) MustStartVmsingle ¶ added in v1.97.12
MustStartVmsingle is a test helper function that starts an instance of vmsingle and fails the test if the app fails to start.
func (*TestCase) MustStartVmstorage ¶ added in v1.97.12
MustStartVmstorage is a test helper function that starts an instance of vmstorage and fails the test if the app fails to start.
func (*TestCase) Stop ¶ added in v1.97.12
func (tc *TestCase) Stop()
Stop performs the test case clean up, such as closing all client connections and removing the -storageDataDir directory.
Note that the -storageDataDir is not removed in case of test case failure to allow for further manual debugging.
type Trace ¶ added in v1.97.14
Trace provides the description and the duration of some unit of work that has been performed during the request processing.
type Vminsert ¶
type Vminsert struct { *ServesMetrics // contains filtered or unexported fields }
Vminsert holds the state of a vminsert app and provides vminsert-specific functions.
func StartVminsert ¶
StartVminsert starts an instance of vminsert with the given flags. It also sets the default flags and populates the app instance state with runtime values extracted from the application log (such as httpListenAddr)
func (*Vminsert) ClusternativeListenAddr ¶ added in v1.97.14
ClusternativeListenAddr returns the address at which the vminsert process is listening for connections from other vminsert apps.
func (Vminsert) Name ¶ added in v1.97.14
func (app Vminsert) Name() string
Name returns the application instance name.
func (*Vminsert) PrometheusAPIV1ImportPrometheus ¶
func (app *Vminsert) PrometheusAPIV1ImportPrometheus(t *testing.T, records []string, opts QueryOpts)
PrometheusAPIV1ImportPrometheus is a test helper function that inserts a collection of records in Prometheus text exposition format for the given tenant by sending a HTTP POST request to /prometheus/api/v1/import/prometheus vminsert endpoint.
See https://docs.victoriametrics.com/url-examples/#apiv1importprometheus
func (*Vminsert) PrometheusAPIV1Write ¶ added in v1.97.13
PrometheusAPIV1Write is a test helper function that inserts a collection of records in Prometheus remote-write format by sending a HTTP POST request to /prometheus/api/v1/write vminsert endpoint.
type Vmselect ¶
type Vmselect struct { *ServesMetrics // contains filtered or unexported fields }
Vmselect holds the state of a vmselect app and provides vmselect-specific functions.
func StartVmselect ¶
StartVmselect starts an instance of vmselect with the given flags. It also sets the default flags and populates the app instance state with runtime values extracted from the application log (such as httpListenAddr)
func (*Vmselect) ClusternativeListenAddr ¶
ClusternativeListenAddr returns the address at which the vmselect process is listening for connections from other vmselect apps.
func (Vmselect) Name ¶ added in v1.97.14
func (app Vmselect) Name() string
Name returns the application instance name.
func (*Vmselect) PrometheusAPIV1Export ¶ added in v1.97.13
func (app *Vmselect) PrometheusAPIV1Export(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
PrometheusAPIV1Export is a test helper function that performs the export of raw samples in JSON line format by sending a HTTP POST request to /prometheus/api/v1/export vmselect endpoint.
See https://docs.victoriametrics.com/url-examples/#apiv1export
func (*Vmselect) PrometheusAPIV1Query ¶ added in v1.97.12
func (app *Vmselect) PrometheusAPIV1Query(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
PrometheusAPIV1Query is a test helper function that performs PromQL/MetricsQL instant query by sending a HTTP POST request to /prometheus/api/v1/query vmselect endpoint.
See https://docs.victoriametrics.com/url-examples/#apiv1query
func (*Vmselect) PrometheusAPIV1QueryRange ¶ added in v1.97.12
func (app *Vmselect) PrometheusAPIV1QueryRange(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
PrometheusAPIV1QueryRange is a test helper function that performs PromQL/MetricsQL range query by sending a HTTP POST request to /prometheus/api/v1/query_range vmselect endpoint.
See https://docs.victoriametrics.com/url-examples/#apiv1query_range
func (*Vmselect) PrometheusAPIV1Series ¶
func (app *Vmselect) PrometheusAPIV1Series(t *testing.T, matchQuery string, opts QueryOpts) *PrometheusAPIV1SeriesResponse
PrometheusAPIV1Series sends a query to a /prometheus/api/v1/series endpoint and returns the list of time series that match the query.
See https://docs.victoriametrics.com/url-examples/#apiv1series
type Vmsingle ¶ added in v1.97.12
type Vmsingle struct { *ServesMetrics // contains filtered or unexported fields }
Vmsingle holds the state of a vmsingle app and provides vmsingle-specific functions.
func StartVmsingle ¶ added in v1.97.12
StartVmsingle starts an instance of vmsingle with the given flags. It also sets the default flags and populates the app instance state with runtime values extracted from the application log (such as httpListenAddr).
func (*Vmsingle) ForceFlush ¶ added in v1.97.12
ForceFlush is a test helper function that forces the flushing of inserted data, so it becomes available for searching immediately.
func (*Vmsingle) InfluxWrite ¶ added in v1.97.15
InfluxWrite is a test helper function that inserts a collection of records in Influx line format by sending a HTTP POST request to /influx/write vmsingle endpoint.
See https://docs.victoriametrics.com/url-examples/#influxwrite
func (Vmsingle) Name ¶ added in v1.97.14
func (app Vmsingle) Name() string
Name returns the application instance name.
func (*Vmsingle) PrometheusAPIV1Export ¶ added in v1.97.13
func (app *Vmsingle) PrometheusAPIV1Export(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
PrometheusAPIV1Export is a test helper function that performs the export of raw samples in JSON line format by sending a HTTP POST request to /prometheus/api/v1/export vmsingle endpoint.
See https://docs.victoriametrics.com/url-examples/#apiv1export
func (*Vmsingle) PrometheusAPIV1ImportPrometheus ¶ added in v1.97.12
PrometheusAPIV1ImportPrometheus is a test helper function that inserts a collection of records in Prometheus text exposition format by sending a HTTP POST request to /prometheus/api/v1/import/prometheus vmsingle endpoint.
See https://docs.victoriametrics.com/url-examples/#apiv1importprometheus
func (*Vmsingle) PrometheusAPIV1Query ¶ added in v1.97.12
func (app *Vmsingle) PrometheusAPIV1Query(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
PrometheusAPIV1Query is a test helper function that performs PromQL/MetricsQL instant query by sending a HTTP POST request to /prometheus/api/v1/query vmsingle endpoint.
See https://docs.victoriametrics.com/url-examples/#apiv1query
func (*Vmsingle) PrometheusAPIV1QueryRange ¶ added in v1.97.12
func (app *Vmsingle) PrometheusAPIV1QueryRange(t *testing.T, query string, opts QueryOpts) *PrometheusAPIV1QueryResponse
PrometheusAPIV1QueryRange is a test helper function that performs PromQL/MetricsQL range query by sending a HTTP POST request to /prometheus/api/v1/query_range vmsingle endpoint.
See https://docs.victoriametrics.com/url-examples/#apiv1query_range
func (*Vmsingle) PrometheusAPIV1Series ¶ added in v1.97.12
func (app *Vmsingle) PrometheusAPIV1Series(t *testing.T, matchQuery string, opts QueryOpts) *PrometheusAPIV1SeriesResponse
PrometheusAPIV1Series sends a query to a /prometheus/api/v1/series endpoint and returns the list of time series that match the query.
See https://docs.victoriametrics.com/url-examples/#apiv1series
func (*Vmsingle) PrometheusAPIV1Write ¶ added in v1.97.13
PrometheusAPIV1Write is a test helper function that inserts a collection of records in Prometheus remote-write format by sending a HTTP POST request to /prometheus/api/v1/write vmsingle endpoint.
type Vmstorage ¶
type Vmstorage struct { *ServesMetrics // contains filtered or unexported fields }
Vmstorage holds the state of a vmstorage app and provides vmstorage-specific functions.
func StartVmstorage ¶
StartVmstorage starts an instance of vmstorage with the given flags. It also sets the default flags and populates the app instance state with runtime values extracted from the application log (such as httpListenAddr)
func (*Vmstorage) ForceFlush ¶ added in v1.97.12
ForceFlush is a test helper function that forces the flushing of inserted data, so it becomes available for searching immediately.
func (Vmstorage) Name ¶ added in v1.97.14
func (app Vmstorage) Name() string
Name returns the application instance name.
func (Vmstorage) Stop ¶
func (app Vmstorage) Stop()
stop sends the app process a SIGINT signal and waits until it terminates gracefully.
func (*Vmstorage) VminsertAddr ¶
VminsertAddr returns the address at which the vmstorage process is listening for vminsert connections.
func (*Vmstorage) VmselectAddr ¶
VmselectAddr returns the address at which the vmstorage process is listening for vmselect connections.