Documentation
¶
Overview ¶
Package ch provides a ClickHouse connection utility.
Index ¶
- Constants
- Variables
- func ConnectLoop(ctx context.Context, dsn string, connTimeout time.Duration, ...) (conn driver.Conn, closeFunc func() error, err error)
- type ClickHouseTestInstance
- type ClickhouseStore
- func (s *ClickhouseStore) CalculateEvents(ctx context.Context, c *warnly.ListIssueMetricsCriteria) ([]warnly.EventsPerHour, error)
- func (s *ClickhouseStore) CalculateEventsPerDay(ctx context.Context, c *warnly.EventDefCriteria) ([]warnly.EventPerDay, error)
- func (s *ClickhouseStore) CalculateFields(ctx context.Context, c warnly.FieldsCriteria) ([]warnly.TagCount, error)
- func (s *ClickhouseStore) Close() error
- func (s *ClickhouseStore) CountEvents(ctx context.Context, criteria *warnly.EventCriteria) (uint64, error)
- func (s *ClickhouseStore) CountFields(ctx context.Context, c *warnly.EventDefCriteria) ([]warnly.FieldValueNum, error)
- func (c *ClickhouseStore) EnableAsyncInsertWait()
- func (s *ClickhouseStore) GetEventPagination(ctx context.Context, c *warnly.EventPaginationCriteria) (*warnly.EventPagination, error)
- func (s *ClickhouseStore) GetFilteredGroupIDs(ctx context.Context, tokens []warnly.QueryToken, from, to time.Time, ...) ([]int64, error)
- func (s *ClickhouseStore) GetIssueEvent(ctx context.Context, c *warnly.EventDefCriteria) (*warnly.IssueEvent, error)
- func (s *ClickhouseStore) ListErrors(ctx context.Context, c warnly.ListErrorsCriteria) ([]warnly.AnalyticsStoreErr, error)
- func (s *ClickhouseStore) ListEvents(ctx context.Context, criteria *warnly.EventCriteria) ([]warnly.EventEntry, error)
- func (s *ClickhouseStore) ListFieldFilters(ctx context.Context, criteria *warnly.FieldFilterCriteria) ([]warnly.Filter, error)
- func (s *ClickhouseStore) ListIssueMetrics(ctx context.Context, c *warnly.ListIssueMetricsCriteria) ([]warnly.IssueMetrics, error)
- func (s *ClickhouseStore) ListPopularTags(ctx context.Context, c *warnly.ListPopularTagsCriteria) ([]warnly.TagCount, error)
- func (s *ClickhouseStore) ListSchemas(ctx context.Context) ([]warnly.Schema, error)
- func (s *ClickhouseStore) ListSlowQueries(ctx context.Context) ([]warnly.SQLQuery, error)
- func (s *ClickhouseStore) ListTagValues(ctx context.Context, c *warnly.ListTagValuesCriteria) ([]warnly.TagValueCount, error)
- func (s *ClickhouseStore) StoreEvent(ctx context.Context, ev *warnly.EventClickhouse) error
Constants ¶
const DefaultTimeout = 5 * time.Second
Variables ¶
var ApproxTime = cmp.Options{cmpopts.EquateApproxTime(1 * time.Second)}
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 ¶
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 ¶
func (s *ClickhouseStore) CalculateEvents( ctx context.Context, c *warnly.ListIssueMetricsCriteria, ) ([]warnly.EventsPerHour, error)
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 ¶
func (s *ClickhouseStore) CountFields(ctx context.Context, c *warnly.EventDefCriteria) ([]warnly.FieldValueNum, error)
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
func (s *ClickhouseStore) GetEventPagination( ctx context.Context, c *warnly.EventPaginationCriteria, ) (*warnly.EventPagination, error)
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 ¶
func (s *ClickhouseStore) GetIssueEvent(ctx context.Context, c *warnly.EventDefCriteria) (*warnly.IssueEvent, error)
GetIssueEvent retrieves a single event associated with a specific issue and project within a given time range.
func (*ClickhouseStore) ListErrors ¶
func (s *ClickhouseStore) ListErrors(ctx context.Context, c warnly.ListErrorsCriteria) ([]warnly.AnalyticsStoreErr, error)
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 ¶
func (s *ClickhouseStore) ListIssueMetrics( ctx context.Context, c *warnly.ListIssueMetricsCriteria, ) ([]warnly.IssueMetrics, error)
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 ¶
ListSchemas lists olap database schemas from largest to smallest.
func (*ClickhouseStore) ListSlowQueries ¶
ListSlowQueries lists slow SQL queries from the olap system and their statistics.
func (*ClickhouseStore) ListTagValues ¶
func (s *ClickhouseStore) ListTagValues( ctx context.Context, c *warnly.ListTagValuesCriteria, ) ([]warnly.TagValueCount, error)
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.