Go Language Concepts Used in Jaeger-lib
Interfaces
The jaeger-lib
library makes extensive use of interfaces to achieve abstraction and polymorphism. Interfaces define contracts that can be implemented by various concrete types. This allows for flexible and extensible code, as different implementations can be used interchangeably.
Example: The metrics/go-kit/factory.go
file defines the Factory
interface:
// Factory provides a unified interface for creating named metrics
// from various go-kit metrics implementations.
type Factory interface {
Counter(name string) kit.Counter
Gauge(name string) kit.Gauge
Histogram(name string) kit.Histogram
Capabilities() Capabilities
}
This interface is implemented by concrete factories, like genericFactory
and noTagsFactory
, allowing for different metrics backends to be plugged in.
Concurrency
The jaeger-lib
library utilizes Go’s concurrency features, such as goroutines and channels, to handle concurrent operations efficiently. Goroutines are lightweight threads managed by the Go runtime, enabling parallel execution of code. Channels provide a safe way to communicate between goroutines.
Example: The metrics/multi/multi.go
file implements the counter
struct, which aggregates values from multiple underlying counters. It uses a goroutine to update the aggregated value concurrently:
type counter struct {
counters []metrics.Counter
}
// Inc increments the counter.
func (c *counter) Inc(n int64) {
for _, counter := range c.counters {
go func(c metrics.Counter) {
c.Inc(n)
}(counter)
}
}
References:
Top-Level Directory Explanations
client/ - This directory contains the client-side code for the Jaeger Tracing library.
client/log/ - This subdirectory contains the logging implementation for the client-side code.
client/log/go-kit/ - This subdirectory of the logging implementation contains the Go-Kit logging adapter.
metrics/ - This directory contains the metrics implementation for the Jaeger Tracing library.
metrics/adapters/ - This subdirectory contains the various metric adapters for different backends.
metrics/go-kit/ - This subdirectory contains the Go-Kit integration for the Jaeger Tracing library.
metrics/go-kit/expvar/ - This subdirectory contains the expvar implementation for the Go-Kit integration.
metrics/go-kit/influx/ - This subdirectory contains the InfluxDB implementation for the Go-Kit integration.
metrics/metricstest/ - This subdirectory contains the testing implementation for the metrics.
metrics/multi/ - This subdirectory contains the implementation for collecting metrics from multiple sources.
metrics/tally/ - This subdirectory contains the implementation for counting metrics using the tally package.
sample/ - This directory contains a sample implementation for the Jaeger Tracing library.