Documentation
¶
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) Conn() driver.Conn
- func (c *Client) Empty(ctx context.Context) (bool, error)
- func (c *Client) EnsureSchema(ctx context.Context) error
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) QuerySummary(ctx context.Context, params domain.SummaryParams) ([]domain.SummaryRow, bool, error)
- func (c *Client) QueryUsageByMeta(ctx context.Context, params domain.MetaUsageParams) ([]domain.MetaUsageRow, bool, error)
- type Config
- type Outbox
- type Replicator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client manages ClickHouse connections and analytical queries.
func (*Client) EnsureSchema ¶
EnsureSchema applies any pending embedded migrations in sequential order.
func (*Client) QuerySummary ¶
func (c *Client) QuerySummary(ctx context.Context, params domain.SummaryParams) ([]domain.SummaryRow, bool, error)
QuerySummary executes multi-dimensional analytical aggregations on ClickHouse.
func (*Client) QueryUsageByMeta ¶
func (c *Client) QueryUsageByMeta(ctx context.Context, params domain.MetaUsageParams) ([]domain.MetaUsageRow, bool, error)
QueryUsageByMeta aggregates token usage by meta key/value filtering.
type Outbox ¶
type Outbox interface {
ClaimOutbox(ctx context.Context, owner uuid.UUID, limit int, lease time.Duration) (repository.OutboxBatch, []*domain.UsageEvent, error)
RenewOutbox(ctx context.Context, owner, batch uuid.UUID, lease time.Duration) (bool, error)
AckOutbox(ctx context.Context, batch uuid.UUID) error
RetryOutboxLater(ctx context.Context, owner, batch uuid.UUID, delay time.Duration) (bool, error)
}
Outbox is the Postgres side: events written there in the same statement as the event itself, leased out in batches until ClickHouse has them.
type Replicator ¶
type Replicator struct {
// contains filtered or unexported fields
}
Replicator copies events from the Postgres outbox to ClickHouse. Nothing is held only in memory: while ClickHouse is down the outbox grows, and a restart resumes where it stopped.
func NewReplicator ¶
func NewReplicator(outbox Outbox, conn driver.Conn, batchSize int, interval time.Duration) *Replicator
NewReplicator copies up to batchSize events per insert, checking the outbox every interval.
func (*Replicator) Close ¶
func (r *Replicator) Close()
Close stops the loop. A batch it was copying stays leased in the outbox and is copied, without duplicates, by whoever claims it once the lease ends.
func (*Replicator) Start ¶
func (r *Replicator) Start()