// Replay the batch data from a single source func (r *replayBatchSource) replayBatchFromData(data io.ReadCloser, batch BatchCollector, recTime bool) { defer batch.Close() defer data.Close() in := bufio.NewScanner(data) // Find relative times start := time.Time{} var diff time.Duration zero := r.clck.Zero() for in.Scan() { var b models.Batch err := json.Unmarshal(in.Bytes(), &b) if err != nil { r.allErrs <- err return } if len(b.Points) == 0 { // do nothing continue } b.Group = models.TagsToGroupID(models.SortedKeys(b.Tags), b.Tags) if start.IsZero() { start = b.Points[0].Time diff = zero.Sub(start) } // Add tags to all points if len(b.Tags) > 0 { for i := range b.Points { if len(b.Points[i].Tags) == 0 { b.Points[i].Tags = b.Tags } } } var lastTime time.Time if !recTime { for i := range b.Points { b.Points[i].Time = b.Points[i].Time.Add(diff).UTC() } lastTime = b.Points[len(b.Points)-1].Time } else { lastTime = b.Points[len(b.Points)-1].Time.Add(diff).UTC() } r.clck.Until(lastTime) b.TMax = b.Points[len(b.Points)-1].Time batch.CollectBatch(b) } r.allErrs <- in.Err() }
// Replay the batch data from a single source func readBatchFromIO(data io.ReadCloser, batches chan<- models.Batch) error { defer close(batches) defer data.Close() dec := json.NewDecoder(data) for dec.More() { var b models.Batch err := dec.Decode(&b) if err != nil { return err } if len(b.Points) == 0 { // do nothing continue } if b.Group == "" { b.Group = models.ToGroupID( b.Name, b.Tags, models.Dimensions{ ByName: b.ByName, TagNames: models.SortedKeys(b.Tags), }, ) } // Add tags to all points if len(b.Tags) > 0 { for i := range b.Points { if len(b.Points[i].Tags) == 0 { b.Points[i].Tags = b.Tags } } } batches <- b } return nil }