Documentation
¶
Overview ¶
Package orchestrator manages the lifecycle of services registered in the shared service registry. It starts and stops services, retries failed MCPServer connections with bounded concurrency, probes connected MCPServers so that one that stops answering fails itself onto that same reconnect schedule, and publishes service state-change events to subscribers.
Service implementations live in subpackages of internal/services. The orchestrator drives them through the services.Service interface and the services.ServiceRegistry; it has no service-specific logic of its own.
Index ¶
- Constants
- Variables
- type Adapter
- func (a *Adapter) ExecuteTool(ctx context.Context, toolName string, args map[string]interface{}) (*api.CallToolResult, error)
- func (a *Adapter) GetAllServices() []api.ServiceStatus
- func (a *Adapter) GetServiceStatus(name string) (*api.ServiceStatus, error)
- func (a *Adapter) GetTools() []api.ToolMetadata
- func (a *Adapter) Register()
- func (a *Adapter) RemoveService(name string) error
- func (a *Adapter) RestartService(name string) error
- func (a *Adapter) StartService(name string) error
- func (a *Adapter) StopService(name string) error
- func (a *Adapter) SubscribeToStateChanges() <-chan api.ServiceStateChangedEvent
- type Config
- type Orchestrator
- func (o *Orchestrator) GetAllServices() []ServiceStatus
- func (o *Orchestrator) GetServiceRegistry() services.ServiceRegistry
- func (o *Orchestrator) GetServiceStatus(name string) (*ServiceStatus, error)
- func (o *Orchestrator) RemoveService(name string) error
- func (o *Orchestrator) RestartService(name string) error
- func (o *Orchestrator) Start(ctx context.Context) error
- func (o *Orchestrator) StartService(name string) error
- func (o *Orchestrator) Stop() error
- func (o *Orchestrator) StopService(name string) error
- func (o *Orchestrator) SubscribeToStateChanges() <-chan ServiceStateChangedEvent
- type ServiceStateChangedEvent
- type ServiceStatus
- type StopReason
Constants ¶
const MaxConcurrentRetries = 5
MaxConcurrentRetries limits the number of MCPServers that can be retried simultaneously. This prevents a "thundering herd" scenario where many failed servers retry at once, potentially overwhelming the system or upstream services.
Variables ¶
var HealthCheckInterval = config.DurationFromEnv("MUSTER_ORCHESTRATOR_HEALTH_CHECK_INTERVAL", 30*time.Second)
HealthCheckInterval is the time between two health probes of a connected MCPServer. Overridable via MUSTER_ORCHESTRATOR_HEALTH_CHECK_INTERVAL (a Go duration) so the integration test harness can observe the recovery without waiting for production-length ticks. Each probe is bounded by the server's own timeout (spec.timeout), see mcpserver.Service.CheckHealth.
var RetryInterval = config.DurationFromEnv("MUSTER_ORCHESTRATOR_RETRY_INTERVAL", 30*time.Second)
RetryInterval is the interval at which the orchestrator checks for failed servers to retry. Overridable via MUSTER_ORCHESTRATOR_RETRY_INTERVAL (a Go duration, e.g. "1s") so the integration test harness can pick up expired backoffs promptly instead of waiting for the next production-length tick.
var ShutdownTimeout = 20 * time.Second
ShutdownTimeout bounds how long Stop waits for the services to stop. It stays below the pod's default termination grace period (30 s), so muster exits on its own rather than by SIGKILL.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter adapts the orchestrator to implement api.ServiceManagerHandler.
func NewAPIAdapter ¶
func NewAPIAdapter(orchestrator *Orchestrator) *Adapter
NewAPIAdapter creates a new orchestrator adapter.
func (*Adapter) ExecuteTool ¶
func (a *Adapter) ExecuteTool(ctx context.Context, toolName string, args map[string]interface{}) (*api.CallToolResult, error)
ExecuteTool executes a tool by name.
func (*Adapter) GetAllServices ¶
func (a *Adapter) GetAllServices() []api.ServiceStatus
GetAllServices returns the status of all services.
func (*Adapter) GetServiceStatus ¶
func (a *Adapter) GetServiceStatus(name string) (*api.ServiceStatus, error)
GetServiceStatus returns the current status of a service.
func (*Adapter) GetTools ¶
func (a *Adapter) GetTools() []api.ToolMetadata
GetTools returns all tools this provider offers.
func (*Adapter) Register ¶
func (a *Adapter) Register()
Register registers the adapter with the API.
func (*Adapter) RemoveService ¶
func (*Adapter) RestartService ¶
func (*Adapter) StartService ¶
Service lifecycle management.
func (*Adapter) StopService ¶
func (*Adapter) SubscribeToStateChanges ¶
func (a *Adapter) SubscribeToStateChanges() <-chan api.ServiceStateChangedEvent
type Config ¶
type Config struct {
Aggregator config.AggregatorConfig
// KubernetesMode reports whether muster runs against an apiserver. It comes
// from the MusterClient rather than from the config flag, so a configured
// Kubernetes mode that fell back to the filesystem keeps stdio working.
KubernetesMode bool
// Namespace is muster's namespace (the configured namespace setting).
Namespace string
}
Config holds the configuration for the orchestrator.
type Orchestrator ¶
type Orchestrator struct {
// contains filtered or unexported fields
}
Orchestrator manages the lifecycle of static services registered in the service registry (MCPServer services and the aggregator service).
func (*Orchestrator) GetAllServices ¶
func (o *Orchestrator) GetAllServices() []ServiceStatus
GetAllServices returns status for all services.
func (*Orchestrator) GetServiceRegistry ¶
func (o *Orchestrator) GetServiceRegistry() services.ServiceRegistry
GetServiceRegistry returns the service registry.
func (*Orchestrator) GetServiceStatus ¶
func (o *Orchestrator) GetServiceStatus(name string) (*ServiceStatus, error)
GetServiceStatus returns the status of a specific service.
func (*Orchestrator) RemoveService ¶
func (o *Orchestrator) RemoveService(name string) error
RemoveService stops a service and removes it from the registry. This is used when a service definition is deleted, so that a later re-create with the same name is reconciled as a fresh service instead of matching the stale registry entry.
func (*Orchestrator) RestartService ¶
func (o *Orchestrator) RestartService(name string) error
RestartService restarts a specific service by name.
func (*Orchestrator) Start ¶
func (o *Orchestrator) Start(ctx context.Context) error
Start initializes and starts all registered static services and creates auto-start MCPServer services from MCPServer definitions.
func (*Orchestrator) StartService ¶
func (o *Orchestrator) StartService(name string) error
StartService starts a specific service by name. For MCP servers, this method waits for the server to be fully registered with the aggregator before returning, ensuring that tools are available.
func (*Orchestrator) Stop ¶
func (o *Orchestrator) Stop() error
Stop gracefully stops the orchestrator and every registered service within shutdownTimeout. It ends the maintenance loop first, so no retry restarts a server while it is being stopped, then stops the services in reverse dependency order (see shutdownWaves), and only then cancels the services' context: the aggregator's background routines run on it, and its Stop has to drain in-flight requests, stop the credential provider, close Valkey and release device-code leases before they go. A service whose Stop overruns the timeout is left behind, so a stuck one cannot hold the process past the pod's termination grace period.
func (*Orchestrator) StopService ¶
func (o *Orchestrator) StopService(name string) error
StopService stops a specific service by name.
func (*Orchestrator) SubscribeToStateChanges ¶
func (o *Orchestrator) SubscribeToStateChanges() <-chan ServiceStateChangedEvent
SubscribeToStateChanges returns a channel for state change events.
type ServiceStateChangedEvent ¶
type ServiceStateChangedEvent struct {
Name string
ServiceType string
OldState string
NewState string
Health string
Error error
Timestamp int64
}
ServiceStateChangedEvent represents a service state change event.
type ServiceStatus ¶
ServiceStatus represents the status of a service.
type StopReason ¶
type StopReason int
StopReason tracks why a service was stopped.
const ( StopReasonManual StopReason = iota StopReasonDependency )