1 // Package provider provides a factory-like abstraction for metrics backends. 2 // This package is provided specifically for the needs of the NY Times framework 3 // Gizmo. Most normal Go kit users shouldn't need to use it. 4 // 5 // Normally, if your microservice needs to support different metrics backends, 6 // you can simply do different construction based on a flag. For example, 7 // 8 // var latency metrics.Histogram 9 // var requests metrics.Counter 10 // switch *metricsBackend { 11 // case "prometheus": 12 // latency = prometheus.NewSummaryVec(...) 13 // requests = prometheus.NewCounterVec(...) 14 // case "statsd": 15 // s := statsd.New(...) 16 // t := time.NewTicker(5*time.Second) 17 // go s.SendLoop(ctx, t.C, "tcp", "statsd.local:8125") 18 // latency = s.NewHistogram(...) 19 // requests = s.NewCounter(...) 20 // default: 21 // log.Fatal("unsupported metrics backend %q", *metricsBackend) 22 // } 23 // 24 package provider 25 26 import ( 27 "github.com/go-kit/kit/metrics" 28 ) 29 30 // Provider abstracts over constructors and lifecycle management functions for 31 // each supported metrics backend. It should only be used by those who need to 32 // swap out implementations dynamically. 33 // 34 // This is primarily useful for intermediating frameworks, and is likely 35 // unnecessary for most Go kit services. See the package-level doc comment for 36 // more typical usage instructions. 37 type Provider interface { 38 NewCounter(name string) metrics.Counter 39 NewGauge(name string) metrics.Gauge 40 NewHistogram(name string, buckets int) metrics.Histogram 41 Stop() 42 } 43