Documentation
¶
Index ¶
- func ListenAndServe(addr string, tlsCfg *tls.Config, reg *Registry, ...) error
- func LoadTLSConfig(certData, keyData, caData []byte) (*tls.Config, error)
- func NewGRPCServer(tlsCfg *tls.Config, unary ...grpc.UnaryServerInterceptor) *grpc.Server
- func StartSpan(ctx context.Context, name string) (context.Context, func())
- func UnaryMetaInterceptor() grpc.UnaryServerInterceptor
- type ClosableHandler
- type EnhancedMonitoredHandler
- func (emh *EnhancedMonitoredHandler) GetDetailedMetrics() map[string]interface{}
- func (emh *EnhancedMonitoredHandler) Invoke(ctx context.Context, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
- func (emh *EnhancedMonitoredHandler) SetResourceLimits(maxMemoryBytes int64, maxGoroutines int32, maxConnections int32) error
- type Handler
- type HealthAwareHandler
- type MonitoredHandler
- type PluginHealth
- type PluginResourceMetrics
- type PluginWrapper
- type ReadyFunc
- type Registry
- func (r *Registry) GetPluginCount() int
- func (r *Registry) GetPluginNames() []string
- func (r *Registry) GetPluginStatus() map[string]interface{}
- func (r *Registry) Invoke(ctx context.Context, pluginName string, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
- func (r *Registry) Lookup(pluginName string) (Handler, bool)
- func (r *Registry) Register(name string, handler ClosableHandler) error
- func (r *Registry) RegisterOrReplace(name string, handler ClosableHandler) error
- func (r *Registry) Shutdown()
- func (r *Registry) StartHealthChecks()
- func (r *Registry) Unregister(name string) error
- func (r *Registry) UpdateMetrics()
- type RegistryConfig
- type ResourceAwareHandler
- type ResourceMonitor
- func (rm *ResourceMonitor) GetAllMetrics() map[string]*PluginResourceMetrics
- func (rm *ResourceMonitor) GetHealthStatus() map[string]interface{}
- func (rm *ResourceMonitor) GetPluginMetrics(pluginID string) *PluginResourceMetrics
- func (rm *ResourceMonitor) RecordRequest(pluginID string)
- func (rm *ResourceMonitor) RecordRequestComplete(pluginID string, durationMs int64, isError bool)
- func (rm *ResourceMonitor) RegisterPlugin(pluginID string)
- func (rm *ResourceMonitor) Stop()
- func (rm *ResourceMonitor) UnregisterPlugin(pluginID string)
- func (rm *ResourceMonitor) UpdateResourceUsage(pluginID string, memoryBytes int64, goroutines int32, connections int32)
- type Runtime
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
func ListenAndServe(addr string, tlsCfg *tls.Config, reg *Registry, unary ...grpc.UnaryServerInterceptor) error
監聽與啟動服務
func LoadTLSConfig ¶
LoadTLSConfig 由憑證內容載入 mTLS 設定。若任一為空,回傳 nil 代表使用明文(僅限開發)。
func NewGRPCServer ¶
建立 gRPC 伺服器(可掛載 mTLS 與攔截器)
func UnaryMetaInterceptor ¶
func UnaryMetaInterceptor() grpc.UnaryServerInterceptor
UnaryMetaInterceptor 取得與透傳必要 metadata(tenant/traceparent/owner 等)
Types ¶
type ClosableHandler ¶
ClosableHandler 支援資源釋放的處理器
type EnhancedMonitoredHandler ¶
type EnhancedMonitoredHandler struct { *MonitoredHandler // contains filtered or unexported fields }
EnhancedMonitoredHandler 增強型監控處理器(支援資源感知)
func NewEnhancedMonitoredHandler ¶
func NewEnhancedMonitoredHandler(pluginID string, handler ResourceAwareHandler, monitor *ResourceMonitor) *EnhancedMonitoredHandler
NewEnhancedMonitoredHandler 創建增強型監控處理器
func (*EnhancedMonitoredHandler) GetDetailedMetrics ¶
func (emh *EnhancedMonitoredHandler) GetDetailedMetrics() map[string]interface{}
GetDetailedMetrics 獲取詳細的監控指標
func (*EnhancedMonitoredHandler) Invoke ¶
func (emh *EnhancedMonitoredHandler) Invoke(ctx context.Context, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
Invoke 執行增強型監控請求
func (*EnhancedMonitoredHandler) SetResourceLimits ¶
func (emh *EnhancedMonitoredHandler) SetResourceLimits(maxMemoryBytes int64, maxGoroutines int32, maxConnections int32) error
SetResourceLimits 設置資源限制
type Handler ¶
type Handler interface {
Invoke(ctx context.Context, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
}
Handler 為每個插件的處理器介面
type HealthAwareHandler ¶
type HealthAwareHandler interface { ClosableHandler HealthCheck() error }
HealthAwareHandler 支援健康檢查的處理器
type MonitoredHandler ¶
type MonitoredHandler struct {
// contains filtered or unexported fields
}
MonitoredHandler 具備資源監控功能的處理器包裝器
func NewMonitoredHandler ¶
func NewMonitoredHandler(pluginID string, handler Handler, monitor *ResourceMonitor) *MonitoredHandler
NewMonitoredHandler 創建新的監控處理器
func (*MonitoredHandler) GetActiveRequests ¶
func (mh *MonitoredHandler) GetActiveRequests() int64
GetActiveRequests 獲取活躍請求數量
func (*MonitoredHandler) Invoke ¶
func (mh *MonitoredHandler) Invoke(ctx context.Context, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
Invoke 執行請求並進行資源監控
type PluginHealth ¶
type PluginHealth int
插件健康狀態枚舉
const ( HealthUnknown PluginHealth = iota // 0: 未知狀態 HealthOk // 1: 正常運行 HealthDegraded // 2: 部分功能可用 HealthCritical // 3: 嚴重錯誤 HealthShuttingDown // 4: 關閉中 )
type PluginResourceMetrics ¶
type PluginResourceMetrics struct { // 基本統計 TotalRequests int64 // 總請求數 ActiveRequests int64 // 活躍請求數 TotalErrors int64 // 總錯誤數 TotalDuration int64 // 總執行時間(毫秒) // 資源使用 MemoryUsageBytes int64 // 記憶體使用量(位元組) GoroutineCount int32 // Goroutine 數量 ConnectionCount int32 // 連線數量 // 性能指標 AvgResponseTimeMs float64 // 平均回應時間 RequestsPerSecond float64 // 每秒請求數 ErrorRate float64 // 錯誤率 // 時間戳 LastUpdateTime int64 // 最後更新時間(Unix毫秒) StartTime int64 // 插件啟動時間 }
PluginResourceMetrics 插件級別資源指標
type PluginWrapper ¶
type PluginWrapper struct {
// contains filtered or unexported fields
}
PluginWrapper 插件封裝結構(包含健康狀態和負載追蹤)
func NewPluginWrapper ¶
func NewPluginWrapper(name string, handler ClosableHandler) *PluginWrapper
NewPluginWrapper 創建新的插件包裝器
func (*PluginWrapper) GetHealth ¶
func (pw *PluginWrapper) GetHealth() PluginHealth
GetHealth 取得健康狀態
func (*PluginWrapper) GetLastCheck ¶
func (pw *PluginWrapper) GetLastCheck() time.Time
GetLastCheck 取得最後檢查時間
func (*PluginWrapper) SetHealth ¶
func (pw *PluginWrapper) SetHealth(health PluginHealth)
SetHealth 設定健康狀態
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 插件註冊中心(核心數據結構)
func NewRegistryWithConfig ¶
func NewRegistryWithConfig(config *RegistryConfig) *Registry
NewRegistryWithConfig 使用配置創建註冊中心
func (*Registry) GetPluginNames ¶
GetPluginNames 獲取所有插件名稱
func (*Registry) GetPluginStatus ¶
GetPluginStatus 獲取插件狀態(用於監控)
func (*Registry) Invoke ¶
func (r *Registry) Invoke(ctx context.Context, pluginName string, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
Invoke 調用插件(含熔斷和負載保護)
func (*Registry) Register ¶
func (r *Registry) Register(name string, handler ClosableHandler) error
Register 註冊插件(執行緒安全)
func (*Registry) RegisterOrReplace ¶
func (r *Registry) RegisterOrReplace(name string, handler ClosableHandler) error
RegisterOrReplace 註冊或替換插件
func (*Registry) StartHealthChecks ¶
func (r *Registry) StartHealthChecks()
StartHealthChecks 啟動健康檢查協程
func (*Registry) UpdateMetrics ¶
func (r *Registry) UpdateMetrics()
UpdateMetrics 更新插件指標(由 Registry 定期調用)
type RegistryConfig ¶
type RegistryConfig struct { MaxLoad int32 `yaml:"max_load" json:"max_load"` // 最大負載,預設 100 HealthInterval time.Duration `yaml:"health_interval" json:"health_interval"` // 健康檢查間隔,預設 30s }
RegistryConfig 註冊中心配置
func DefaultRegistryConfig ¶
func DefaultRegistryConfig() *RegistryConfig
DefaultRegistryConfig 預設配置
type ResourceAwareHandler ¶
type ResourceAwareHandler interface { Handler // GetResourceUsage 返回當前資源使用情況 GetResourceUsage() (memoryBytes int64, goroutines int32, connections int32) // SetResourceLimits 設置資源限制 SetResourceLimits(maxMemoryBytes int64, maxGoroutines int32, maxConnections int32) error }
ResourceAwareHandler 支援資源感知的處理器接口
type ResourceMonitor ¶
type ResourceMonitor struct {
// contains filtered or unexported fields
}
ResourceMonitor 資源監控管理器
func NewResourceMonitor ¶
func NewResourceMonitor(interval time.Duration) (*ResourceMonitor, error)
NewResourceMonitor 創建新的資源監控器
func (*ResourceMonitor) GetAllMetrics ¶
func (rm *ResourceMonitor) GetAllMetrics() map[string]*PluginResourceMetrics
GetAllMetrics 獲取所有插件指標
func (*ResourceMonitor) GetHealthStatus ¶
func (rm *ResourceMonitor) GetHealthStatus() map[string]interface{}
GetHealthStatus 獲取監控健康狀態
func (*ResourceMonitor) GetPluginMetrics ¶
func (rm *ResourceMonitor) GetPluginMetrics(pluginID string) *PluginResourceMetrics
GetPluginMetrics 獲取插件指標
func (*ResourceMonitor) RecordRequest ¶
func (rm *ResourceMonitor) RecordRequest(pluginID string)
RecordRequest 記錄請求開始
func (*ResourceMonitor) RecordRequestComplete ¶
func (rm *ResourceMonitor) RecordRequestComplete(pluginID string, durationMs int64, isError bool)
RecordRequestComplete 記錄請求完成
func (*ResourceMonitor) RegisterPlugin ¶
func (rm *ResourceMonitor) RegisterPlugin(pluginID string)
RegisterPlugin 註冊插件監控
func (*ResourceMonitor) UnregisterPlugin ¶
func (rm *ResourceMonitor) UnregisterPlugin(pluginID string)
UnregisterPlugin 取消註冊插件監控
func (*ResourceMonitor) UpdateResourceUsage ¶
func (rm *ResourceMonitor) UpdateResourceUsage(pluginID string, memoryBytes int64, goroutines int32, connections int32)
UpdateResourceUsage 更新資源使用情況
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
type Server ¶
type Server struct { v1.UnimplementedToolBridgeServiceServer // contains filtered or unexported fields }
Server 實作 ToolBridge,將請求分派至已註冊的 Handler。
func (*Server) Healthz ¶
func (s *Server) Healthz(ctx context.Context, _ *v1.HealthzRequest) (*v1.HealthzResponse, error)
func (*Server) Invoke ¶
func (s *Server) Invoke(ctx context.Context, req *v1.InvokeRequest) (*v1.InvokeResponse, error)
func (*Server) InvokeStream ¶
func (s *Server) InvokeStream(_ *v1.InvokeStreamRequest, _ v1.ToolBridgeService_InvokeStreamServer) error
Streaming 版(保留擴充)
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
plugins
|
|
knowledge
Package knowledge 實作知識庫管理插件
|
Package knowledge 實作知識庫管理插件 |
observability/health_aggregator
Package health_aggregator 實作健康指標聚合插件
|
Package health_aggregator 實作健康指標聚合插件 |