Documentation
¶
Overview ¶
Package postgresql provides a PostgreSQL-backed archival store for completed AgentRun resources. The operator's AgentRunReconciler snapshots terminal-phase runs here so the UI can display historical runs beyond the lifetime of the live Kubernetes CRDs (which may be garbage-collected by the controller's retention policy).
Index ¶
- Constants
- func IsTerminalPhase(phase agentorcav1alpha1.AgentRunPhase) bool
- type HistoryPage
- type HistoryQuery
- type HistoryResult
- type RunArchive
- type Store
- func (s *Store) ApplyMigration(ctx context.Context) error
- func (s *Store) ArchiveRun(ctx context.Context, run *agentorcav1alpha1.AgentRun, traceEventsJSON []byte) error
- func (s *Store) Close() error
- func (s *Store) GetRun(ctx context.Context, namespace, name string) (*RunArchive, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) QueryHistory(ctx context.Context, q HistoryQuery) (*HistoryPage, error)
Constants ¶
const MigrationSQL = `` /* 2308-byte string literal not displayed */
MigrationSQL is the SQL used to create/alter the archival schema. Applied at operator startup.
Variables ¶
This section is empty.
Functions ¶
func IsTerminalPhase ¶
func IsTerminalPhase(phase agentorcav1alpha1.AgentRunPhase) bool
IsTerminalPhase reports whether the given AgentRun phase is terminal.
Types ¶
type HistoryPage ¶
type HistoryPage struct {
Runs []HistoryResult `json:"runs"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
HistoryPage is the paginated response for run history queries.
type HistoryQuery ¶
type HistoryQuery struct {
// Limit caps the number of results (default 50, clamped to [1, 200]).
Limit int
// Offset is the number of rows to skip (for pagination).
Offset int
// Phase filters by AgentRun phase (e.g. "Succeeded", "Failed"). Empty = all.
Phase string
// AgentRef filters by the agent name referenced by the run.
AgentRef string
// Namespaces restricts results to the given namespaces (typically a tenant's
// authorized set). Empty = all namespaces (only meaningful when the caller has
// cluster-wide access).
Namespaces []string
// Search matches against the run name case-insensitively.
Search string
}
HistoryQuery holds filter/sort/pagination parameters for run history lookups.
type HistoryResult ¶
type HistoryResult struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
AgentRef string `json:"agentRef"`
Phase string `json:"phase"`
SpendUSD string `json:"spendUSD"`
StartTime *time.Time `json:"startTime,omitempty"`
CompletionTime *time.Time `json:"completionTime,omitempty"`
Tenant string `json:"tenant,omitempty"`
// ContextUsedTokens / MaxContextTokens are surfaced so the UI can show a
// context-utilization preview without a full detail round-trip.
ContextUsedTokens int `json:"contextUsedTokens,omitempty"`
MaxContextTokens int `json:"maxContextTokens,omitempty"`
}
HistoryResult is a single row in a history listing.
type RunArchive ¶
type RunArchive struct {
// ID is the composite primary key: "namespace/name".
ID string `db:"id"`
// Kubernetes metadata.
Name string `db:"name"`
Namespace string `db:"namespace"`
Labels map[string]string `db:"labels"`
// Spec-level fields.
AgentRef string `db:"agent_ref"`
Input string `db:"input"`
ParentRunRef string `db:"parent_run_ref"`
PriorRunRef string `db:"prior_run_ref"`
TimeoutSec sql.NullInt64 `db:"timeout_sec"`
// Status-level fields (captured at archival time).
Phase string `db:"phase"`
PodName string `db:"pod_name"`
SpendUSD string `db:"spend_usd"`
Output string `db:"output"`
RawOutput string `db:"raw_output"`
RestartCount int `db:"restart_count"`
StartTime *time.Time `db:"start_time"`
CompletionTime *time.Time `db:"completion_time"`
ContextUsedTokens int `db:"context_used_tokens"`
MaxContextTokens int `db:"max_context_tokens"`
// Tenant attribution (from agentorca.io/tenant label, empty if unattributed).
Tenant string `db:"tenant"`
// Routing decisions and child refs (JSON-serialised).
RoutingDecisionsJSON []byte `db:"routing_decisions"`
ChildRunRefsJSON []byte `db:"child_run_refs"`
// TraceEventsJSON is the archived execution trace — a JSON array of
// {id, event, ts, childRunName} entries read from the Redis token stream
// at archival time. NULL when no trace events were available (store
// disabled, stream expired, or pre-feature run).
TraceEventsJSON []byte `db:"trace_events"`
// Timestamps.
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
RunArchive is the relational representation of an archived AgentRun. Fields are flattened from the CRD spec and status for SQL querying.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the PostgreSQL archival store.
func NewStore ¶
NewStore creates a new PostgreSQL store from a connection DSN. The DSN format follows the pgx connection string syntax:
postgresql://user:password@host:5432/dbname?sslmode=require
func (*Store) ApplyMigration ¶
ApplyMigration runs the schema migration SQL against the store.
func (*Store) ArchiveRun ¶
func (s *Store) ArchiveRun(ctx context.Context, run *agentorcav1alpha1.AgentRun, traceEventsJSON []byte) error
ArchiveRun upserts a completed AgentRun into the archival table. traceEventsJSON is a pre-marshalled JSON array of trace entries (or nil to leave the column untouched on conflict). It is passed in by the controller after reading the Redis token stream, so the full execution trace can be rendered in the history view.
func (*Store) QueryHistory ¶
func (s *Store) QueryHistory(ctx context.Context, q HistoryQuery) (*HistoryPage, error)
QueryHistory returns a paginated, filtered list of archived runs.