Documentation
¶
Index ¶
- type AssertOptions
- type Client
- func (c *Client) CloseConnections()
- func (c *Client) Delete(t *testing.T, url string) (string, int)
- func (c *Client) Get(t *testing.T, url string) (string, int)
- func (c *Client) Post(t *testing.T, url, contentType string, data []byte) (string, int)
- func (c *Client) PostForm(t *testing.T, url string, data url.Values) (string, int)
- func (c *Client) Write(t *testing.T, address string, data []string)
- type LogsQLQueryResponse
- type QueryOpts
- type QueryOptsLogs
- type ServesMetrics
- type Stopper
- type TestCase
- func (tc *TestCase) Assert(opts *AssertOptions)
- func (tc *TestCase) Client() *Client
- func (tc *TestCase) Dir() string
- func (tc *TestCase) MustStartDefaultVlagent(remoteWriteURLs []string) *Vlagent
- func (tc *TestCase) MustStartDefaultVlsingle() *Vlsingle
- func (tc *TestCase) MustStartVlagent(instance string, remoteWriteURLs []string, flags []string) *Vlagent
- func (tc *TestCase) MustStartVlsingle(instance string, flags []string) *Vlsingle
- func (tc *TestCase) Stop()
- func (tc *TestCase) StopApp(instance string)
- func (tc *TestCase) T() *testing.T
- type Vlagent
- type Vlsingle
- func (app *Vlsingle) ForceFlush(t *testing.T)
- func (app *Vlsingle) HTTPAddr() string
- func (app *Vlsingle) JSONLineWrite(t *testing.T, records []string, opts QueryOptsLogs)
- func (app *Vlsingle) LogsQLQuery(t *testing.T, query string, opts QueryOptsLogs) *LogsQLQueryResponse
- func (app Vlsingle) Name() string
- func (app *Vlsingle) NativeWrite(t *testing.T, records []logstorage.InsertRow, opts QueryOpts)
- func (app Vlsingle) Stop()
- func (app *Vlsingle) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssertOptions ¶
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.
func (*Client) CloseConnections ¶
func (c *Client) CloseConnections()
CloseConnections closes client connections.
func (*Client) Delete ¶
Delete sends a HTTP DELETE request and returns the response body and status code to the caller.
func (*Client) Get ¶
Get sends a HTTP GET request, returns the response body and status code to the caller.
func (*Client) Post ¶
Post sends a HTTP POST request, returns the response body and status code to the caller.
type LogsQLQueryResponse ¶
type LogsQLQueryResponse struct {
LogLines []string
}
LogsQLQueryResponse is an in-memory representation of the /select/logsql/query response.
func NewLogsQLQueryResponse ¶
func NewLogsQLQueryResponse(t *testing.T, s string) *LogsQLQueryResponse
NewLogsQLQueryResponse is a test helper function that creates a new instance of LogsQLQueryResponse by unmarshalling a json string.
type QueryOpts ¶
type QueryOpts struct {
Timeout string
Start string
End string
Time string
Step string
ExtraFilters []string
ExtraLabels []string
}
QueryOpts contains various params used for querying or ingesting data
type QueryOptsLogs ¶
QueryOptsLogs contains various params used for VictoriaLogs querying or ingesting data
type ServesMetrics ¶
type ServesMetrics struct {
// contains filtered or unexported fields
}
ServesMetrics is used to retrieve the app's metrics.
This type is expected to be embedded 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 ¶
func (app *ServesMetrics) GetMetricsByPrefix(t *testing.T, prefix string) []float64
GetMetricsByPrefix retrieves the values of all metrics that start with given prefix.
type Stopper ¶
type Stopper interface {
Stop()
}
Stopper is an interface of objects that needs to be stopped via Stop() call
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 ¶
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) MustStartDefaultVlagent ¶
MustStartDefaultVlagent is a test helper function that starts an instance of vlagent with defaults suitable for most tests.
func (*TestCase) MustStartDefaultVlsingle ¶
MustStartDefaultVlsingle is a test helper function that starts an instance of vlsingle with defaults suitable for most tests.
func (*TestCase) MustStartVlagent ¶
func (tc *TestCase) MustStartVlagent(instance string, remoteWriteURLs []string, flags []string) *Vlagent
MustStartVlagent is a test helper function that starts an instance of vlagent and fails the test if the app fails to start.
func (*TestCase) MustStartVlsingle ¶
MustStartVlsingle is a test helper function that starts an instance of vlsingle and fails the test if the app fails to start.
func (*TestCase) Stop ¶
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 Vlagent ¶
type Vlagent struct {
*ServesMetrics
// contains filtered or unexported fields
}
Vlagent holds the state of a vlagent app and provides vlagent-specific functions
func StartVlagent ¶
func StartVlagent(instance string, remoteWriteURLs []string, flags []string, cli *Client) (*Vlagent, error)
StartVlagent starts an instance of vlagent 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 (*Vlagent) JSONLineWrite ¶
func (app *Vlagent) JSONLineWrite(t *testing.T, records []string, opts QueryOptsLogs)
JSONLineWrite is a test helper function that inserts a collection of records in json line format by sending a HTTP POST request to /insert/jsonline vlagent endpoint.
See https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api
func (Vlagent) Stop ¶
func (app Vlagent) Stop()
Stop sends the app process a SIGINT signal and waits until it terminates gracefully.
func (Vlagent) String ¶
func (app Vlagent) String() string
String returns the string representation of the app state.
func (*Vlagent) WaitQueueEmptyAfter ¶
WaitQueueEmptyAfter checks that persistent queue is empty after execution of provided callback
type Vlsingle ¶
type Vlsingle struct {
*ServesMetrics
// contains filtered or unexported fields
}
Vlsingle holds the state of a vlsingle app and provides vlsingle-specific functions.
func StartVlsingle ¶
StartVlsingle starts an instance of vlsingle 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 (*Vlsingle) ForceFlush ¶
ForceFlush is a test helper function that forces the flushing of inserted data, so it becomes available for searching immediately.
func (*Vlsingle) HTTPAddr ¶
HTTPAddr returns the address at which the vmstorage process is listening for http connections.
func (*Vlsingle) JSONLineWrite ¶
func (app *Vlsingle) JSONLineWrite(t *testing.T, records []string, opts QueryOptsLogs)
JSONLineWrite is a test helper function that inserts a collection of records in json line format by sending a HTTP POST request to /insert/jsonline vlsingle endpoint.
See https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api
func (*Vlsingle) LogsQLQuery ¶
func (app *Vlsingle) LogsQLQuery(t *testing.T, query string, opts QueryOptsLogs) *LogsQLQueryResponse
LogsQLQuery is a test helper function that performs PromQL/MetricsQL range query by sending a HTTP POST request to /select/logsql/query endpoint.
See https://docs.victoriametrics.com/victorialogs/querying/#querying-logs
func (Vlsingle) Name ¶
func (app Vlsingle) Name() string
Name returns the application instance name.
func (*Vlsingle) NativeWrite ¶
NativeWrite is a test helper function that sends a collection of records to /internal/insert API.