SeriesSetToQueryResponse builds a QueryResponse proto
(s storage.SeriesSet)
| 112 | |
| 113 | // SeriesSetToQueryResponse builds a QueryResponse proto |
| 114 | func SeriesSetToQueryResponse(s storage.SeriesSet) (*QueryResponse, error) { |
| 115 | result := &QueryResponse{} |
| 116 | |
| 117 | var it chunkenc.Iterator |
| 118 | for s.Next() { |
| 119 | series := s.At() |
| 120 | samples := []cortexpb.Sample{} |
| 121 | histograms := []cortexpb.WrappedHistogram{} |
| 122 | it = series.Iterator(it) |
| 123 | for valType := it.Next(); valType != chunkenc.ValNone; valType = it.Next() { |
| 124 | switch valType { |
| 125 | case chunkenc.ValFloat: |
| 126 | t, v := it.At() |
| 127 | samples = append(samples, cortexpb.Sample{ |
| 128 | TimestampMs: t, |
| 129 | Value: v, |
| 130 | }) |
| 131 | case chunkenc.ValHistogram: |
| 132 | t, v := it.AtHistogram(nil) |
| 133 | histograms = append(histograms, cortexpb.WrappedHistogram{Histogram: cortexpb.HistogramToHistogramProto(t, v)}) |
| 134 | case chunkenc.ValFloatHistogram: |
| 135 | t, v := it.AtFloatHistogram(nil) |
| 136 | histograms = append(histograms, cortexpb.WrappedHistogram{Histogram: cortexpb.FloatHistogramToHistogramProto(t, v)}) |
| 137 | default: |
| 138 | panic("unhandled default case") |
| 139 | } |
| 140 | } |
| 141 | if err := it.Err(); err != nil { |
| 142 | return nil, err |
| 143 | } |
| 144 | ts := cortexpb.TimeSeries{ |
| 145 | Labels: cortexpb.FromLabelsToLabelAdapters(series.Labels()), |
| 146 | } |
| 147 | if len(samples) > 0 { |
| 148 | ts.Samples = samples |
| 149 | } |
| 150 | if len(histograms) > 0 { |
| 151 | ts.Histograms = histograms |
| 152 | } |
| 153 | result.Timeseries = append(result.Timeseries, ts) |
| 154 | } |
| 155 | |
| 156 | return result, s.Err() |
| 157 | } |
| 158 | |
| 159 | // FromMetricsForLabelMatchersRequest unpacks a MetricsForLabelMatchersRequest proto |
| 160 | func FromMetricsForLabelMatchersRequest(cache storecache.MatchersCache, req *MetricsForLabelMatchersRequest) (model.Time, model.Time, int, [][]*labels.Matcher, error) { |