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)