|
8 | 8 | "github.com/cloudhut/kminion/v2/kafka" |
9 | 9 | "github.com/google/uuid" |
10 | 10 | "github.com/prometheus/client_golang/prometheus" |
11 | | - "github.com/prometheus/client_golang/prometheus/promauto" |
12 | 11 | "github.com/twmb/franz-go/pkg/kgo" |
13 | 12 | "go.uber.org/zap" |
14 | 13 | ) |
@@ -44,7 +43,7 @@ type Service struct { |
44 | 43 | } |
45 | 44 |
|
46 | 45 | // NewService creates a new instance of the e2e moinitoring service (wow) |
47 | | -func NewService(ctx context.Context, cfg Config, logger *zap.Logger, kafkaSvc *kafka.Service, metricNamespace string) (*Service, error) { |
| 46 | +func NewService(ctx context.Context, cfg Config, logger *zap.Logger, kafkaSvc *kafka.Service, promRegisterer prometheus.Registerer) (*Service, error) { |
48 | 47 | minionID := uuid.NewString() |
49 | 48 | groupID := fmt.Sprintf("%v-%v", cfg.Consumer.GroupIdPrefix, minionID) |
50 | 49 |
|
@@ -94,29 +93,32 @@ func NewService(ctx context.Context, cfg Config, logger *zap.Logger, kafkaSvc *k |
94 | 93 | svc.messageTracker = newMessageTracker(svc) |
95 | 94 |
|
96 | 95 | makeCounterVec := func(name string, labelNames []string, help string) *prometheus.CounterVec { |
97 | | - return promauto.NewCounterVec(prometheus.CounterOpts{ |
98 | | - Namespace: metricNamespace, |
| 96 | + cv := prometheus.NewCounterVec(prometheus.CounterOpts{ |
99 | 97 | Subsystem: "end_to_end", |
100 | 98 | Name: name, |
101 | 99 | Help: help, |
102 | 100 | }, labelNames) |
| 101 | + promRegisterer.MustRegister(cv) |
| 102 | + return cv |
103 | 103 | } |
104 | 104 | makeGaugeVec := func(name string, labelNames []string, help string) *prometheus.GaugeVec { |
105 | | - return promauto.NewGaugeVec(prometheus.GaugeOpts{ |
106 | | - Namespace: metricNamespace, |
| 105 | + gv := prometheus.NewGaugeVec(prometheus.GaugeOpts{ |
107 | 106 | Subsystem: "end_to_end", |
108 | 107 | Name: name, |
109 | 108 | Help: help, |
110 | 109 | }, labelNames) |
| 110 | + promRegisterer.MustRegister(gv) |
| 111 | + return gv |
111 | 112 | } |
112 | 113 | makeHistogramVec := func(name string, maxLatency time.Duration, labelNames []string, help string) *prometheus.HistogramVec { |
113 | | - return promauto.NewHistogramVec(prometheus.HistogramOpts{ |
114 | | - Namespace: metricNamespace, |
| 114 | + hv := prometheus.NewHistogramVec(prometheus.HistogramOpts{ |
115 | 115 | Subsystem: "end_to_end", |
116 | 116 | Name: name, |
117 | 117 | Help: help, |
118 | 118 | Buckets: createHistogramBuckets(maxLatency), |
119 | 119 | }, labelNames) |
| 120 | + promRegisterer.MustRegister(hv) |
| 121 | + return hv |
120 | 122 | } |
121 | 123 |
|
122 | 124 | // Low-level info |
@@ -178,7 +180,6 @@ func (s *Service) Start(ctx context.Context) error { |
178 | 180 | case <-initCh: |
179 | 181 | isInitialized = true |
180 | 182 | s.logger.Info("consumer has been successfully initialized") |
181 | | - break |
182 | 183 | case <-ctx.Done(): |
183 | 184 | return nil |
184 | 185 | } |
|
0 commit comments