Documentation
¶
Overview ¶
Package failover stores operator-managed manual failover mappings.
Index ¶
- Constants
- Variables
- type MongoDBStore
- func (s *MongoDBStore) Close() error
- func (s *MongoDBStore) Delete(ctx context.Context, source string) error
- func (s *MongoDBStore) DeleteAll(ctx context.Context) error
- func (s *MongoDBStore) Get(ctx context.Context, source string) (*Rule, error)
- func (s *MongoDBStore) List(ctx context.Context) ([]Rule, error)
- func (s *MongoDBStore) Upsert(ctx context.Context, rule Rule) error
- type PostgreSQLStore
- func (s *PostgreSQLStore) Close() error
- func (s *PostgreSQLStore) Delete(ctx context.Context, source string) error
- func (s *PostgreSQLStore) DeleteAll(ctx context.Context) error
- func (s *PostgreSQLStore) Get(ctx context.Context, source string) (*Rule, error)
- func (s *PostgreSQLStore) List(ctx context.Context) ([]Rule, error)
- func (s *PostgreSQLStore) Upsert(ctx context.Context, rule Rule) error
- type Registry
- type Resolver
- type Result
- type Rule
- type RuleProvider
- type SQLiteStore
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) Delete(ctx context.Context, source string) error
- func (s *SQLiteStore) DeleteAll(ctx context.Context) error
- func (s *SQLiteStore) Get(ctx context.Context, source string) (*Rule, error)
- func (s *SQLiteStore) List(ctx context.Context) ([]Rule, error)
- func (s *SQLiteStore) Upsert(ctx context.Context, rule Rule) error
- type Service
- func (s *Service) Delete(ctx context.Context, source string) error
- func (s *Service) Disabled() map[string]bool
- func (s *Service) Get(source string) (*Rule, bool)
- func (s *Service) List() []Rule
- func (s *Service) ListViews() []View
- func (s *Service) Refresh(ctx context.Context) error
- func (s *Service) ResetDashboardRules(ctx context.Context) error
- func (s *Service) Rules() map[string][]string
- func (s *Service) StartBackgroundRefresh(interval time.Duration) func()
- func (s *Service) Upsert(ctx context.Context, rule Rule) error
- type Store
- type View
Constants ¶
const ( ManagedSourceDashboard = "dashboard" ManagedSourceConfig = "config" )
Variables ¶
var ErrManaged = errors.New("failover mapping is managed by configuration")
var ErrNotFound = errors.New("failover mapping not found")
Functions ¶
This section is empty.
Types ¶
type MongoDBStore ¶
type MongoDBStore struct {
// contains filtered or unexported fields
}
func NewMongoDBStore ¶
func NewMongoDBStore(database *mongo.Database) (*MongoDBStore, error)
func (*MongoDBStore) Close ¶
func (s *MongoDBStore) Close() error
func (*MongoDBStore) Delete ¶
func (s *MongoDBStore) Delete(ctx context.Context, source string) error
type PostgreSQLStore ¶
type PostgreSQLStore struct {
// contains filtered or unexported fields
}
func NewPostgreSQLStore ¶
func (*PostgreSQLStore) Close ¶
func (s *PostgreSQLStore) Close() error
func (*PostgreSQLStore) Delete ¶
func (s *PostgreSQLStore) Delete(ctx context.Context, source string) error
type Registry ¶
type Registry interface {
GetModel(model string) *providers.ModelInfo
ListModelsWithProvider() []providers.ModelWithProvider
}
Registry is the minimal provider inventory surface needed for failover candidate resolution.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver computes failover model chains for translated routes.
func NewResolverWithRuleProvider ¶
func NewResolverWithRuleProvider(cfg config.FailoverConfig, registry Registry, ruleProvider RuleProvider) *Resolver
NewResolverWithRuleProvider builds a failover resolver from config and the current model inventory, backed by an optional dynamic manual-rule provider. Returns nil when failover is effectively disabled.
func (*Resolver) ResolveFailovers ¶
func (r *Resolver) ResolveFailovers(resolution *core.RequestModelResolution, op core.Operation) []core.ModelSelector
ResolveFailovers returns the ordered failover chain for a resolved request. Manual failovers preserve configured order. Runtime auto mode is intentionally not used; generated candidates must be saved as manual rules first.
func (*Resolver) SuggestFailovers ¶
func (r *Resolver) SuggestFailovers(resolution *core.RequestModelResolution, op core.Operation) []core.ModelSelector
SuggestFailovers returns ranked candidate selectors for an operator to review and save as a manual rule. Suggestions are never used directly at runtime.
type Result ¶
type Result struct {
Service *Service
Store Store
Storage storage.Storage
// contains filtered or unexported fields
}
func NewWithSharedStorage ¶
type Rule ¶
type Rule struct {
Source string `json:"primary_model" bson:"_id"`
Targets []string `json:"fallback_models" bson:"fallback_models"`
Enabled bool `json:"enabled" bson:"enabled"`
ManagedSource string `json:"managed_source" bson:"managed_source"`
CreatedAt time.Time `json:"created_at" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
}
Rule is one manual failover mapping for a primary model selector.
func ConfigRules ¶
func ConfigRules(cfg config.FailoverConfig) []Rule
type RuleProvider ¶
RuleProvider supplies the current effective manual failover rules.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
func NewSQLiteStore ¶
func NewSQLiteStore(db *sql.DB) (*SQLiteStore, error)
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service merges dashboard-managed mappings with read-only config/env mappings.
func NewService ¶
func NewService(store Store, cfg config.FailoverConfig) (*Service, error)
func (*Service) Disabled ¶
Disabled returns the set of disabled sources, or nil when none. The returned map is the cached snapshot and must not be mutated by callers.
func (*Service) ResetDashboardRules ¶
func (*Service) Rules ¶
Rules returns the enabled source -> targets map. The returned map is the cached snapshot and must not be mutated by callers.
func (*Service) StartBackgroundRefresh ¶
type Store ¶
type Store interface {
List(ctx context.Context) ([]Rule, error)
Get(ctx context.Context, source string) (*Rule, error)
Upsert(ctx context.Context, rule Rule) error
Delete(ctx context.Context, source string) error
DeleteAll(ctx context.Context) error
Close() error
}
Store defines persistence operations for dashboard-managed failover mappings.
type View ¶
type View struct {
Source string `json:"primary_model"`
Targets []string `json:"fallback_models"`
Enabled bool `json:"enabled"`
Managed bool `json:"managed"`
ManagedSource string `json:"managed_source"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
View is the admin-facing representation of one failover mapping.
func GenerateSuggestions ¶
func GenerateSuggestions(registry Registry, rules RuleProvider, primaryModel string) []View
GenerateSuggestions builds dashboard failover-rule suggestions for every text-generation-capable model in the registry, optionally filtered to one source model (matched by selector, bare model ID, or provider-qualified ID). It returns an empty slice when the registry is nil or nothing qualifies.