ch

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package ch provides a ClickHouse connection utility.

Index

Constants

View Source
const DefaultTimeout = 5 * time.Second

Variables

ApproxTime is a compare helper for clock skew.

Functions

func ConnectLoop

func ConnectLoop(
	ctx context.Context,
	dsn string,
	connTimeout time.Duration,
	logger *slog.Logger,
) (conn driver.Conn, closeFunc func() error, err error)

ConnectLoop tries to connect to ClickHouse with retries until the defaultTimeout is reached. It returns the connection and a close function to close the connection pool.

Types

type ClickHouseTestInstance

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

ClickHouseTestInstance is a wrapper around the Docker-based database instance.

func MustTestInstance

func MustTestInstance() *ClickHouseTestInstance

MustTestInstance is NewTestInstance, except it prints errors to stderr and calls os.Exit when finished.

func NewTestInstance

func NewTestInstance() (*ClickHouseTestInstance, error)

NewTestInstance creates a new Docker-based ClickHouse instance. It creates an initial database, runs the migrations, and sets that database as a template.

func (*ClickHouseTestInstance) Close

func (i *ClickHouseTestInstance) Close() (retErr error)

Close terminates the test database instance, cleaning up any resources.

func (*ClickHouseTestInstance) MustClose

func (i *ClickHouseTestInstance) MustClose()

MustClose is like Close except it prints the error to stderr and calls os.Exit.

func (*ClickHouseTestInstance) NewDatabase

func (i *ClickHouseTestInstance) NewDatabase(tb testing.TB) (driver.Conn, string)

NewDatabase creates a new database suitable for use in testing. It returns an established database connection (driver.Conn) and the DSN.

type ClickhouseStore

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

ClickhouseStore encapsulates clickhouse connection.

func NewClickhouseStore

func NewClickhouseStore(conn clickhouse.Conn, tracerProvider svcotel.TracerProvider) *ClickhouseStore

NewClickhouseStore creates a new ClickhouseStore.

func (*ClickhouseStore) CalculateEvents

CalculateEvents calculates the number of events per day split by hour.

func (*ClickhouseStore) CalculateEventsPerDay

func (s *ClickhouseStore) CalculateEventsPerDay(ctx context.Context, c *warnly.EventDefCriteria) ([]warnly.EventPerDay, error)

CalculateEventsPerDay calculates the number of events per day for a given group and project within a specified time range.

func (*ClickhouseStore) CalculateFields

func (s *ClickhouseStore) CalculateFields(ctx context.Context, c warnly.FieldsCriteria) ([]warnly.TagCount, error)

CalculateFields calculates the number of occurrences of each field for a given issue identifier and project within a specified time range.

func (*ClickhouseStore) Close

func (s *ClickhouseStore) Close() error

Close closes the connection to Clickhouse.

func (*ClickhouseStore) CountEvents

func (s *ClickhouseStore) CountEvents(ctx context.Context, criteria *warnly.EventCriteria) (uint64, error)

CountEvents returns the number of events for a given project and issue.

func (*ClickhouseStore) CountFields

CountFields counts additional fields for a given issue and project within a specified time range.

func (*ClickhouseStore) EnableAsyncInsertWait

func (c *ClickhouseStore) EnableAsyncInsertWait()

func (*ClickhouseStore) GetEventPagination added in v0.5.0

GetEventPagination returns the pagination for an event.

func (*ClickhouseStore) GetFilteredGroupIDs

func (s *ClickhouseStore) GetFilteredGroupIDs(
	ctx context.Context,
	tokens []warnly.QueryToken,
	from, to time.Time,
	projectIDs []int,
) ([]int64, error)

GetFilteredGroupIDs returns group IDs that match the query filters.

func (*ClickhouseStore) GetIssueEvent

GetIssueEvent retrieves a single event associated with a specific issue and project within a given time range.

func (*ClickhouseStore) ListErrors

ListErrors lists recent errors from the olap system for the last 24 hours.

func (*ClickhouseStore) ListEvents

func (s *ClickhouseStore) ListEvents(ctx context.Context, criteria *warnly.EventCriteria) ([]warnly.EventEntry, error)

ListEvents lists error events per issue based on the given criteria.

func (*ClickhouseStore) ListFieldFilters

func (s *ClickhouseStore) ListFieldFilters(
	ctx context.Context,
	criteria *warnly.FieldFilterCriteria,
) ([]warnly.Filter, error)

ListFieldFilters lists field filters for a given set of project IDs.

func (*ClickhouseStore) ListIssueMetrics

ListIssueMetrics lists issue metrics for the given project IDs and issue IDs within the specified time range. It displays how many times each issue was seen, when it was first and last seen, and the number of unique users affected.

func (*ClickhouseStore) ListPopularTags

func (s *ClickhouseStore) ListPopularTags(
	ctx context.Context,
	c *warnly.ListPopularTagsCriteria,
) ([]warnly.TagCount, error)

ListPopularTags lists popular tag keys across all events in the given time range and projects.

func (*ClickhouseStore) ListSchemas

func (s *ClickhouseStore) ListSchemas(ctx context.Context) ([]warnly.Schema, error)

ListSchemas lists olap database schemas from largest to smallest.

func (*ClickhouseStore) ListSlowQueries

func (s *ClickhouseStore) ListSlowQueries(ctx context.Context) ([]warnly.SQLQuery, error)

ListSlowQueries lists slow SQL queries from the olap system and their statistics.

func (*ClickhouseStore) ListTagValues

ListTagValues lists popular values for a given tag in the specified time range and projects.

func (*ClickhouseStore) StoreEvent

func (s *ClickhouseStore) StoreEvent(ctx context.Context, ev *warnly.EventClickhouse) error

StoreEvent stores an event in the analytics database.

Jump to

Keyboard shortcuts

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