SeriesChunksToMatrix converts slice of []client.TimeSeriesChunk to a model.Matrix.
(from, through model.Time, serieses []client.TimeSeriesChunk)
| 16 | |
| 17 | // SeriesChunksToMatrix converts slice of []client.TimeSeriesChunk to a model.Matrix. |
| 18 | func SeriesChunksToMatrix(from, through model.Time, serieses []client.TimeSeriesChunk) (model.Matrix, error) { |
| 19 | if serieses == nil { |
| 20 | return nil, nil |
| 21 | } |
| 22 | |
| 23 | result := model.Matrix{} |
| 24 | for _, series := range serieses { |
| 25 | metric := cortexpb.FromLabelAdaptersToMetric(series.Labels) |
| 26 | chunks, err := FromChunks(cortexpb.FromLabelAdaptersToLabels(series.Labels), series.Chunks) |
| 27 | if err != nil { |
| 28 | return nil, err |
| 29 | } |
| 30 | |
| 31 | its := make([]chunkenc.Iterable, 0, len(chunks)) |
| 32 | samples := []model.SamplePair{} |
| 33 | for _, chk := range chunks { |
| 34 | its = append(its, chk.Data) |
| 35 | } |
| 36 | it := storage.ChainSampleIteratorFromIterables(nil, its) |
| 37 | for it.Next() != chunkenc.ValNone { |
| 38 | t, v := it.At() |
| 39 | if model.Time(t) < from { |
| 40 | continue |
| 41 | } |
| 42 | if model.Time(t) > through { |
| 43 | break |
| 44 | } |
| 45 | samples = append(samples, model.SamplePair{Timestamp: model.Time(t), Value: model.SampleValue(v)}) |
| 46 | } |
| 47 | if err := it.Err(); err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | |
| 51 | result = append(result, &model.SampleStream{ |
| 52 | Metric: metric, |
| 53 | Values: samples, |
| 54 | }) |
| 55 | } |
| 56 | return result, nil |
| 57 | } |
| 58 | |
| 59 | // FromChunks converts []client.Chunk to []chunk.Chunk. |
| 60 | func FromChunks(metric labels.Labels, in []client.Chunk) ([]chunk.Chunk, error) { |