Common-Go Component
Overview
The Common-Go component is a foundational Go library that provides shared utilities, abstractions, and functionality used across multiple Gitpod services. It serves as a central repository for common code patterns, helping to maintain consistency, reduce duplication, and simplify development across the Gitpod platform's Go-based microservices.
Purpose
The primary purposes of the Common-Go component are:
Provide shared utilities and abstractions for Gitpod's Go-based services
Ensure consistent implementation of cross-cutting concerns
Reduce code duplication across services
Simplify service development with ready-to-use components
Standardize logging, metrics, tracing, and server configuration
Offer common patterns for Kubernetes integration
Provide utilities for gRPC communication
Support consistent error handling and debugging
Architecture
The Common-Go component is structured as a collection of Go packages, each focusing on a specific area of functionality:
Baseserver: Core server implementation with standardized configuration
Log: Structured logging utilities
Tracing: Distributed tracing functionality
gRPC: Utilities for gRPC communication
Kubernetes: Kubernetes client and utilities
Analytics: Analytics tracking and reporting
Experiments: Feature flag and experimentation support
Metrics: Prometheus metrics collection
Utilities: Various helper functions and utilities
The component is designed to be imported and used by other Go-based services in the Gitpod platform, providing a consistent foundation for service development.
Key Packages and Functionality
Baseserver
Standard server implementation with HTTP and gRPC support
Consistent configuration and option handling
Health check endpoints
Graceful shutdown
Metrics integration
Log
Structured logging based on logrus
Context-aware logging
Log level management
Field-based logging
Metrics integration for log counts
Tracing
Distributed tracing with OpenTelemetry
Span creation and management
Context propagation
Prometheus integration for tracing metrics
gRPC
Standard gRPC server and client configuration
Authentication and authorization middleware
Rate limiting
Error handling
Metrics collection
Kubernetes
Kubernetes client configuration
Custom resource definitions
Controller patterns
Informer and lister utilities
Analytics
Event tracking
User and session identification
Batch processing of analytics events
Privacy-aware data collection
Experiments
Feature flag management
A/B testing support
Gradual rollout capabilities
User segmentation
Metrics
Prometheus metrics collection
Standard metric types (counters, gauges, histograms)
Metric registration and exposure
Label standardization
Utilities
String manipulation
Time handling
Error wrapping
JSON utilities
Network helpers
Dependencies
Internal Dependencies
components/scrubber
: For data scrubbing and sanitization
External Dependencies
Kubernetes client libraries
gRPC and related libraries
Prometheus client
OpenTelemetry
Logrus for logging
Various utility libraries
Integration Points
The Common-Go component integrates with:
All Go-based Gitpod Services: Provides foundational functionality
Kubernetes: For cluster interaction and management
Prometheus: For metrics collection
Tracing Systems: For distributed tracing
Logging Systems: For centralized logging
Usage Patterns
Server Initialization
Logging
Tracing
Metrics
Common Usage Patterns
The Common-Go component is typically used to:
Initialize and configure services
Set up logging, metrics, and tracing
Interact with Kubernetes
Implement gRPC servers and clients
Handle cross-cutting concerns like authentication and rate limiting
Manage feature flags and experiments
Track analytics events
Related Components
All Go-based Services: Use the Common-Go component for foundational functionality
Kubernetes Components: Interact with Kubernetes using utilities from Common-Go
Monitoring Components: Use metrics and tracing from Common-Go