pub struct RingKernelContext { /* private fields */ }Expand description
Unified runtime context managing all enterprise features.
This is the main entry point for using RingKernel’s enterprise features. It instantiates and manages:
- Health checking and circuit breakers
- Prometheus metrics exporter
- Multi-GPU coordination
- Kernel migration infrastructure
- Background monitoring tasks
§Lifecycle
The runtime goes through these states:
Initializing→Running→Draining→ShuttingDown→Stopped
Use start_monitoring() to begin background health checks and watchdog scans.
Use shutdown() for graceful termination.
Implementations§
Source§impl RingKernelContext
impl RingKernelContext
Sourcepub fn config(&self) -> &RingKernelConfig
pub fn config(&self) -> &RingKernelConfig
Get the configuration.
Sourcepub fn health_checker(&self) -> Arc<HealthChecker>
pub fn health_checker(&self) -> Arc<HealthChecker>
Get the health checker.
Sourcepub fn watchdog(&self) -> Arc<KernelWatchdog>
pub fn watchdog(&self) -> Arc<KernelWatchdog>
Get the kernel watchdog.
Sourcepub fn circuit_breaker(&self) -> Arc<CircuitBreaker>
pub fn circuit_breaker(&self) -> Arc<CircuitBreaker>
Get the circuit breaker.
Sourcepub fn degradation_manager(&self) -> Arc<DegradationManager>
pub fn degradation_manager(&self) -> Arc<DegradationManager>
Get the degradation manager.
Sourcepub fn prometheus_exporter(&self) -> Arc<PrometheusExporter>
pub fn prometheus_exporter(&self) -> Arc<PrometheusExporter>
Get the Prometheus exporter.
Sourcepub fn observability(&self) -> Arc<ObservabilityContext>
pub fn observability(&self) -> Arc<ObservabilityContext>
Get the observability context.
Sourcepub fn multi_gpu_coordinator(&self) -> Arc<MultiGpuCoordinator>
pub fn multi_gpu_coordinator(&self) -> Arc<MultiGpuCoordinator>
Get the multi-GPU coordinator.
Sourcepub fn migrator(&self) -> Arc<KernelMigrator>
pub fn migrator(&self) -> Arc<KernelMigrator>
Get the kernel migrator.
Sourcepub fn checkpoint_storage(&self) -> Arc<dyn CheckpointStorage>
pub fn checkpoint_storage(&self) -> Arc<dyn CheckpointStorage>
Get the checkpoint storage.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the runtime is running.
Sourcepub fn stats(&self) -> RuntimeStatsSnapshot
pub fn stats(&self) -> RuntimeStatsSnapshot
Get runtime statistics.
Sourcepub fn record_kernel_launch(&self)
pub fn record_kernel_launch(&self)
Record a kernel launch.
Sourcepub fn record_messages(&self, count: u64)
pub fn record_messages(&self, count: u64)
Record messages processed.
Sourcepub fn record_migration(&self)
pub fn record_migration(&self)
Record a migration completion.
Sourcepub fn record_checkpoint(&self)
pub fn record_checkpoint(&self)
Record a checkpoint creation.
Sourcepub fn record_health_check(&self)
pub fn record_health_check(&self)
Record a health check run.
Sourcepub fn record_circuit_trip(&self)
pub fn record_circuit_trip(&self)
Record a circuit breaker trip.
Sourcepub fn lifecycle_state(&self) -> LifecycleState
pub fn lifecycle_state(&self) -> LifecycleState
Get the current lifecycle state.
Sourcepub fn is_shutdown_requested(&self) -> bool
pub fn is_shutdown_requested(&self) -> bool
Check if shutdown has been requested.
Sourcepub fn is_accepting_work(&self) -> bool
pub fn is_accepting_work(&self) -> bool
Check if the runtime is accepting new work.
Sourcepub fn start(&self) -> Result<()>
pub fn start(&self) -> Result<()>
Transition to running state.
Call this after initialization is complete to start accepting work.
Sourcepub fn run_health_check_cycle(&self) -> HealthCycleResult
pub fn run_health_check_cycle(&self) -> HealthCycleResult
Run a single health check cycle.
This performs one round of health checks and updates the circuit breaker and degradation manager based on the results.
Note: This is a synchronous method that uses cached circuit breaker state. For full async health checks, use the HealthChecker directly.
Sourcepub fn run_watchdog_cycle(&self) -> WatchdogResult
pub fn run_watchdog_cycle(&self) -> WatchdogResult
Run a single watchdog scan cycle.
This checks for stale kernels and takes appropriate action.
Sourcepub fn flush_metrics(&self) -> String
pub fn flush_metrics(&self) -> String
Flush metrics to Prometheus.
This renders current metrics to the Prometheus exporter format.
Sourcepub fn background_task_status(&self) -> BackgroundTaskStatus
pub fn background_task_status(&self) -> BackgroundTaskStatus
Get background task status.
Sourcepub fn start_monitoring(
self: &Arc<Self>,
config: MonitoringConfig,
) -> MonitoringHandles
pub fn start_monitoring( self: &Arc<Self>, config: MonitoringConfig, ) -> MonitoringHandles
Start background monitoring loops.
This spawns async tasks for:
- Health check loop (runs at configured interval)
- Watchdog loop (checks for stale kernels)
- Metrics flush loop (exports Prometheus metrics)
Returns handles that can be used to stop the monitoring tasks.
§Example
let runtime = RuntimeBuilder::new().production().build()?;
runtime.start()?;
let config = MonitoringConfig::new()
.health_check_interval(Duration::from_secs(5))
.watchdog_interval(Duration::from_secs(2));
let handles = runtime.start_monitoring(config).await;
// ... runtime runs ...
// Graceful shutdown
handles.signal_shutdown();
handles.wait_for_shutdown().await;Sourcepub fn start_monitoring_default(self: &Arc<Self>) -> MonitoringHandles
pub fn start_monitoring_default(self: &Arc<Self>) -> MonitoringHandles
Start monitoring with default configuration.
Sourcepub fn request_shutdown(&self) -> Result<()>
pub fn request_shutdown(&self) -> Result<()>
Request graceful shutdown.
This signals background tasks to stop and transitions to draining state.
Returns immediately; use wait_for_shutdown() to block until complete.
Sourcepub fn complete_shutdown(&self) -> Result<ShutdownReport>
pub fn complete_shutdown(&self) -> Result<ShutdownReport>
Complete the shutdown process.
This performs final cleanup and transitions to stopped state.
Source§impl RingKernelContext
impl RingKernelContext
Sourcepub fn export_metrics(&self) -> String
pub fn export_metrics(&self) -> String
Export Prometheus metrics.
Sourcepub fn metrics_snapshot(&self) -> ContextMetrics
pub fn metrics_snapshot(&self) -> ContextMetrics
Create a metrics snapshot for the runtime context.