master

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 57 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	Cfg     *config.MasterRuntimeConfig
	Logger  *zap.Logger
	DB      *gorm.DB
	Bus     app.EventBus
	Router  *gin.Engine
	Version atomic.Int64

	Hub      *msync.Hub
	Listener net.Listener

	App app.Application

	// Heartbeat captures agent last_seen in memory and periodically flushes
	// to DB; also serves freshness reads for API enrichment. Started in Run
	// and stopped (force-flushed) in Shutdown.
	Heartbeat *msync.HeartbeatTracker

	// Aggregator buffers per-key billing rollup deltas (token_daily /
	// channel_daily / hourly_bucket) in memory and flushes them in
	// batched UPSERTs. Settler hands off each committed UsageLog to it
	// via the UsageAggregator interface. Started in Run; Stop() in
	// Shutdown drains the final batch before Heartbeat.Stop.
	Aggregator *billing.Aggregator

	// RebuildRunner schedules async per-hour billing rollup rebuilds.
	// Submitted jobs run as background goroutines (one per Submit);
	// the gc loop spawns inside NewRebuildRunner. Stopped in Shutdown
	// between Aggregator and Heartbeat (spec §9).
	RebuildRunner *billing.RebuildRunner

	// LimitEvaluator periodically evaluates per-channel usage limits,
	// toggling Status + LimitState. Stopped in Shutdown.
	LimitEvaluator *billing.LimitEvaluator

	// BYOKProvider 是 BYOK cipher 的注入点。private_channel.Handler
	// 通过它获取 *Cipher,避免污染 app.Application 顶层接口。
	BYOKProvider byokcrypto.Provider
	// contains filtered or unexported fields
}

func New

func New(cfg config.MasterRuntimeProvider, logger *zap.Logger) (*Server, error)

func (*Server) GetEmbeddedAgentStore

func (s *Server) GetEmbeddedAgentStore() *cache.Store

GetEmbeddedAgentStore returns the embedded agent's cache store. Tests use this to wait for cache sync barriers (e.g. polling until __system_test__ token is visible to the relay's auth middleware).

Returns nil if embedded agent has not been set up yet.

func (*Server) InitAdminUser

func (s *Server) InitAdminUser(username, password string) error

func (*Server) Run

func (s *Server) Run() error

func (*Server) SetChannelMasterListen

func (s *Server) SetChannelMasterListen(addr string)

SetChannelMasterListen overrides the channel handler's MasterListen after master.New() has run. Used by tests that bind a real listener (which yields the actual port) only after server construction.

func (*Server) SetupEmbeddedAgentForTest

func (s *Server) SetupEmbeddedAgentForTest(listenAddr string) error

SetupEmbeddedAgentForTest mounts the embedded agent relay routes on the master router using the given listen address. This is the test-only escape hatch that replicates the production path in Run() without requiring a real net.Listener. Call it after httptest.NewServer so you have the actual port.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Jump to

Keyboard shortcuts

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