clickhouse

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package clickhouse is the analytics store client: connection setup, the event model and the dashboard queries.

It builds a ClickHouse connection from Config (address, database, optional TLS through transport/tlsconfig), validates database names, and exposes the event row model, EventFilters and the dashboard and event-type queries used by analytics-api, the processor and the runtime API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Options

func Options(cfg Config) (*clickhouse.Options, error)

Options is shared by every native ClickHouse caller so direct driver users cannot accidentally omit configured analytics transport encryption.

func ValidateDBName

func ValidateDBName(name string) error

ValidateDBName validates ClickHouse database name format.

Types

type Client

type Client struct {
	Conn   clickhouse.Conn
	DBName string
}

Client wraps a ClickHouse connection.

func NewClient

func NewClient(cfg Config) (*Client, error)

NewClient creates a new ClickHouse client.

func (*Client) Close

func (c *Client) Close() error

Close closes the ClickHouse connection.

func (*Client) InsertEvents

func (c *Client) InsertEvents(ctx context.Context, batch []events.Envelope) error

InsertEvents stores a batch of platform event envelopes.

func (*Client) Ping

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

Ping checks the database connection.

func (*Client) QueryDashboardSummary

func (c *Client) QueryDashboardSummary(ctx context.Context) (*DashboardSummary, error)

QueryDashboardSummary returns summary statistics for the dashboard.

func (*Client) QueryEventTypes

func (c *Client) QueryEventTypes(ctx context.Context) ([]EventTypeStat, error)

QueryEventTypes returns event counts grouped by event type.

func (*Client) QueryEvents

func (c *Client) QueryEvents(ctx context.Context, limit, offset int) ([]EventRow, error)

QueryEvents returns events from ClickHouse with limit and offset.

func (*Client) QueryEventsFiltered

func (c *Client) QueryEventsFiltered(ctx context.Context, filters EventFilters) ([]EventRow, error)

QueryEventsFiltered returns events filtered by various fields.

func (*Client) QuerySources

func (c *Client) QuerySources(ctx context.Context) ([]SourceStat, error)

QuerySources returns event counts grouped by source.

func (*Client) QueryStats

func (c *Client) QueryStats(ctx context.Context) (uint64, error)

QueryStats returns total event count.

type Config

type Config struct {
	Addr        string
	Database    string
	DialTimeout time.Duration
	TLS         *tls.Config
	Username    string
	Password    string
}

Config provides ClickHouse connection configuration.

type DashboardSummary

type DashboardSummary struct {
	TotalEvents    uint64 `json:"total_events"`
	ActiveServers  int    `json:"active_servers"`
	ActiveGrants   int    `json:"active_grants"`
	ActiveSessions int    `json:"active_sessions"`
	LatestSource   string `json:"latest_source"`
	LastEventType  string `json:"last_event_type"`
	LastEventTime  string `json:"last_event_time,omitempty"`
}

DashboardSummary provides overview statistics for the dashboard.

type EventFilters

type EventFilters struct {
	TraceID                 string
	Source                  string
	EventType               string
	Server                  string
	ServerUID               string
	Namespace               string
	TeamID                  string
	SubjectTeamID           string
	ResourceTeamID          string
	Cluster                 string
	HumanID                 string
	AgentID                 string
	SessionID               string
	Decision                string
	ToolName                string
	Reason                  string
	MatchedGrant            string
	MatchedGrantNamespace   string
	MatchedSession          string
	MatchedSessionNamespace string
	Since                   time.Time
	Until                   time.Time
	Limit                   int
	Offset                  int
}

EventFilters provides filtering options for events.

type EventRow

type EventRow struct {
	Timestamp time.Time `json:"timestamp"`
	TraceID   string    `json:"trace_id,omitempty"`
	Source    string    `json:"source"`
	EventType string    `json:"event_type"`
	Server    string    `json:"server,omitempty"`
	Namespace string    `json:"namespace,omitempty"`
	// TeamID retains its existing resource authority meaning.
	TeamID         string          `json:"team_id,omitempty"`
	SubjectTeamID  string          `json:"subject_team_id,omitempty"`
	ResourceTeamID string          `json:"resource_team_id,omitempty"`
	Cluster        string          `json:"cluster,omitempty"`
	HumanID        string          `json:"human_id,omitempty"`
	AgentID        string          `json:"agent_id,omitempty"`
	SessionID      string          `json:"session_id,omitempty"`
	Decision       string          `json:"decision,omitempty"`
	ToolName       string          `json:"tool_name,omitempty"`
	Payload        json.RawMessage `json:"payload"`
}

EventRow represents a single event from ClickHouse.

type EventTypeStat

type EventTypeStat struct {
	EventType string `json:"event_type"`
	Count     uint64 `json:"count"`
}

EventTypeStat represents event counts by event type.

type RowScanner

type RowScanner interface {
	Scan(dest ...any) error
}

RowScanner abstracts row scanning for testability.

type SourceStat

type SourceStat struct {
	Source string `json:"source"`
	Count  uint64 `json:"count"`
}

SourceStat represents event counts by source.

Jump to

Keyboard shortcuts

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