Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateMinRanges(config *GeneratorConfig) (minRange, minInstantRange time.Duration)
- func SaveConfig(dataDir string, config *GeneratorConfig) error
- func SaveMetadata(dataDir string, metadata *DatasetMetadata) error
- type Batch
- type Builder
- type ChunkStore
- type DataObjStore
- type DataObjV2EngineStore
- type DatasetMetadata
- type DatasetStatistics
- type DenseInterval
- type Faker
- func (f *Faker) AuthAction() string
- func (f *Faker) AuthError() string
- func (f *Faker) AuthSuccess() bool
- func (f *Faker) CacheError() string
- func (f *Faker) CacheKey() string
- func (f *Faker) CacheOp() string
- func (f *Faker) CacheSize() int
- func (f *Faker) CacheTTL() int
- func (f *Faker) DBError() string
- func (f *Faker) Duration() time.Duration
- func (f *Faker) Error() string
- func (f *Faker) ErrorMessage() string
- func (f *Faker) GRPCMethod() string
- func (f *Faker) GrafanaComponent() string
- func (f *Faker) GrafanaLogger() string
- func (f *Faker) GrafanaMessage() string
- func (f *Faker) Hostname() string
- func (f *Faker) IP() string
- func (f *Faker) K8sComponent() string
- func (f *Faker) K8sLogPrefix() string
- func (f *Faker) K8sMessage() string
- func (f *Faker) KafkaError() string
- func (f *Faker) KafkaEvent() string
- func (f *Faker) KafkaOffset() int
- func (f *Faker) KafkaPartition() int
- func (f *Faker) KafkaTopic() string
- func (f *Faker) Method() string
- func (f *Faker) NginxErrorType() string
- func (f *Faker) NginxPath() string
- func (f *Faker) OrgID() string
- func (f *Faker) PID() int
- func (f *Faker) Path() string
- func (f *Faker) PrometheusComponent() string
- func (f *Faker) PrometheusMessage() string
- func (f *Faker) PrometheusSubcomponent() string
- func (f *Faker) QueryType() string
- func (f *Faker) Referer() string
- func (f *Faker) RowsAffected() int
- func (f *Faker) SpanID() string
- func (f *Faker) Status() int
- func (f *Faker) SyslogPriority(isError bool) int
- func (f *Faker) Table() string
- func (f *Faker) TempoComponent() string
- func (f *Faker) TempoMessage() string
- func (f *Faker) TraceID() string
- func (f *Faker) User() string
- func (f *Faker) UserAgent() string
- type Generator
- type GeneratorConfig
- type K6TestCase
- type LabelConfig
- type LogFormat
- type LogGenerator
- type MetadataVariableResolver
- type OTELAttributes
- type OTELTraceContext
- type Opt
- func (o Opt) WithDenseInterval(start time.Time, duration time.Duration) Opt
- func (o Opt) WithLabelCardinality(clusters, namespaces, services, pods, containers int) Opt
- func (o Opt) WithLabelConfig(cfg LabelConfig) Opt
- func (o Opt) WithNumStreams(n int) Opt
- func (o Opt) WithSeed(seed int64) Opt
- func (o Opt) WithStartTime(t time.Time) Opt
- func (o Opt) WithTimeSpread(d time.Duration) Opt
- type QueryDefinition
- type QueryDirection
- type QueryFile
- type QueryRegistry
- type QueryRequirements
- type SerializableStreamMetadata
- type Service
- type Store
- type StreamMetadata
- type Suite
- type TestCase
- type TimeRange
- type TimeRangeConfig
- type VariableResolver
Constants ¶
const (
DefaultDataDir = "./data"
)
const ( // MetadataVersion is the current version of the dataset metadata format. // It is exported so that callers outside the bench package (e.g. the // discover pipeline) can validate or set the version field without // needing a separate accessor function. MetadataVersion = "1.0" )
Variables ¶
var ( // UnwrappableFields are numeric fields that can be used with | unwrap in // metric queries. The discover tool issues series queries for each field to // find streams that expose these values. UnwrappableFields = []string{ "bytes", "duration", "duration_ms", "offset", "partition", "rows_affected", "size", "spans", "status", "streams", "ttl", } // FilterableKeywords are literal strings commonly appearing in log content. // Used for line filter queries like |= "level" or |~ "error". The discover // tool tests keyword presence per stream to populate ByKeyword in the output // metadata. FilterableKeywords = []string{ "debug", "duration", "error", "failed", "level", "refused", } // StructuredMetadataKeys are keys that appear as structured metadata // attached to log entries (not as stream labels). The discover tool uses // detected_fields responses to find streams that carry these keys. // Note: detected_level lives here (not in LabelKeys) because it is // injected by Loki as structured metadata, not as an indexed stream label. StructuredMetadataKeys = []string{ "detected_level", "pod", } // LabelKeys are indexed stream labels used for selectors and grouping // (by/without). The discover tool issues one series query per key with // matcher {key=~".+"} to enumerate streams. LabelKeys = []string{ "cluster", "container", "level", "namespace", "pod", "service_name", } )
Bounded sets: characteristics common to all datasets These define the set of possible queries and drive targeted series API queries during stream discovery. Each exported variable corresponds to a discovery query dimension used by the discover CLI.
Functions ¶
func CalculateMinRanges ¶ added in v3.7.0
func CalculateMinRanges(config *GeneratorConfig) (minRange, minInstantRange time.Duration)
CalculateMinRanges computes the minimum range durations needed for range and instant queries based on the log generation rate for a stream.
MinRange: For range queries that sample multiple points over time - Formula: time needed for 5 samples (with 10-100 logs per sample)
MinInstantRange: For instant queries that sample at a single point in time - Formula: time needed for 10 logs (to ensure capture at single sampling point)
TODO: This function is specific to the generated data. We will need to expand on this concept when parsing real datasets. For the generated data, the algorithm is based on the following: - baseEntries: 10-100 entries per stream (average ~55) - timeSpread: configured time span over which logs are distributed - logRate: baseEntries / timeSpread (logs per second)
func SaveConfig ¶
func SaveConfig(dataDir string, config *GeneratorConfig) error
SaveConfig saves the generator configuration to a file in the data directory
func SaveMetadata ¶ added in v3.7.0
func SaveMetadata(dataDir string, metadata *DatasetMetadata) error
SaveMetadata writes metadata to a JSON file in the specified directory
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder helps construct test datasets using multiple stores
func NewBuilder ¶
NewBuilder creates a new Builder
type ChunkStore ¶
type ChunkStore struct {
// contains filtered or unexported fields
}
func NewChunkStore ¶
func NewChunkStore(dir, tenantID string) (*ChunkStore, error)
func NewChunkStoreWithRegisterer ¶ added in v3.7.0
func NewChunkStoreWithRegisterer(dir, tenantID string, reg prometheus.Registerer) (*ChunkStore, error)
func (*ChunkStore) Close ¶
func (s *ChunkStore) Close() error
Close flushes any remaining data and closes resources
type DataObjStore ¶
type DataObjStore struct {
// contains filtered or unexported fields
}
DataObjStore implements Store using the dataobj format
func NewDataObjStore ¶
func NewDataObjStore(dir, tenant string) (*DataObjStore, error)
NewDataObjStore creates a new DataObjStore
func (*DataObjStore) Close ¶
func (s *DataObjStore) Close() error
Close flushes any remaining data and closes resources
type DataObjV2EngineStore ¶ added in v3.6.0
type DataObjV2EngineStore struct {
// contains filtered or unexported fields
}
DataObjV2EngineStore uses the new engine for querying. It assumes the engine can read the "new dataobj format" (e.g. columnar data) from the provided dataDir via a filesystem objstore.Bucket.
func NewDataObjV2EngineStore ¶ added in v3.6.0
func NewDataObjV2EngineStore(dir string, tenantID string) (*DataObjV2EngineStore, error)
NewDataObjV2EngineStore creates a new store that uses the v2 dataobj engine.
type DatasetMetadata ¶ added in v3.7.0
type DatasetMetadata struct {
AllSelectors []string `json:"all_selectors"`
ByFormat map[LogFormat][]string `json:"by_format"`
ByServiceName map[string][]string `json:"by_service_name"`
Statistics DatasetStatistics `json:"statistics"`
TimeRange TimeRange `json:"time_range"`
Version string `json:"version"`
ByUnwrappableField map[string][]string `json:"by_unwrappable_field"` // field name -> selectors with that field
ByDetectedField map[string][]string `json:"by_detected_field"` // parsable field -> selectors with that field
ByStructuredMetadata map[string][]string `json:"by_structured_metadata"` // metadata key -> selectors with that key
ByLabelKey map[string][]string `json:"by_label_key"` // label name -> selectors with that label
ByKeyword map[string][]string `json:"by_keyword"` // keyword -> selectors containing that keyword
MetadataBySelector map[string]*SerializableStreamMetadata `json:"metadata_by_selector"` // selector -> stream metadata for range resolution
}
DatasetMetadata contains queryable information about a generated dataset It maps query properties to stream/label patterns
func BuildMetadata ¶ added in v3.7.0
func BuildMetadata(config *GeneratorConfig, streamsMeta []StreamMetadata) *DatasetMetadata
BuildMetadata constructs dataset metadata from stream metadata This is called during data generation to create the metadata file
NOTE: Currently uses helper functions (getUnwrappableFields, etc.) that hardcode application knowledge. This is a temporary approach for synthetic datasets. See TODO comments on helper functions for refactoring plan to support real datasets.
func GenerateInMemoryMetadata ¶ added in v3.7.0
func GenerateInMemoryMetadata(config *GeneratorConfig) *DatasetMetadata
GenerateInMemoryMetadata creates metadata in memory without file I/O This is useful for tests that need metadata but don't want to generate a full dataset
func LoadMetadata ¶ added in v3.7.0
func LoadMetadata(dataDir string) (*DatasetMetadata, error)
LoadMetadata reads metadata from a JSON file in the specified directory
type DatasetStatistics ¶ added in v3.7.0
type DatasetStatistics struct {
Generated time.Time `json:"generated"`
StreamsByFormat map[LogFormat]int `json:"streams_by_format"`
StreamsByService map[string]int `json:"streams_by_service"`
TotalStreams int `json:"total_streams"`
}
DatasetStatistics provides aggregate information about the dataset
type DenseInterval ¶
DenseInterval represents a period of high log volume
type Faker ¶
type Faker struct {
// contains filtered or unexported fields
}
Faker provides methods to generate fake data consistently
func (*Faker) AuthAction ¶
AuthAction returns a random authentication action
func (*Faker) AuthSuccess ¶
AuthSuccess returns a random authentication success status
func (*Faker) CacheError ¶
CacheError returns a random cache error
func (*Faker) ErrorMessage ¶
ErrorMessage returns a random error message
func (*Faker) GRPCMethod ¶
GRPCMethod returns a random gRPC method
func (*Faker) GrafanaComponent ¶
GrafanaComponent returns a random Grafana component
func (*Faker) GrafanaLogger ¶
GrafanaLogger returns a random Grafana logger
func (*Faker) GrafanaMessage ¶
GrafanaMessage returns a random Grafana message
func (*Faker) K8sComponent ¶
K8sComponent returns a random Kubernetes component
func (*Faker) K8sLogPrefix ¶
K8sLogPrefix returns a random Kubernetes log prefix
func (*Faker) K8sMessage ¶
K8sMessage returns a random Kubernetes message
func (*Faker) KafkaError ¶
KafkaError returns a random Kafka error
func (*Faker) KafkaEvent ¶
KafkaEvent returns a random Kafka event
func (*Faker) KafkaOffset ¶
KafkaOffset returns a random Kafka offset
func (*Faker) KafkaPartition ¶
KafkaPartition returns a random Kafka partition
func (*Faker) KafkaTopic ¶
KafkaTopic returns a random Kafka topic
func (*Faker) NginxErrorType ¶
NginxErrorType returns a random nginx error type
func (*Faker) PrometheusComponent ¶
PrometheusComponent returns a random Prometheus component
func (*Faker) PrometheusMessage ¶
PrometheusMessage returns a random Prometheus message
func (*Faker) PrometheusSubcomponent ¶
PrometheusSubcomponent returns a random Prometheus subcomponent
func (*Faker) RowsAffected ¶
RowsAffected returns a random number of rows affected
func (*Faker) SyslogPriority ¶
SyslogPriority returns a random syslog priority
func (*Faker) TempoComponent ¶
TempoComponent returns a random Tempo component
func (*Faker) TempoMessage ¶
TempoMessage returns a random Tempo message
type Generator ¶
type Generator struct {
StreamsMeta []StreamMetadata // Pre-generated stream metadata used across batches
// contains filtered or unexported fields
}
Generator represents a log generator with configuration
func NewGenerator ¶
NewGenerator creates a new generator with the given options
type GeneratorConfig ¶
type GeneratorConfig struct {
StartTime time.Time
TimeSpread time.Duration
// DenseIntervals defines periods of high log density
// Each interval will have 10x more logs than normal periods
DenseIntervals []DenseInterval
LabelConfig LabelConfig
NumStreams int // Number of streams to generate per batch
Seed int64 // Source of randomness
}
GeneratorConfig contains all configuration for the log generator
func LoadConfig ¶
func LoadConfig(dataDir string) (*GeneratorConfig, error)
LoadConfig loads the generator configuration from the data directory
func (*GeneratorConfig) NewRand ¶
func (c *GeneratorConfig) NewRand() *rand.Rand
NewRand creates a new random source using the configured seed
type K6TestCase ¶ added in v3.7.0
type K6TestCase struct {
Name string `json:"name"`
Query string `json:"query"`
TenantID int `json:"tenantId"`
Start string `json:"start"`
End string `json:"end"`
Step string `json:"step"`
Direction string `json:"direction"`
Kind string `json:"kind"`
Source string `json:"source"`
}
K6TestCase represents a test case in the format consumed by the k6 test runner.
func ConvertTestCaseToK6 ¶ added in v3.7.0
func ConvertTestCaseToK6(tc TestCase, tenantID int, length time.Duration, buffer time.Duration) K6TestCase
ConvertTestCaseToK6 converts a resolved TestCase into the k6 JSON format. length is the query window duration from the template's TimeRangeConfig. buffer is how far from "now" the query window ends.
type LabelConfig ¶
type LabelConfig struct {
Clusters int // 1-10 clusters
Namespaces int // 10-100 namespaces
Services int // 100-1000 services
Pods int // 1000-10000 pods
Containers int // 1-5 containers per pod
LogLevels []string // Log levels to use
EnvTypes []string // Environment types
Regions []string // Regions
Datacenters []string // Datacenters
}
LabelConfig configures the cardinality of generated labels
type LogFormat ¶ added in v3.7.0
type LogFormat string
LogFormat represents the format of logs produced by an application
type LogGenerator ¶
LogGenerator is a function that generates a log line
type MetadataVariableResolver ¶ added in v3.7.0
type MetadataVariableResolver struct {
// contains filtered or unexported fields
}
MetadataVariableResolver resolves variables based on dataset metadata It uses multi-dimensional filtering to ensure queries match compatible streams
func NewMetadataVariableResolver ¶ added in v3.7.0
func NewMetadataVariableResolver(metadata *DatasetMetadata, seed int64) *MetadataVariableResolver
NewMetadataVariableResolver creates a new resolver from dataset metadata
func (*MetadataVariableResolver) GetTimeRange ¶ added in v3.7.0
func (r *MetadataVariableResolver) GetTimeRange(length time.Duration) (start, end time.Time, err error)
GetTimeRange returns the start and end time for a query based on the metadata time range
func (*MetadataVariableResolver) ResolveQuery ¶ added in v3.7.0
func (r *MetadataVariableResolver) ResolveQuery(query string, requirements QueryRequirements, isInstant bool) (string, error)
ResolveQuery resolves variables in a query based on requirements Supports: ${SELECTOR}, ${LABEL_NAME}, ${LABEL_VALUE}, ${RANGE} The isInstant parameter determines whether to use MinInstantRange (true) or MinRange (false) for ${RANGE}
type OTELAttributes ¶
type OTELAttributes struct {
Resource map[string]string // Resource attributes constant for the service
Trace *OTELTraceContext // Optional trace context
}
OTELAttributes represents OpenTelemetry attributes for logs
type OTELTraceContext ¶
OTELTraceContext represents OpenTelemetry trace context
type Opt ¶
type Opt struct {
// contains filtered or unexported fields
}
Opt represents configuration options for the generator
func (Opt) WithDenseInterval ¶
WithDenseInterval adds a dense interval to the configuration
func (Opt) WithLabelCardinality ¶
WithLabelCardinality configures the cardinality of different labels
func (Opt) WithLabelConfig ¶
func (o Opt) WithLabelConfig(cfg LabelConfig) Opt
WithLabelConfig sets the entire label configuration
func (Opt) WithNumStreams ¶
WithNumStreams sets the number of streams to generate per batch
func (Opt) WithStartTime ¶
WithStartTime sets the start time for log generation
type QueryDefinition ¶ added in v3.7.0
type QueryDefinition struct {
Description string `yaml:"description"`
Query string `yaml:"query"`
Kind string `yaml:"kind,omitempty"` // "log" or "metric"
Skip bool `yaml:"skip,omitempty"`
TimeRange TimeRangeConfig `yaml:"time_range"`
Directions QueryDirection `yaml:"directions,omitempty"`
Requires QueryRequirements `yaml:"requires,omitempty"` // Requirements for stream selection
Tags []string `yaml:"tags,omitempty"`
Notes string `yaml:"notes,omitempty"`
Source string `yaml:"-"` // Source location (suite/file.yaml:line), populated during load
}
QueryDefinition represents a single query definition from the registry
type QueryDirection ¶ added in v3.7.0
type QueryDirection string
QueryDirection specifies which direction(s) to run a log query
const ( DirectionForward QueryDirection = "forward" DirectionBackward QueryDirection = "backward" DirectionBoth QueryDirection = "both" )
type QueryFile ¶ added in v3.7.0
type QueryFile struct {
Queries []QueryDefinition `yaml:"queries"`
}
QueryFile represents a YAML file containing query definitions
type QueryRegistry ¶ added in v3.7.0
type QueryRegistry struct {
// contains filtered or unexported fields
}
QueryRegistry manages loading and accessing query definitions
func NewQueryRegistry ¶ added in v3.7.0
func NewQueryRegistry(baseDir string) *QueryRegistry
NewQueryRegistry creates a new query registry
func (*QueryRegistry) ExpandQuery ¶ added in v3.7.0
func (r *QueryRegistry) ExpandQuery(def QueryDefinition, resolver VariableResolver, isInstant bool) ([]TestCase, error)
ExpandQuery expands a query definition into one or more TestCase instances by resolving variables and creating cases for each direction
func (*QueryRegistry) GetQueries ¶ added in v3.7.0
func (r *QueryRegistry) GetQueries(includeSkipped bool, suites ...Suite) []QueryDefinition
GetQueries returns all loaded queries for the specified suites If suites is empty, returns all queries If includeSkipped is false, skipped queries are filtered out
func (*QueryRegistry) Load ¶ added in v3.7.0
func (r *QueryRegistry) Load(suites ...Suite) error
Load loads all query definitions for the specified suites
type QueryRequirements ¶ added in v3.7.0
type QueryRequirements struct {
LogFormat string `yaml:"log_format,omitempty"` // "json", "logfmt", or "unstructured"
UnwrappableFields []string `yaml:"unwrappable_fields,omitempty"` // Numeric fields needed for | unwrap
StructuredMetadata []string `yaml:"structured_metadata,omitempty"` // Structured metadata keys needed
DetectedFields []string `yaml:"detected_fields,omitempty"` // Fields that must be parsable from log content (for aggregations/filters)
Labels []string `yaml:"labels,omitempty"` // Stream label keys needed (for selectors, filters, or grouping)
Keywords []string `yaml:"keywords,omitempty"` // Strings that must appear in log content
}
QueryRequirements specifies what characteristics a stream must have for a query to work
type SerializableStreamMetadata ¶ added in v3.7.0
type SerializableStreamMetadata struct {
MinRange time.Duration `json:"min_range"`
MinInstantRange time.Duration `json:"min_instant_range"`
}
SerializableStreamMetadata contains only the fields needed for query resolution This is a subset of StreamMetadata that can be safely serialized to JSON
type Service ¶ added in v3.7.0
type Service struct {
Name string
Format LogFormat // Log format: json, logfmt, or unstructured
LogGenerator LogGenerator
OTELResource map[string]string // OTEL resource attributes
}
Service represents a type of application that generates logs
type Store ¶
type Store interface {
// Write writes a batch of streams to the store
Write(ctx context.Context, streams []logproto.Stream) error
// Name returns the name of the store implementation
Name() string
// Close flushes any remaining data and closes resources
Close() error
}
Store represents a storage backend for log data
type StreamMetadata ¶
type StreamMetadata struct {
Labels string
Service Service
Format LogFormat // Log format for this stream
// MinRange is the minimum lookback range for range queries to capture multiple samples
MinRange time.Duration
// MinInstantRange is the minimum lookback range for instant queries to capture logs at a single sampling point
MinInstantRange time.Duration
}
StreamMetadata holds the consistent properties of a stream
type TestCase ¶
type TestCase struct {
Query string
Start time.Time
End time.Time
Direction logproto.Direction
Step time.Duration // Step size for metric queries
Source string // Source location (suite/file.yaml:line)
QueryDesc string // Query description from YAML
Tags []string
}
TestCase represents a LogQL test case for benchmarking and testing
func (TestCase) Description ¶
Description returns a detailed description of the test case including time range
func (TestCase) Equal ¶ added in v3.7.0
Equal returns true if two TestCases represent the same query execution.
type TimeRangeConfig ¶ added in v3.7.0
type TimeRangeConfig struct {
// Length is the duration the query should cover (end - start)
Length string `yaml:"length"`
// Step is the step size for metric queries
Step string `yaml:"step,omitempty"`
}
TimeRangeConfig defines the time range parameters for a query
func (*TimeRangeConfig) ParseLength ¶ added in v3.7.0
func (t *TimeRangeConfig) ParseLength() (time.Duration, error)
ParseLength parses the length string into a time.Duration
type VariableResolver ¶ added in v3.7.0
type VariableResolver interface {
// ResolveQuery resolves variables in a query based on requirements
// The isInstant parameter determines whether to use MinInstantRange (true) or MinRange (false) for ${RANGE}
ResolveQuery(query string, requirements QueryRequirements, isInstant bool) (string, error)
// GetTimeRange returns the start and end time for a query based on its time range config
GetTimeRange(length time.Duration) (start, end time.Time, err error)
}
VariableResolver is responsible for resolving query variables
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
bench
command
|
|
|
correctness-metrics
command
|
|
|
generate
command
|
|
|
generate-k6
command
|
|
|
stream
command
|
|
|
discover
|
|
|
cmd
command
|
|