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 ¶
- func Options(cfg Config) (*clickhouse.Options, error)
- func ValidateDBName(name string) error
- type Client
- func (c *Client) Close() error
- func (c *Client) InsertEvents(ctx context.Context, batch []events.Envelope) error
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) QueryDashboardSummary(ctx context.Context) (*DashboardSummary, error)
- func (c *Client) QueryEventTypes(ctx context.Context) ([]EventTypeStat, error)
- func (c *Client) QueryEvents(ctx context.Context, limit, offset int) ([]EventRow, error)
- func (c *Client) QueryEventsFiltered(ctx context.Context, filters EventFilters) ([]EventRow, error)
- func (c *Client) QuerySources(ctx context.Context) ([]SourceStat, error)
- func (c *Client) QueryStats(ctx context.Context) (uint64, error)
- type Config
- type DashboardSummary
- type EventFilters
- type EventRow
- type EventTypeStat
- type RowScanner
- type SourceStat
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 ¶
ValidateDBName validates ClickHouse database name format.
Types ¶
type Client ¶
type Client struct {
Conn clickhouse.Conn
DBName string
}
Client wraps a ClickHouse connection.
func (*Client) InsertEvents ¶
InsertEvents stores a batch of platform event envelopes.
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 ¶
QueryEvents returns events from ClickHouse with limit and offset.
func (*Client) QueryEventsFiltered ¶
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.
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 ¶
EventTypeStat represents event counts by event type.
type RowScanner ¶
RowScanner abstracts row scanning for testability.
type SourceStat ¶
SourceStat represents event counts by source.