Documentation
¶
Index ¶
- type AIDecision
- type Action
- type AuditLog
- type DatabaseConfig
- type DatabaseManager
- func (dm *DatabaseManager) Close()
- func (dm *DatabaseManager) Exec(ctx context.Context, query string, args ...interface{}) (pgconn.CommandTag, error)
- func (dm *DatabaseManager) GetPool() *pgxpool.Pool
- func (dm *DatabaseManager) GetSQLDB() (*sql.DB, error)
- func (dm *DatabaseManager) HealthCheck(ctx context.Context) error
- func (dm *DatabaseManager) Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
- func (dm *DatabaseManager) QueryRow(ctx context.Context, query string, args ...interface{}) pgx.Row
- func (dm *DatabaseManager) Stats() *pgxpool.Stat
- func (dm *DatabaseManager) Transaction(ctx context.Context, fn func(pgx.Tx) error) error
- type Organization
- type Repository
- func (r *Repository) CreateAIDecision(ctx context.Context, decision *AIDecision) error
- func (r *Repository) CreateAction(ctx context.Context, action *Action) error
- func (r *Repository) CreateAuditLog(ctx context.Context, log *AuditLog) error
- func (r *Repository) CreateSavingsEvent(ctx context.Context, event *SavingsEvent) error
- func (r *Repository) GetActionByID(ctx context.Context, id string) (*Action, error)
- func (r *Repository) GetPendingActions(ctx context.Context) ([]*Action, error)
- func (r *Repository) GetTokenUsageStats(ctx context.Context, timeRange time.Duration) (map[string]interface{}, error)
- func (r *Repository) RecordTokenUsage(ctx context.Context, usage *TokenUsage) error
- func (r *Repository) UpdateActionStatus(ctx context.Context, id, status string, startedAt, completedAt *time.Time, ...) error
- type Resource
- type SavingsEvent
- type TokenUsage
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AIDecision ¶
type AIDecision struct {
ID string `json:"id" db:"id"`
ResourceID string `json:"resource_id" db:"resource_id"`
Model string `json:"model" db:"model"`
Decision string `json:"decision" db:"decision"`
Reasoning *string `json:"reasoning" db:"reasoning"`
Confidence *float64 `json:"confidence" db:"confidence"`
TokensUsed *int `json:"tokens_used" db:"tokens_used"`
LatencyMs *int `json:"latency_ms" db:"latency_ms"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
AIDecision represents an AI decision
type Action ¶
type Action struct {
ID string `json:"id" db:"id"`
ResourceID string `json:"resource_id" db:"resource_id"`
ActionType string `json:"action_type" db:"action_type"`
Status string `json:"status" db:"status"`
Checksum string `json:"checksum" db:"checksum"`
Payload string `json:"payload" db:"payload"`
RiskScore float64 `json:"risk_score" db:"risk_score"`
EstimatedSavings float64 `json:"estimated_savings" db:"estimated_savings"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
StartedAt *time.Time `json:"started_at" db:"started_at"`
CompletedAt *time.Time `json:"completed_at" db:"completed_at"`
ErrorMessage *string `json:"error_message" db:"error_message"`
}
Action represents an action in the system
type AuditLog ¶
type AuditLog struct {
ID string `json:"id" db:"id"`
UserID *string `json:"user_id" db:"user_id"`
Action string `json:"action" db:"action"`
ResourceType *string `json:"resource_type" db:"resource_type"`
ResourceID *string `json:"resource_id" db:"resource_id"`
Details map[string]interface{} `json:"details" db:"details"`
IPAddress *string `json:"ip_address" db:"ip_address"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
AuditLog represents an audit log entry
type DatabaseConfig ¶
type DatabaseConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Database string `yaml:"database"`
Username string `yaml:"username"`
Password string `yaml:"password"`
SSLMode string `yaml:"ssl_mode"`
MaxConnections int `yaml:"max_connections"`
MinConnections int `yaml:"min_connections"`
MaxIdleTime time.Duration `yaml:"max_idle_time"`
MaxLifetime time.Duration `yaml:"max_lifetime"`
ConnectTimeout time.Duration `yaml:"connect_timeout"`
HealthCheckPeriod time.Duration `yaml:"health_check_period"`
}
DatabaseConfig holds database configuration
func DefaultDatabaseConfig ¶
func DefaultDatabaseConfig() DatabaseConfig
DefaultDatabaseConfig returns a default database configuration
func ProductionDatabaseConfig ¶
func ProductionDatabaseConfig() DatabaseConfig
ProductionDatabaseConfig returns a production database configuration
type DatabaseManager ¶
type DatabaseManager struct {
// contains filtered or unexported fields
}
DatabaseManager manages database connections and operations
func NewDatabaseManager ¶
func NewDatabaseManager(config DatabaseConfig, logger *zap.Logger, tracer trace.Tracer) (*DatabaseManager, error)
NewDatabaseManager creates a new database manager with zap logging
func (*DatabaseManager) Close ¶
func (dm *DatabaseManager) Close()
Close closes the database connection pool
func (*DatabaseManager) Exec ¶
func (dm *DatabaseManager) Exec(ctx context.Context, query string, args ...interface{}) (pgconn.CommandTag, error)
Exec executes a query that doesn't return rows
func (*DatabaseManager) GetPool ¶
func (dm *DatabaseManager) GetPool() *pgxpool.Pool
GetPool returns the underlying connection pool
func (*DatabaseManager) GetSQLDB ¶
func (dm *DatabaseManager) GetSQLDB() (*sql.DB, error)
GetSQLDB returns a *sql.DB for compatibility with libraries that need it
func (*DatabaseManager) HealthCheck ¶
func (dm *DatabaseManager) HealthCheck(ctx context.Context) error
HealthCheck performs a health check on the database
func (*DatabaseManager) Query ¶
func (dm *DatabaseManager) Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
Query executes a query that returns rows
func (*DatabaseManager) Stats ¶
func (dm *DatabaseManager) Stats() *pgxpool.Stat
Stats returns connection pool statistics
func (*DatabaseManager) Transaction ¶
Transaction executes a function within a database transaction
type Organization ¶
type Organization struct {
ID string `json:"id" db:"id"`
Name string `json:"name" db:"name"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
Settings map[string]interface{} `json:"settings" db:"settings"`
}
Organization represents an organization
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository provides database operations for entities
func NewRepository ¶
func NewRepository(db *DatabaseManager, logger *zap.Logger, tracer trace.Tracer) *Repository
NewRepository creates a new repository
func (*Repository) CreateAIDecision ¶
func (r *Repository) CreateAIDecision(ctx context.Context, decision *AIDecision) error
CreateAIDecision creates a new AI decision
func (*Repository) CreateAction ¶
func (r *Repository) CreateAction(ctx context.Context, action *Action) error
CreateAction creates a new action
func (*Repository) CreateAuditLog ¶
func (r *Repository) CreateAuditLog(ctx context.Context, log *AuditLog) error
CreateAuditLog creates a new audit log entry
func (*Repository) CreateSavingsEvent ¶
func (r *Repository) CreateSavingsEvent(ctx context.Context, event *SavingsEvent) error
CreateSavingsEvent creates a new savings event
func (*Repository) GetActionByID ¶
GetActionByID retrieves an action by ID
func (*Repository) GetPendingActions ¶
func (r *Repository) GetPendingActions(ctx context.Context) ([]*Action, error)
GetPendingActions retrieves all pending actions
func (*Repository) GetTokenUsageStats ¶
func (r *Repository) GetTokenUsageStats(ctx context.Context, timeRange time.Duration) (map[string]interface{}, error)
GetTokenUsageStats retrieves token usage statistics
func (*Repository) RecordTokenUsage ¶
func (r *Repository) RecordTokenUsage(ctx context.Context, usage *TokenUsage) error
RecordTokenUsage records token usage
func (*Repository) UpdateActionStatus ¶
func (r *Repository) UpdateActionStatus(ctx context.Context, id, status string, startedAt, completedAt *time.Time, errorMessage *string) error
UpdateActionStatus updates an action's status
type Resource ¶
type Resource struct {
ID string `json:"id" db:"id"`
OrganizationID *string `json:"organization_id" db:"organization_id"`
CloudResourceID string `json:"cloud_resource_id" db:"cloud_resource_id"`
CloudProvider string `json:"cloud_provider" db:"cloud_provider"`
ResourceType *string `json:"resource_type" db:"resource_type"`
Region *string `json:"region" db:"region"`
Tags map[string]interface{} `json:"tags" db:"tags"`
Metadata map[string]interface{} `json:"metadata" db:"metadata"`
MonthlyCost *float64 `json:"monthly_cost" db:"monthly_cost"`
LastScanned *time.Time `json:"last_scanned" db:"last_scanned"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
Resource represents a cloud resource
type SavingsEvent ¶
type SavingsEvent struct {
ID string `json:"id" db:"id"`
ActionID *string `json:"action_id" db:"action_id"`
ResourceID string `json:"resource_id" db:"resource_id"`
OptimizationType *string `json:"optimization_type" db:"optimization_type"`
EstimatedSavings *float64 `json:"estimated_savings" db:"estimated_savings"`
ActualSavings *float64 `json:"actual_savings" db:"actual_savings"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
SavingsEvent represents a savings event
type TokenUsage ¶
type TokenUsage struct {
ID string `json:"id" db:"id"`
Model string `json:"model" db:"model"`
Tokens int `json:"tokens" db:"tokens"`
CostUSD float64 `json:"cost_usd" db:"cost_usd"`
RequestType *string `json:"request_type" db:"request_type"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
TokenUsage represents token usage tracking
type User ¶
type User struct {
ID string `json:"id" db:"id"`
Email string `json:"email" db:"email"`
OrganizationID *string `json:"organization_id" db:"organization_id"`
Role string `json:"role" db:"role"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
LastLogin *time.Time `json:"last_login" db:"last_login"`
}
User represents a user