clickhouse

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultClusterName = "default"

DefaultClusterName is the cluster the scrapper reads system tables through when the configuration does not name one. ClickHouse Cloud always defines it.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClickhouseQueryLogSchema added in v0.5.0

type ClickhouseQueryLogSchema struct {
	QueryType                  string    `db:"type"`
	EventTimeMicroseconds      time.Time `db:"event_time_microseconds"`
	QueryStartTimeMicroseconds time.Time `db:"query_start_time_microseconds"`

	// Performance Information
	QueryDurationMs  uint64 `db:"query_duration_ms"`
	PeakThreadsUsage uint64 `db:"peak_threads_usage"`

	// IO Information
	ReadRows  uint64 `db:"read_rows"`
	ReadBytes uint64 `db:"read_bytes"`

	WrittenRows  uint64 `db:"written_rows"`
	WrittenBytes uint64 `db:"written_bytes"`

	ResultRows  uint64 `db:"result_rows"`
	ResultBytes uint64 `db:"result_bytes"`

	// Query Information
	MemoryUsage            uint64   `db:"memory_usage"`
	CurrentDatabase        string   `db:"current_database"`
	Query                  string   `db:"normalized_query"`
	NormalizedQueryHash    uint64   `db:"normalized_query_hash"`
	QueryKind              string   `db:"query_kind"`
	Databases              []string `db:"databases"`
	Tables                 []string `db:"tables"`
	Columns                []string `db:"columns"`
	Partitions             []string `db:"partitions"`
	Projections            []string `db:"projections"`
	Views                  []string `db:"views"`
	UsedFunctions          []string `db:"used_functions"`
	UsedAggregateFunctions []string `db:"used_aggregate_functions"`
	ExceptionCode          int32    `db:"exception_code"`
	Exception              string   `db:"exception"`
	StackTrace             string   `db:"stack_trace"`

	// Server Information
	Hostname string `db:"hostname"`

	// Client Information
	InitialUser                       string    `db:"initial_user"`
	InitialQueryId                    string    `db:"initial_query_id"`
	InitialAddress                    *net.IP   `db:"initial_address"`
	InitialPort                       uint16    `db:"initial_port"`
	InitialQueryStartTimeMicroseconds time.Time `db:"initial_query_start_time_microseconds"`
	OsUser                            string    `db:"os_user"`
	ClientHostname                    string    `db:"client_hostname"`
	ClientName                        string    `db:"client_name"`
	ClientRevision                    uint32    `db:"client_revision"`
	ClientRevisionMajor               uint32    `db:"client_version_major"`
	ClientRevisionMinor               uint32    `db:"client_version_minor"`
	ClientRevisionPatch               uint32    `db:"client_version_patch"`
	DistributedDepth                  uint64    `db:"distributed_depth"`

	// HTTP Client Information
	HttpMethod    uint8  `db:"http_method"`
	HttpUserAgent string `db:"http_user_agent"`
	HttpReferer   string `db:"http_referer"`
	ForwardedFor  string `db:"forwarded_for"`

	// Script Information
	ScriptQueryNumber uint32 `db:"script_query_number"`
	ScriptLineNumber  uint32 `db:"script_line_number"`

	// The log_comment setting the query ran with. dwhsupport's own executor sends
	// the query context there instead of in a SQL comment.
	LogComment string `db:"log_comment"`
}

type ClickhouseScrapper

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

func NewClickhouseScrapper

func NewClickhouseScrapper(ctx context.Context, conf ClickhouseScrapperConf) (*ClickhouseScrapper, error)

func (*ClickhouseScrapper) Capabilities added in v0.10.6

func (e *ClickhouseScrapper) Capabilities() scrapper.Capabilities

func (*ClickhouseScrapper) Close

func (e *ClickhouseScrapper) Close() error

func (*ClickhouseScrapper) DialectType added in v0.1.8

func (e *ClickhouseScrapper) DialectType() string

func (*ClickhouseScrapper) EstimateQuery added in v0.16.0

func (e *ClickhouseScrapper) EstimateQuery(ctx context.Context, sql string) (*scrapper.QueryEstimate, error)

EstimateQuery returns a row estimate via `EXPLAIN ESTIMATE`, which reports the parts/rows/marks the planner expects to read per table without executing the query. Bytes are not available from this plan, so only Rows is populated. The estimate is planner-based and depends on up-to-date part metadata.

func (*ClickhouseScrapper) Executor

func (*ClickhouseScrapper) FetchQueryLogs added in v0.5.0

func (s *ClickhouseScrapper) FetchQueryLogs(
	ctx context.Context,
	from, to time.Time,
	obfuscator querylogs.QueryObfuscator,
) (querylogs.QueryLogIterator, error)

func (*ClickhouseScrapper) IsPermissionError added in v0.1.1

func (e *ClickhouseScrapper) IsPermissionError(err error) bool

func (*ClickhouseScrapper) QueryCatalog

func (e *ClickhouseScrapper) QueryCatalog(ctx context.Context) ([]*scrapper.CatalogColumnRow, error)

func (*ClickhouseScrapper) QueryCustomMetrics

func (e *ClickhouseScrapper) QueryCustomMetrics(ctx context.Context, sql string, args ...any) ([]*scrapper.CustomMetricsRow, error)

func (*ClickhouseScrapper) QueryDatabases

func (e *ClickhouseScrapper) QueryDatabases(ctx context.Context) ([]*scrapper.DatabaseRow, error)

func (*ClickhouseScrapper) QueryPlatformUsers added in v0.21.0

func (e *ClickhouseScrapper) QueryPlatformUsers(ctx context.Context) (*scrapper.PlatformUsers, error)

QueryPlatformUsers lists system.users with the roles granted to each user (system.role_grants) and, where the server keeps a session log, their last login. ClickHouse states no user type, email, display name, comment or creation time, so those are always skipped.

Nothing a grant or the server version decides fails the call: a refused system.users is a refused source, one this server lacks an unavailable one, and a refused or missing role or session log read only skips that fact. When the cluster fan-out is refused (no READ ON REMOTE) or the cluster is not defined, the connected node is read alone and the listing says so.

Otherwise the listing is complete: system.users is either refused or lists every user, there is no partial view of it.

func (*ClickhouseScrapper) QueryRoutines added in v0.23.0

func (e *ClickhouseScrapper) QueryRoutines(ctx context.Context) ([]*scrapper.RoutineRow, error)

func (*ClickhouseScrapper) QuerySchemas added in v0.14.5

func (e *ClickhouseScrapper) QuerySchemas(ctx context.Context) ([]*scrapper.SchemaRow, error)

QuerySchemas lists ClickHouse databases as schemas. ClickHouse has no catalog/database level above its databases, so each ClickHouse database is mapped to a SchemaRow under the connection's own identity — see rowIdentity, which every scrapped row shares.

func (*ClickhouseScrapper) QuerySegments

func (e *ClickhouseScrapper) QuerySegments(ctx context.Context, sql string, args ...any) ([]*scrapper.SegmentRow, error)

func (*ClickhouseScrapper) QueryShape added in v0.8.3

func (e *ClickhouseScrapper) QueryShape(ctx context.Context, sql string) ([]*scrapper.QueryShapeColumn, error)

func (*ClickhouseScrapper) QuerySqlDefinitions

func (e *ClickhouseScrapper) QuerySqlDefinitions(ctx context.Context) ([]*scrapper.SqlDefinitionRow, error)

func (*ClickhouseScrapper) QueryTableConstraints added in v0.9.0

func (e *ClickhouseScrapper) QueryTableConstraints(ctx context.Context) ([]*scrapper.TableConstraintRow, error)

func (*ClickhouseScrapper) QueryTableMetrics

func (e *ClickhouseScrapper) QueryTableMetrics(ctx context.Context, lastMetricsFetchTime time.Time) ([]*scrapper.TableMetricsRow, error)

func (*ClickhouseScrapper) QueryTables

func (*ClickhouseScrapper) RunRawQuery added in v0.13.7

func (*ClickhouseScrapper) SqlDialect added in v0.1.8

func (e *ClickhouseScrapper) SqlDialect() sqldialect.Dialect

func (*ClickhouseScrapper) ValidateConfiguration

func (e *ClickhouseScrapper) ValidateConfiguration(ctx context.Context) ([]string, error)

ValidateConfiguration reports a configured cluster this server does not have, which is the difference between the warehouse owner learning about it here and learning about it as a CLUSTER_DOESNT_EXIST on the first catalog fetch.

type ClickhouseScrapperConf

type ClickhouseScrapperConf struct {
	dwhexecclickhouse.ClickhouseConf
	// InstanceName is the name this ClickHouse is published under. ClickHouse has
	// no container above a database, so something has to name the service itself;
	// empty leaves that to the connection host. It is not a database and does not
	// restrict what is scraped.
	InstanceName string
	// Cluster selects how system tables are read. See ClusterConf.
	Cluster ClusterConf
}

type ClusterConf added in v0.16.3

type ClusterConf struct {
	// SingleNode reads system tables directly on the connected node instead of
	// fanning out across a cluster. It is the only thing that works on an install
	// whose remote_servers defines no cluster, and it removes the need for the
	// REMOTE privilege — but on an install that does have replicas it reports the
	// metadata of one node, so it has to be chosen deliberately rather than
	// inherited from an unset field.
	SingleNode bool
	// Name is the cluster passed to clusterAllReplicas. Empty means
	// DefaultClusterName. Ignored when SingleNode is set.
	Name string
}

ClusterConf selects how the scrapper reads ClickHouse system tables.

The zero value fans out with clusterAllReplicas(DefaultClusterName, …): system tables are per-node, so a metadata read has to see every replica rather than whichever one answered.

func (ClusterConf) Validate added in v0.16.3

func (c ClusterConf) Validate() error

Jump to

Keyboard shortcuts

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