From f61c9f5df987095866caed30c14d1835e831edd0 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 18 Jun 2025 08:34:33 +0200 Subject: [PATCH] draft prometheus update booking... --- infrastructure/prometheus.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/infrastructure/prometheus.go b/infrastructure/prometheus.go index 27232ff..9c154b8 100644 --- a/infrastructure/prometheus.go +++ b/infrastructure/prometheus.go @@ -134,11 +134,10 @@ func (p *PrometheusService) Call(bookingID string) (*booking.Booking, map[string func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval time.Duration, flusher http.Flusher, encoder *json.Encoder) { if end != nil { max := 100 - count := 0 + bookIDS := []string{} mets := map[string][]models.MetricsSnapshot{} for time.Now().Before(*end) { go func() { - count++ book, metrics := p.Call(bookingID) for k, v := range metrics { if me, ok := mets[k]; !ok { @@ -148,9 +147,10 @@ func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval ti mets[k] = me } } + bookIDS = append(bookIDS, bookingID) encoder.Encode(metrics) flusher.Flush() - if count == max { + if len(bookIDS) == max { if book.ExecutionMetrics == nil { book.ExecutionMetrics = mets } else { @@ -164,6 +164,7 @@ func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval ti } } book.GetAccessor(nil).UpdateOne(book, bookingID) + bookIDS = []string{} } }() time.Sleep(interval)