failover

package
v0.1.56 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package failover stores operator-managed manual failover mappings.

Index

Constants

View Source
const (
	ManagedSourceDashboard = "dashboard"
	ManagedSourceConfig    = "config"
)

Variables

View Source
var ErrManaged = errors.New("failover mapping is managed by configuration")
View Source
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

func (*MongoDBStore) DeleteAll

func (s *MongoDBStore) DeleteAll(ctx context.Context) error

func (*MongoDBStore) Get

func (s *MongoDBStore) Get(ctx context.Context, source string) (*Rule, error)

func (*MongoDBStore) List

func (s *MongoDBStore) List(ctx context.Context) ([]Rule, error)

func (*MongoDBStore) Upsert

func (s *MongoDBStore) Upsert(ctx context.Context, rule Rule) error

type PostgreSQLStore

type PostgreSQLStore struct {
	// contains filtered or unexported fields
}

func NewPostgreSQLStore

func NewPostgreSQLStore(ctx context.Context, pool *pgxpool.Pool) (*PostgreSQLStore, error)

func (*PostgreSQLStore) Close

func (s *PostgreSQLStore) Close() error

func (*PostgreSQLStore) Delete

func (s *PostgreSQLStore) Delete(ctx context.Context, source string) error

func (*PostgreSQLStore) DeleteAll

func (s *PostgreSQLStore) DeleteAll(ctx context.Context) error

func (*PostgreSQLStore) Get

func (s *PostgreSQLStore) Get(ctx context.Context, source string) (*Rule, error)

func (*PostgreSQLStore) List

func (s *PostgreSQLStore) List(ctx context.Context) ([]Rule, error)

func (*PostgreSQLStore) Upsert

func (s *PostgreSQLStore) Upsert(ctx context.Context, rule Rule) 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 New

func New(ctx context.Context, cfg *config.Config) (*Result, error)

func NewWithSharedStorage

func NewWithSharedStorage(ctx context.Context, cfg *config.Config, shared storage.Storage) (*Result, error)

func (*Result) Close

func (r *Result) Close() error

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

type RuleProvider interface {
	Rules() map[string][]string
	Disabled() map[string]bool
}

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

func (*SQLiteStore) Delete

func (s *SQLiteStore) Delete(ctx context.Context, source string) error

func (*SQLiteStore) DeleteAll

func (s *SQLiteStore) DeleteAll(ctx context.Context) error

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, source string) (*Rule, error)

func (*SQLiteStore) List

func (s *SQLiteStore) List(ctx context.Context) ([]Rule, error)

func (*SQLiteStore) Upsert

func (s *SQLiteStore) Upsert(ctx context.Context, rule Rule) 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) Delete

func (s *Service) Delete(ctx context.Context, source string) error

func (*Service) Disabled

func (s *Service) Disabled() map[string]bool

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) Get

func (s *Service) Get(source string) (*Rule, bool)

func (*Service) List

func (s *Service) List() []Rule

func (*Service) ListViews

func (s *Service) ListViews() []View

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context) error

func (*Service) ResetDashboardRules

func (s *Service) ResetDashboardRules(ctx context.Context) error

func (*Service) Rules

func (s *Service) Rules() map[string][]string

Rules returns the enabled source -> targets map. The returned map is the cached snapshot and must not be mutated by callers.

func (*Service) StartBackgroundRefresh

func (s *Service) StartBackgroundRefresh(interval time.Duration) func()

func (*Service) Upsert

func (s *Service) Upsert(ctx context.Context, rule Rule) error

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.

Jump to

Keyboard shortcuts

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