Skip to content

Commit 7c5bb31

Browse files
author
amuraru
committed
[INTERNAL] Log scrape timing
1 parent ed86638 commit 7c5bb31

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

prometheus/exporter.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
281281
}
282282

283283
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
284+
startTime := time.Now()
284285
ctx, cancel := context.WithTimeout(context.Background(), time.Second*180)
285286
defer cancel()
286287

@@ -297,9 +298,19 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
297298
ok = e.collectConsumerGroupLags(ctx, ch) && ok
298299
ok = e.collectTopicInfo(ctx, ch) && ok
299300

301+
duration := time.Since(startTime)
302+
300303
if ok {
301304
ch <- prometheus.MustNewConstMetric(e.exporterUp, prometheus.GaugeValue, 1.0)
305+
e.logger.Info("Completed Kafka metrics scrape successfully",
306+
zap.String("request_id", uuid.String()),
307+
zap.Duration("duration", duration),
308+
zap.Float64("duration_seconds", duration.Seconds()))
302309
} else {
303310
ch <- prometheus.MustNewConstMetric(e.exporterUp, prometheus.GaugeValue, 0.0)
311+
e.logger.Warn("Completed Kafka metrics scrape with errors",
312+
zap.String("request_id", uuid.String()),
313+
zap.Duration("duration", duration),
314+
zap.Float64("duration_seconds", duration.Seconds()))
304315
}
305316
}

0 commit comments

Comments
 (0)