Documentation
¶
Overview ¶
Package chstorage provides Clickhouse-based storage.
Index ¶
- Constants
- Variables
- func DecodeUnicodeLabel(v string) string
- type Attributes
- type AttributesOption
- type Backup
- type BucketedSampleQuery
- type ClickHouseClient
- type ClickhouseOptimizer
- type Column
- type Columns
- type DialOptions
- type IncompatibleSchemaError
- type InputNode
- type Inserter
- type InserterOptions
- type LogsQuery
- type LogsSelector
- type MetricsCacheOptions
- type MigrationDiff
- type MigrationStatus
- type Migrator
- func (m *Migrator) Create(ctx context.Context) error
- func (m *Migrator) Diff(ctx context.Context) ([]MigrationDiff, error)
- func (m *Migrator) Drop(ctx context.Context, log func(database, table string)) error
- func (m *Migrator) DropIfExists(ctx context.Context, log func(database, table string)) error
- func (m *Migrator) Validate(ctx context.Context) error
- type MigratorOptions
- type Querier
- func (q *Querier) Capabilities() (caps logqlengine.QuerierCapabilities)
- func (q *Querier) DetectedFields(ctx context.Context, opts logstorage.LabelsOptions) (values []logstorage.DetectedField, rerr error)
- func (q *Querier) DetectedLabels(ctx context.Context, opts logstorage.LabelsOptions) (values []logstorage.DetectedLabel, rerr error)
- func (q *Querier) ExemplarQuerier(ctx context.Context) (storage.ExemplarQuerier, error)
- func (q *Querier) LabelNames(ctx context.Context, opts logstorage.LabelsOptions) (result []string, rerr error)
- func (q *Querier) LabelValues(ctx context.Context, labelName string, opts logstorage.LabelsOptions) (riter iterators.Iterator[logstorage.Label], rerr error)
- func (q *Querier) MetricMetadata(ctx context.Context, opts metricstorage.MetadataParams) (metricstorage.Metadata, error)
- func (q *Querier) MetricsScanners() (enginestorage.Scanners, error)
- func (q *Querier) Querier(mint, maxt int64) (storage.Querier, error)
- func (q *Querier) Query(ctx context.Context, labels []logql.LabelMatcher) (logqlengine.PipelineNode, error)
- func (q *Querier) SearchTags(ctx context.Context, tags map[string]string, ...) (_ iterators.Iterator[tracestorage.Span], rerr error)
- func (q *Querier) SelectSpansets(ctx context.Context, params traceqlengine.SelectSpansetsParams) (_ iterators.Iterator[traceqlengine.Trace], rerr error)
- func (q *Querier) Series(ctx context.Context, opts logstorage.SeriesOptions) (result logstorage.Series, rerr error)
- func (q *Querier) TagNames(ctx context.Context, opts tracestorage.TagNamesOptions) (r []tracestorage.TagName, rerr error)
- func (q *Querier) TagValues(ctx context.Context, tag traceql.Attribute, opts tracestorage.TagValuesOptions) (_ iterators.Iterator[tracestorage.Tag], rerr error)
- func (q *Querier) TraceByID(ctx context.Context, id otelstorage.TraceID, ...) (_ iterators.Iterator[tracestorage.Span], rerr error)
- type QuerierOptions
- type Restore
- type SampleQuery
- type SamplingNode
- func (n *SamplingNode) EvalBucketedSample(ctx context.Context, params logqlengine.EvalParams, window time.Duration) (logqlengine.StepIterator, error)
- func (n *SamplingNode) EvalSample(ctx context.Context, params logqlengine.EvalParams) (logqlengine.SampleIterator, error)
- func (n *SamplingNode) Traverse(cb logqlengine.NodeVisitor) error
- type SamplingOp
- type Tables
Constants ¶
const ( // MigrationUnknown is an unknown migration status. MigrationUnknown = MigrationStatus(iota) // MigrationDelete indicates that table should be removed in the new version. MigrationDelete // MigrationCreate indicates that table should be created in the new version. MigrationCreate // MigrationUpgrade indicates that table should be changed in the new version. MigrationUpgrade // MigrationOK indicates that table does not require any changes. MigrationOK )
Variables ¶
var ErrLogsResultTooLarge = errors.New("sample query result is too large")
ErrLogsResultTooLarge means that ClickHouse aborted a sample query because its result exceeded the configured byte limit.
var ErrLogsTooManySamples = errors.New("too many log lines requested for sampling")
ErrLogsTooManySamples means that a LogQL sample query (e.g. count_over_time, rate, bytes_over_time) matched more log rows than allowed.
var ErrMetricsTooManySeries = errors.New("too many timeseries requested")
ErrMetricsTooManySeries whether if query requested more timeseries than allowed.
Functions ¶
func DecodeUnicodeLabel ¶
DecodeUnicodeLabel tries to decode U__k8s_2e_node_2e_name into k8s.node.name. It decodes any hex-encoded character in the format _XX_ where XX is a two-digit hex value.
Types ¶
type Attributes ¶
type Attributes struct {
Name string
Value proto.ColumnOf[otelstorage.Attrs]
}
func NewAttributes ¶
func NewAttributes(name string, opts ...AttributesOption) *Attributes
NewAttributes constructs a new Attributes storage representation.
func (*Attributes) Append ¶
func (a *Attributes) Append(kv otelstorage.Attrs)
Append adds a new map of attributes.
func (*Attributes) Columns ¶
func (a *Attributes) Columns() Columns
Columns returns a slice of Columns for this attribute set.
func (*Attributes) DDL ¶
func (a *Attributes) DDL(table *ddl.Table)
DDL applies the schema changes to the table.
func (*Attributes) Row ¶
func (a *Attributes) Row(idx int) otelstorage.Attrs
Row returns a new map of attributes for a given row.
type AttributesOption ¶
type AttributesOption func(*attributesOptions)
func WithLowCardinality ¶
func WithLowCardinality(v bool) AttributesOption
type Backup ¶
type Backup struct {
// contains filtered or unexported fields
}
Backup implements a oteldb backup process.
Backup is stored in a Clickhouse Native format.
type BucketedSampleQuery ¶
type BucketedSampleQuery struct {
// Start, End define the output step range.
Start, End time.Time
// Step is the output resolution. If <= 0 (instant query), a single
// bucket covering (End-Range, End] is produced.
Step time.Duration
// Range is the range-aggregation window, e.g. the `[5m]` in
// count_over_time({...}[5m]).
Range time.Duration
Sel LogsSelector
Sampling SamplingOp
// GroupingLabels must be non-empty: this query only makes sense for the
// sum/avg/min/max by(...) (...) shape the optimizer already requires
// before offloading to it (see querier_logs_optimizer.go).
GroupingLabels []logql.Label
}
BucketedSampleQuery defines a sample query that aggregates samples per output step directly in ClickHouse, instead of fetching one row per raw log line for logqlmetric.RangeAggregation (range_agg.go) to bucket in Go. It implements the same step-bucketing math as the PromQL rate/increase/delta offload (see querier_metrics_rate.go and chsql_stepfanout.go), without the counter-reset detection tier rate needs — log sample values (line counts, byte lengths) are not counters.
func (*BucketedSampleQuery) Execute ¶
func (v *BucketedSampleQuery) Execute(ctx context.Context, q *Querier) (_ logqlmetric.StepIterator, rerr error)
Execute executes the query using given querier.
type ClickHouseClient ¶
type ClickHouseClient interface {
Do(ctx context.Context, q ch.Query) error
Ping(ctx context.Context) error
}
func Dial ¶
func Dial(ctx context.Context, dsn string, opts DialOptions) (ClickHouseClient, error)
Dial creates new ClickHouseClient using given DSN.
func NewDialingClickhouseClient ¶
func NewDialingClickhouseClient(options ch.Options) ClickHouseClient
type ClickhouseOptimizer ¶
type ClickhouseOptimizer struct{}
ClickhouseOptimizer replaces LogQL engine execution nodes with optimzied Clickhouse queries.
func (*ClickhouseOptimizer) Name ¶
func (o *ClickhouseOptimizer) Name() string
Name returns optimizer name.
func (*ClickhouseOptimizer) Optimize ¶
func (o *ClickhouseOptimizer) Optimize(ctx context.Context, q logqlengine.Query) (logqlengine.Query, error)
Optimize implements [Optimizer].
type Columns ¶
type Columns []Column
Columns is a set of Columns.
func MergeColumns ¶
MergeColumns merges multiple sets of columns into one.
func (Columns) All ¶
All returns comma-separated column names for using in SELECT query instead of `SELECT *`.
func (Columns) ChsqlResult ¶
func (c Columns) ChsqlResult() []chsql.ResultColumn
ChsqlResult returns columns for using in SELECT query.
type DialOptions ¶
type DialOptions struct {
// MeterProvider provides OpenTelemetry meter for pool.
MeterProvider metric.MeterProvider
// TracerProvider provides OpenTelemetry tracer for pool.
TracerProvider trace.TracerProvider
// Logger provides logger for pool.
Logger *zap.Logger
}
DialOptions is Dial function options.
type IncompatibleSchemaError ¶
type IncompatibleSchemaError struct {
Table string
}
IncompatibleSchemaError is returned when there is an existing table with incompatible schema.
func (*IncompatibleSchemaError) Error ¶
func (e *IncompatibleSchemaError) Error() string
IncompatibleSchemaError implements [error].
type InputNode ¶
type InputNode struct {
Sel LogsSelector
// contains filtered or unexported fields
}
InputNode rebuilds LogQL pipeline in as Clickhouse query.
func (*InputNode) EvalPipeline ¶
func (n *InputNode) EvalPipeline(ctx context.Context, params logqlengine.EvalParams) (logqlengine.EntryIterator, error)
EvalPipeline implements logqlengine.PipelineNode.
func (*InputNode) Traverse ¶
func (n *InputNode) Traverse(cb logqlengine.NodeVisitor) error
Traverse implements logqlengine.Node.
type Inserter ¶
type Inserter struct {
// contains filtered or unexported fields
}
Inserter implements tracestorage.Inserter using Clickhouse.
func NewInserter ¶
func NewInserter(c ClickHouseClient, opts InserterOptions) (*Inserter, error)
NewInserter creates new Inserter.
func (*Inserter) ConsumeMetrics ¶
ConsumeMetrics inserts given metrics.
func (*Inserter) RecordWriter ¶
func (i *Inserter) RecordWriter(ctx context.Context) (logstorage.RecordWriter, error)
RecordWriter returns a new logstorage.RecordWriter
func (*Inserter) SpanWriter ¶
func (i *Inserter) SpanWriter(ctx context.Context) (tracestorage.SpanWriter, error)
SpanWriter returns a new tracestorage.SpanWriter
type InserterOptions ¶
type InserterOptions struct {
// Tables provides table paths to query.
Tables Tables
// CHLogLevel sets log level for ch-go.
CHLogLevel zapcore.LevelEnabler
// MeterProvider provides OpenTelemetry meter for this querier.
MeterProvider metric.MeterProvider
// TracerProvider provides OpenTelemetry tracer for this querier.
TracerProvider trace.TracerProvider
// Tracker provides global metric tracker.
Tracker globalmetric.Tracker
}
InserterOptions is Inserter's options.
type LogsQuery ¶
type LogsQuery[E any] struct { Start, End time.Time Sel LogsSelector Direction logqlengine.Direction Limit int Mapper func(logstorage.Record) (E, error) }
LogsQuery defines a logs query.
type LogsSelector ¶
type LogsSelector struct {
Labels []logql.LabelMatcher
Line []logql.LineFilter
PipelineLabels []logql.LabelPredicate
}
LogsSelector defines common parameters for logs selection.
type MetricsCacheOptions ¶
type MetricsCacheOptions = metricscache.Options
MetricsCacheOptions is an alias for metricscache.Options.
type MigrationDiff ¶
type MigrationDiff struct {
Table string
Diff string
Status MigrationStatus
}
MigrationDiff is result of comparison of existing table and latest schema version.
type MigrationStatus ¶
type MigrationStatus uint8
MigrationStatus defines status of table.
func (MigrationStatus) ColorString ¶
func (s MigrationStatus) ColorString() string
ColorString returns colored string representation.
func (MigrationStatus) String ¶
func (s MigrationStatus) String() string
String implements fmt.Stringer.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator provides migration tool for oteldb.
func NewMigrator ¶
func NewMigrator(client ClickHouseClient, opts MigratorOptions) *Migrator
NewMigrator creates new Migrator.
func (*Migrator) Diff ¶
func (m *Migrator) Diff(ctx context.Context) ([]MigrationDiff, error)
Diff returns a difference of current schema and latest schema.
func (*Migrator) DropIfExists ¶
DropIfExists drops all known existing tables. This will remove data.
type MigratorOptions ¶
type MigratorOptions struct {
Tables Tables
Cluster string
KeeperPathPrefix string
TTL time.Duration
Replicated bool
}
MigratorOptions defines migration options.
func (*MigratorOptions) AddFlags ¶
func (o *MigratorOptions) AddFlags(fs *pflag.FlagSet)
AddFlags registers command-line flags for migrator options.
type Querier ¶
type Querier struct {
// contains filtered or unexported fields
}
Querier implements tracestorage.Querier using Clickhouse.
func NewQuerier ¶
func NewQuerier(c ClickHouseClient, opts QuerierOptions) (*Querier, error)
NewQuerier creates new Querier.
func (*Querier) Capabilities ¶
func (q *Querier) Capabilities() (caps logqlengine.QuerierCapabilities)
Capabilities implements logqlengine.Querier.
func (*Querier) DetectedFields ¶
func (q *Querier) DetectedFields(ctx context.Context, opts logstorage.LabelsOptions) (values []logstorage.DetectedField, rerr error)
DetectedFields implements logstorage.Querier.
func (*Querier) DetectedLabels ¶
func (q *Querier) DetectedLabels(ctx context.Context, opts logstorage.LabelsOptions) (values []logstorage.DetectedLabel, rerr error)
DetectedLabels implements logstorage.Querier.
func (*Querier) ExemplarQuerier ¶
Querier returns a new Querier on the storage.
func (*Querier) LabelNames ¶
func (q *Querier) LabelNames(ctx context.Context, opts logstorage.LabelsOptions) (result []string, rerr error)
LabelNames implements logstorage.Querier.
func (*Querier) LabelValues ¶
func (q *Querier) LabelValues(ctx context.Context, labelName string, opts logstorage.LabelsOptions) (riter iterators.Iterator[logstorage.Label], rerr error)
LabelValues implements logstorage.Querier.
func (*Querier) MetricMetadata ¶
func (q *Querier) MetricMetadata(ctx context.Context, opts metricstorage.MetadataParams) (metricstorage.Metadata, error)
MetricMetadata returns metric metadata for the given options.
func (*Querier) MetricsScanners ¶
func (q *Querier) MetricsScanners() (enginestorage.Scanners, error)
MetricsScanners returns scanners implementation to use with thanos-io PromQL engine.
func (*Querier) Querier ¶
Querier returns a new metrics storage.Querier.
func (*Querier) Query ¶
func (q *Querier) Query(ctx context.Context, labels []logql.LabelMatcher) (logqlengine.PipelineNode, error)
Query creates new InputNode.
func (*Querier) SearchTags ¶
func (q *Querier) SearchTags(ctx context.Context, tags map[string]string, opts tracestorage.SearchTagsOptions) (_ iterators.Iterator[tracestorage.Span], rerr error)
SearchTags performs search by given tags.
func (*Querier) SelectSpansets ¶
func (q *Querier) SelectSpansets(ctx context.Context, params traceqlengine.SelectSpansetsParams) (_ iterators.Iterator[traceqlengine.Trace], rerr error)
SelectSpansets get spansets from storage.
func (*Querier) Series ¶
func (q *Querier) Series(ctx context.Context, opts logstorage.SeriesOptions) (result logstorage.Series, rerr error)
Series returns all available log series.
func (*Querier) TagNames ¶
func (q *Querier) TagNames(ctx context.Context, opts tracestorage.TagNamesOptions) (r []tracestorage.TagName, rerr error)
TagNames returns all available tag names.
func (*Querier) TagValues ¶
func (q *Querier) TagValues(ctx context.Context, tag traceql.Attribute, opts tracestorage.TagValuesOptions) (_ iterators.Iterator[tracestorage.Tag], rerr error)
TagValues returns all available tag values for given tag.
func (*Querier) TraceByID ¶
func (q *Querier) TraceByID(ctx context.Context, id otelstorage.TraceID, opts tracestorage.TraceByIDOptions) (_ iterators.Iterator[tracestorage.Span], rerr error)
TraceByID returns spans of given trace.
type QuerierOptions ¶
type QuerierOptions struct {
// Tables provides table paths to query.
Tables Tables
// LabelLimit defines limit for label lookup in the main table.
LabelLimit int
// MetricSeriesLimit defines limit for total number of series requested by the query.
MetricSeriesLimit int
// MetricExemplarsLimit defines limit for total number of exemplars returned by a single query.
MetricExemplarsLimit int
// MaxResultRows defines max number of rows to read from ClickHouse.
MaxResultRows int
// MaxResultBytes defines max number of bytes to read from ClickHouse.
MaxResultBytes int
// MaxExecutionTime defines max execution time for ClickHouse query.
MaxExecutionTime time.Duration
// MaxSampleRows defines max number of log rows a LogQL sample query
// (e.g. count_over_time, rate, bytes_over_time) is allowed to fetch.
MaxSampleRows int
// MaxSampleResultBytes defines max number of result bytes a LogQL sample
// query is allowed to fetch from ClickHouse (max_result_bytes override).
MaxSampleResultBytes int
// DisableRateOffloading disables rate/increase/delta/etc. offloading to ClickHouse.
DisableRateOffloading bool
// DisableMetricOffloading disables all metric offloading to ClickHouse.
DisableMetricOffloading bool
// MetricsCacheOptions configures metrics cache.
MetricsCacheOptions MetricsCacheOptions
// CHLogLevel sets log level for ch-go.
CHLogLevel zapcore.LevelEnabler
// MeterProvider provides OpenTelemetry meter for this querier.
MeterProvider metric.MeterProvider
// TracerProvider provides OpenTelemetry tracer for this querier.
TracerProvider trace.TracerProvider
// Tracker tracks global metrics.
Tracker globalmetric.Tracker
}
QuerierOptions is Querier's options.
type Restore ¶
type Restore struct {
// contains filtered or unexported fields
}
Restore implements a oteldb restore process.
Restore is stored in a Clickhouse native format.
func NewRestore ¶
func NewRestore(client ClickHouseClient, tables Tables, logger *zap.Logger) *Restore
NewRestore creates a new Restore instance.
type SampleQuery ¶
type SampleQuery struct {
Start, End time.Time
Sel LogsSelector
Sampling SamplingOp
GroupingLabels []logql.Label
}
SampleQuery defines a sample query.
func (*SampleQuery) Execute ¶
func (v *SampleQuery) Execute(ctx context.Context, q *Querier) (_ logqlengine.SampleIterator, rerr error)
Execute executes the query using given querier.
type SamplingNode ¶
type SamplingNode struct {
Sel LogsSelector
Sampling SamplingOp
GroupingLabels []logql.Label
// contains filtered or unexported fields
}
SamplingNode is a logqlengine.SampleNode, which offloads sampling to Clickhouse
func (*SamplingNode) EvalBucketedSample ¶
func (n *SamplingNode) EvalBucketedSample( ctx context.Context, params logqlengine.EvalParams, window time.Duration, ) (logqlengine.StepIterator, error)
EvalBucketedSample implements logqlengine.BucketedSampleNode.
func (*SamplingNode) EvalSample ¶
func (n *SamplingNode) EvalSample(ctx context.Context, params logqlengine.EvalParams) (logqlengine.SampleIterator, error)
EvalSample implements logqlengine.SampleNode.
func (*SamplingNode) Traverse ¶
func (n *SamplingNode) Traverse(cb logqlengine.NodeVisitor) error
Traverse implements logqlengine.Node.
type SamplingOp ¶
type SamplingOp int
SamplingOp defines a sampler operation.
const ( // CountSampling counts lines. CountSampling SamplingOp = iota + 1 // BytesSampling counts line lengths in bytes. BytesSampling )
Source Files
¶
- attributes.go
- attributes_json.go
- backup.go
- backup_logs.go
- backup_metrics.go
- backup_traces.go
- chsql_stepfanout.go
- chstorage.go
- clickhouse.go
- col_simple_agg_func.go
- columns.go
- columns_logs.go
- columns_metrics.go
- columns_migration.go
- columns_traces.go
- dial.go
- inserter.go
- inserter_logs.go
- inserter_metrics.go
- inserter_totals.go
- inserter_traces.go
- metrics_cache.go
- migrate.go
- querier.go
- querier_logs.go
- querier_logs_node.go
- querier_logs_optimizer.go
- querier_logs_query.go
- querier_metrics.go
- querier_metrics_cache.go
- querier_metrics_exemplars.go
- querier_metrics_hist.go
- querier_metrics_labels.go
- querier_metrics_metadata.go
- querier_metrics_points.go
- querier_metrics_rate.go
- querier_metrics_scanners.go
- querier_metrics_series.go
- querier_metrics_timeseries.go
- querier_traces.go
- restore.go
- restore_logs.go
- restore_metrics.go
- restore_traces.go
- schema.go
- schema_metrics.go
- schema_traces.go