Path: blob/main/memory-bank/components/ws-manager-bridge.md
2487 views
Workspace Manager Bridge Component
Overview
The Workspace Manager Bridge (ws-manager-bridge) is a critical component in the Gitpod architecture that acts as an intermediary between the workspace manager (ws-manager) and the rest of the Gitpod platform. It subscribes to workspace status updates from the workspace manager, processes these updates, and synchronizes the information with the database and other components of the system.
Purpose
The primary purposes of the Workspace Manager Bridge component are:
Subscribe to workspace status updates from workspace managers
Process and transform workspace status information
Update the database with current workspace instance states
Trigger appropriate actions based on workspace lifecycle events
Provide metrics and monitoring for workspace instances
Manage workspace cluster information and available workspace classes
Bridge the communication between workspace managers and other Gitpod components
Handle prebuild status updates and synchronization
Expose a gRPC service for cluster management
Architecture
The Workspace Manager Bridge consists of several key components:
Bridge Controller: Manages the lifecycle of bridges to workspace clusters
Workspace Manager Bridge: Handles status updates from workspace managers
Workspace Instance Controller: Controls workspace instances based on their state
Prebuild Updater: Updates prebuild information based on workspace status
Cluster Service Server: Provides a gRPC service for cluster management
Metrics: Collects and exposes metrics about workspace instances
The component is designed to be resilient to failures, with mechanisms for reconnection, message queuing, and error handling.
Key Files and Structure
src/main.ts
: Entry point for the applicationsrc/bridge.ts
: Core implementation of the workspace manager bridgesrc/bridge-controller.ts
: Controls bridges to workspace clusterssrc/workspace-instance-controller.ts
: Controls workspace instancessrc/prebuild-updater.ts
: Updates prebuild informationsrc/cluster-service-server.ts
: gRPC service for cluster managementsrc/wsman-subscriber.ts
: Subscribes to workspace manager eventssrc/metrics.ts
: Metrics collection and reportingsrc/config.ts
: Configuration for the componentsrc/container-module.ts
: Dependency injection setup
Workflow
The Workspace Manager Bridge follows this general workflow:
Initialization:
Connect to the database
Set up metrics and tracing
Start the bridge controller
Start the cluster service server
Start the workspace instance controller
Status Update Handling:
Subscribe to status updates from workspace managers
Queue updates by instance ID to ensure proper ordering
Process updates and update the database
Trigger appropriate actions based on workspace lifecycle events
Update prebuild information if necessary
Publish instance updates to Redis for other components
Workspace Instance Control:
Periodically check workspace instances
Enforce timeouts and other policies
Handle stopped workspaces
Workspace Class Management:
Periodically update workspace class information from clusters
Store updated information in the database
Status Update Processing
The bridge processes workspace status updates from the workspace manager and maps them to the Gitpod data model:
Phase Mapping: Maps workspace phases (PENDING, CREATING, INITIALIZING, RUNNING, STOPPING, STOPPED) to the corresponding database representation
Condition Mapping: Maps workspace conditions (deployed, failed, timeout, etc.) to the database
Port Mapping: Maps exposed ports and their visibility/protocol
Timestamp Recording: Records important timestamps (started, deployed, stopped)
Metrics Collection: Collects metrics about workspace instances
Lifecycle Handling: Triggers appropriate actions based on lifecycle events
Dependencies
Internal Dependencies
@gitpod/gitpod-db
: Database access@gitpod/gitpod-protocol
: Shared protocol definitions@gitpod/ws-manager
: Workspace manager client@gitpod/ws-manager-bridge-api
: Bridge API definitions@gitpod/ws-daemon
: Workspace daemon client
External Dependencies
Express for metrics endpoint
Prometheus client for metrics
gRPC for communication with workspace managers
Redis for publishing instance updates
Integration Points
The Workspace Manager Bridge integrates with:
Workspace Manager: Subscribes to workspace status updates
Database: Updates workspace instance information
Redis: Publishes instance updates for other components
Prometheus: Exposes metrics
Other Gitpod Components: Provides workspace status information
Configuration
The Workspace Manager Bridge is configured through environment variables:
CONTROLLER_INTERVAL_SECONDS
: Interval for controller operationsCONTROLLER_MAX_DISCONNECT_SECONDS
: Maximum time to wait for reconnectionVarious database and connection settings
Metrics
The component exposes various metrics:
Workspace instance status updates
Workspace startup time
First user activity
Stale status updates
Update processing time
Error counts
Common Usage Patterns
The Workspace Manager Bridge is typically used to:
Monitor workspace instance status
Update the database with current workspace states
Trigger actions based on workspace lifecycle events
Collect metrics about workspace instances
Manage workspace cluster information
Related Components
Workspace Manager: Manages workspace instances in Kubernetes
Workspace Daemon: Manages workspace-level operations
Database: Stores workspace instance information
Server: Uses workspace instance information for API responses
Dashboard: Displays workspace status to users