Documentation
¶
Overview ¶
Package lokicompliance provides utilities for Loki/LogQL compliance testing.
Packagel lokicompliance provides utilities for Loki/LogQL compliance testing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateLogs ¶
func GenerateLogs(ctx context.Context, targets []string, opts GenerateOptions) error
GenerateLogs generates logs and sends them to targets
Types ¶
type Comparer ¶
type Comparer struct {
// contains filtered or unexported fields
}
A Comparer allows comparing query results for test cases between a reference API and a test API.
type Config ¶
type Config struct {
ReferenceTargetConfig TargetConfig `yaml:"reference_target_config"`
TestTargetConfig TargetConfig `yaml:"test_target_config"`
TestCases []*TestCasePattern `yaml:"test_cases"`
QueryParameters QueryParameters `yaml:"query_parameters"`
}
Config models the main configuration file.
func LoadFromFiles ¶
LoadFromFiles parses the given YAML files into a Config.
type GenerateOptions ¶
type GenerateOptions struct {
Start, End time.Time
Step time.Duration
Lines int
Streams []string
Client ht.Client
}
GenerateOptions defines options for [LogGenerator.Generate].
type LogEntry ¶
type LogEntry struct {
Timestamp time.Time
Level plog.SeverityNumber
// HTTP attributes.
Protocol string
Method string
ClientIP netip.Addr
RemoteIP netip.Addr
RemotePort uint16
Status int
Took time.Duration
Size uint64
SpanID pcommon.SpanID
TraceID pcommon.TraceID
}
func NewLogEntry ¶
NewLogEntry generates new LogEntry.
func (LogEntry) EncodeJSON ¶
EncodeJSON encodes entry to given encoder.
type LokiAPI ¶
type LokiAPI interface {
Query(ctx context.Context, params lokiapi.QueryParams) (*lokiapi.QueryResponse, error)
QueryRange(ctx context.Context, params lokiapi.QueryRangeParams) (*lokiapi.QueryResponse, error)
}
LokiAPI represents LogQL API.
type QueryParameters ¶
type Result ¶
type Result struct {
TestCase *TestCase `json:"testCase"`
Diff string `json:"diff"`
Expected json.RawMessage `json:"expected"`
Got json.RawMessage `json:"got"`
UnexpectedFailure string `json:"unexpectedFailure"`
UnexpectedSuccess bool `json:"unexpectedSuccess"`
Unsupported bool `json:"unsupported"`
}
Result tracks a single test case's query comparison result.
type TargetConfig ¶
type TargetConfig struct {
// ReadyQuery is a log query to check instance readiness.
ReadyQuery string `yaml:"ready_query"`
QueryURL string `yaml:"query_url"`
PushURL string `yaml:"push_url,omitempty"`
}
TargetConfig represents the configuration of a single Prometheus API endpoint.
type TestCase ¶
type TestCase struct {
Query string `json:"query"`
SkipComparison bool `json:"skipComparison"`
ShouldFail bool `json:"shouldFail"`
ShouldBeEmpty bool `json:"shouldBeEmpty"`
Start time.Time `json:"start"`
End time.Time `json:"end"`
Step time.Duration `json:"step"`
Limit int `json:"limit"`
Direction lokiapi.Direction `json:"direction"`
}
TestCase represents a fully expanded query to be tested.