clickhouse

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColName       = "name"
	ColSampleType = "sample_type"
	ColSampleUnit = "sample_unit"
	ColPeriodType = "period_type"
	ColPeriodUnit = "period_unit"
	ColPeriod     = "period"
	ColDuration   = "duration"
	ColTimestamp  = "timestamp"
	ColTimeNanos  = "time_nanos"
	ColValue      = "value"
	ColLabels     = "labels"

	// Stacktrace nested columns.
	ColStacktraceAddress            = "stacktrace.address"
	ColStacktraceMappingStart       = "stacktrace.mapping_start"
	ColStacktraceMappingLimit       = "stacktrace.mapping_limit"
	ColStacktraceMappingOffset      = "stacktrace.mapping_offset"
	ColStacktraceMappingFile        = "stacktrace.mapping_file"
	ColStacktraceMappingBuildID     = "stacktrace.mapping_build_id"
	ColStacktraceLineNumber         = "stacktrace.line_number"
	ColStacktraceFunctionName       = "stacktrace.function_name"
	ColStacktraceFunctionSystemName = "stacktrace.function_system_name"
	ColStacktraceFunctionFilename   = "stacktrace.function_filename"
	ColStacktraceFunctionStartLine  = "stacktrace.function_start_line"
)

Column names matching the profile schema.

Variables

This section is empty.

Functions

func BuildWhereClause

func BuildWhereClause(conditions []string, allArgs []interface{}) (string, []interface{})

BuildWhereClause combines multiple filter conditions into a single WHERE clause.

func CreateTableSQL

func CreateTableSQL(database, table string) string

CreateTableSQL returns the SQL statement to create the profile data table. The schema uses: - JSON type for dynamic labels (native ClickHouse support for dynamic columns). - Nested type for stacktrace data with explicit columns for each location field.

func InsertSQL

func InsertSQL(database, table string) string

InsertSQL returns the SQL statement for inserting data into the table.

func LabelMatchersToSQL

func LabelMatchersToSQL(matchers []*labels.Matcher) (string, []interface{}, error)

LabelMatchersToSQL converts Prometheus label matchers to SQL WHERE clause conditions.

func ProfileTypeFilter

func ProfileTypeFilter(qp profile.QueryParts) (string, []interface{})

ProfileTypeFilter generates SQL WHERE clause conditions for profile type filtering.

func QueryToFilters

func QueryToFilters(query string, startNanos, endNanos int64) (string, []interface{}, profile.QueryParts, error)

QueryToFilters converts a query string and time range to SQL filter components.

func TimeRangeFilter

func TimeRangeFilter(startNanos, endNanos int64) (string, []interface{})

TimeRangeFilter generates SQL WHERE clause conditions for time range filtering.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a wrapper around the ClickHouse connection.

func NewClient

func NewClient(ctx context.Context, cfg Config) (*Client, error)

NewClient creates a new ClickHouse client with the given configuration. It first connects without a database to ensure the database can be created, then reconnects with the database specified.

func (*Client) Close

func (c *Client) Close() error

Close closes the ClickHouse connection.

func (*Client) Config

func (c *Client) Config() Config

Config returns the client configuration.

func (*Client) Conn

func (c *Client) Conn() driver.Conn

Conn returns the underlying ClickHouse connection.

func (*Client) Database

func (c *Client) Database() string

Database returns the database name.

func (*Client) EnsureSchema

func (c *Client) EnsureSchema(ctx context.Context) error

EnsureSchema creates the table if it doesn't exist. Note: The database is already created in NewClient.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, query string, args ...interface{}) error

Exec executes a query without returning rows.

func (*Client) FullTableName

func (c *Client) FullTableName() string

FullTableName returns the fully qualified table name (database.table).

func (*Client) PrepareBatch

func (c *Client) PrepareBatch(ctx context.Context, query string) (driver.Batch, error)

PrepareBatch prepares a batch for insertion.

func (*Client) Query

func (c *Client) Query(ctx context.Context, query string, args ...interface{}) (driver.Rows, error)

Query executes a query and returns the rows.

func (*Client) Table

func (c *Client) Table() string

Table returns the table name.

type Config

type Config struct {
	Address  string
	Database string
	Username string
	Password string
	Table    string
	Secure   bool
}

Config holds ClickHouse connection configuration.

type Ingester

type Ingester struct {
	// contains filtered or unexported fields
}

Ingester implements the ingester.Ingester interface for ClickHouse.

func NewIngester

func NewIngester(logger log.Logger, client *Client) *Ingester

NewIngester creates a new ClickHouse ingester.

func (*Ingester) Ingest

func (i *Ingester) Ingest(ctx context.Context, record arrow.RecordBatch) error

Ingest implements the ingester.Ingester interface. It converts Arrow records to ClickHouse batch inserts.

type LineInfo

type LineInfo struct {
	LineNumber         int64
	FunctionStartLine  int64
	FunctionName       string
	FunctionSystemName string
	FunctionFilename   string
}

LineInfo holds decoded line/function information from an encoded location.

type Querier

type Querier struct {
	// contains filtered or unexported fields
}

Querier implements the query.Querier interface for ClickHouse.

func NewQuerier

func NewQuerier(
	client *Client,
	logger log.Logger,
	tracer trace.Tracer,
	mem memory.Allocator,
	sym symbolizer.SymbolizationClient,
) *Querier

NewQuerier creates a new ClickHouse querier.

func (*Querier) GetProfileMetadataLabels

func (q *Querier) GetProfileMetadataLabels(
	ctx context.Context,
	query string,
	start, end time.Time,
) ([]string, error)

GetProfileMetadataLabels returns unique label names for the given query.

func (*Querier) GetProfileMetadataMappings

func (q *Querier) GetProfileMetadataMappings(
	ctx context.Context,
	query string,
	start, end time.Time,
) ([]string, error)

GetProfileMetadataMappings returns unique mapping files for the given query.

func (*Querier) HasProfileData

func (q *Querier) HasProfileData(ctx context.Context) (bool, error)

HasProfileData checks if there is any profile data in the store.

func (*Querier) Labels

func (q *Querier) Labels(
	ctx context.Context,
	match []string,
	start, end time.Time,
	profileType string,
) ([]string, error)

Labels returns the unique label names within the given time range.

func (*Querier) ProfileTypes

func (q *Querier) ProfileTypes(
	ctx context.Context,
	start, end time.Time,
) ([]*pb.ProfileType, error)

ProfileTypes returns the available profile types within the given time range.

func (*Querier) QueryMerge

func (q *Querier) QueryMerge(
	ctx context.Context,
	query string,
	start, end time.Time,
	aggregateByLabels []string,
	invertCallStacks bool,
	functionToFilterBy string,
) (profile.Profile, error)

QueryMerge executes a merge query over a time range.

func (*Querier) QueryRange

func (q *Querier) QueryRange(
	ctx context.Context,
	query string,
	startTime, endTime time.Time,
	step time.Duration,
	limit uint32,
	sumBy []string,
) ([]*pb.MetricsSeries, error)

QueryRange executes a range query and returns time series data. It aggregates samples by timestamp bucket and labels in ClickHouse, returning one row per unique labelset with an array of time series samples.

func (*Querier) QuerySingle

func (q *Querier) QuerySingle(
	ctx context.Context,
	query string,
	t time.Time,
	invertCallStacks bool,
) (profile.Profile, error)

QuerySingle executes a point query for a single timestamp.

func (*Querier) Values

func (q *Querier) Values(
	ctx context.Context,
	labelName string,
	match []string,
	start, end time.Time,
	profileType string,
) ([]string, error)

Values returns the unique values for a given label name.

type StacktraceData

type StacktraceData struct {
	Addresses           []uint64
	MappingStarts       []uint64
	MappingLimits       []uint64
	MappingOffsets      []uint64
	MappingFiles        []string
	MappingBuildIDs     []string
	LineNumbers         []int64
	FunctionNames       []string
	FunctionSystemNames []string
	FunctionFilenames   []string
	FunctionStartLines  []int64
}

StacktraceData holds the extracted stacktrace information for a single sample.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL