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.
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
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.
- Standard server implementation with HTTP and gRPC support
- Consistent configuration and option handling
- Health check endpoints
- Graceful shutdown
- Metrics integration
- Structured logging based on logrus
- Context-aware logging
- Log level management
- Field-based logging
- Metrics integration for log counts
- Distributed tracing with OpenTelemetry
- Span creation and management
- Context propagation
- Prometheus integration for tracing metrics
- Standard gRPC server and client configuration
- Authentication and authorization middleware
- Rate limiting
- Error handling
- Metrics collection
- Kubernetes client configuration
- Custom resource definitions
- Controller patterns
- Informer and lister utilities
- Event tracking
- User and session identification
- Batch processing of analytics events
- Privacy-aware data collection
- Feature flag management
- A/B testing support
- Gradual rollout capabilities
- User segmentation
- Prometheus metrics collection
- Standard metric types (counters, gauges, histograms)
- Metric registration and exposure
- Label standardization
- String manipulation
- Time handling
- Error wrapping
- JSON utilities
- Network helpers
components/scrubber
: For data scrubbing and sanitization
- Kubernetes client libraries
- gRPC and related libraries
- Prometheus client
- OpenTelemetry
- Logrus for logging
- Various utility libraries
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
srv, err := baseserver.New("service-name",
baseserver.WithVersion(version),
baseserver.WithConfig(cfg.Server),
)
if err != nil {
log.WithError(err).Fatal("failed to initialize server")
}
log.WithFields(log.Fields{
"user": userID,
"workspace": workspaceID,
}).Info("workspace started")
span, ctx := tracing.FromContext(ctx, "operation-name")
defer span.Finish()
span.SetTag("key", "value")
counter := prometheus.NewCounter(prometheus.CounterOpts{
Name: "operation_total",
Help: "Total number of operations performed",
})
metrics.Registry.MustRegister(counter)
counter.Inc()
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
- 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