draft prometheus update booking...
This commit is contained in:
parent
c7290b0ead
commit
f61c9f5df9
@ -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) {
|
func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval time.Duration, flusher http.Flusher, encoder *json.Encoder) {
|
||||||
if end != nil {
|
if end != nil {
|
||||||
max := 100
|
max := 100
|
||||||
count := 0
|
bookIDS := []string{}
|
||||||
mets := map[string][]models.MetricsSnapshot{}
|
mets := map[string][]models.MetricsSnapshot{}
|
||||||
for time.Now().Before(*end) {
|
for time.Now().Before(*end) {
|
||||||
go func() {
|
go func() {
|
||||||
count++
|
|
||||||
book, metrics := p.Call(bookingID)
|
book, metrics := p.Call(bookingID)
|
||||||
for k, v := range metrics {
|
for k, v := range metrics {
|
||||||
if me, ok := mets[k]; !ok {
|
if me, ok := mets[k]; !ok {
|
||||||
@ -148,9 +147,10 @@ func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval ti
|
|||||||
mets[k] = me
|
mets[k] = me
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bookIDS = append(bookIDS, bookingID)
|
||||||
encoder.Encode(metrics)
|
encoder.Encode(metrics)
|
||||||
flusher.Flush()
|
flusher.Flush()
|
||||||
if count == max {
|
if len(bookIDS) == max {
|
||||||
if book.ExecutionMetrics == nil {
|
if book.ExecutionMetrics == nil {
|
||||||
book.ExecutionMetrics = mets
|
book.ExecutionMetrics = mets
|
||||||
} else {
|
} else {
|
||||||
@ -164,6 +164,7 @@ func (p *PrometheusService) Stream(bookingID string, end *time.Time, interval ti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
book.GetAccessor(nil).UpdateOne(book, bookingID)
|
book.GetAccessor(nil).UpdateOne(book, bookingID)
|
||||||
|
bookIDS = []string{}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
time.Sleep(interval)
|
time.Sleep(interval)
|
||||||
|
Loading…
Reference in New Issue
Block a user