(t *testing.T, floatHistogram bool)
| 5147 | } |
| 5148 | |
| 5149 | func testHistogramStaleSampleHelper(t *testing.T, floatHistogram bool) { |
| 5150 | t.Helper() |
| 5151 | l := labels.FromStrings("a", "b") |
| 5152 | numHistograms := 20 |
| 5153 | head, _ := newTestHead(t, 100000, compression.None, false) |
| 5154 | t.Cleanup(func() { |
| 5155 | require.NoError(t, head.Close()) |
| 5156 | }) |
| 5157 | require.NoError(t, head.Init(0)) |
| 5158 | |
| 5159 | type timedHistogram struct { |
| 5160 | t int64 |
| 5161 | h *histogram.Histogram |
| 5162 | fh *histogram.FloatHistogram |
| 5163 | } |
| 5164 | expHistograms := make([]timedHistogram, 0, numHistograms) |
| 5165 | |
| 5166 | testQuery := func(numStale int) { |
| 5167 | q, err := NewBlockQuerier(head, head.MinTime(), head.MaxTime()) |
| 5168 | require.NoError(t, err) |
| 5169 | t.Cleanup(func() { |
| 5170 | require.NoError(t, q.Close()) |
| 5171 | }) |
| 5172 | |
| 5173 | ss := q.Select(context.Background(), false, nil, labels.MustNewMatcher(labels.MatchEqual, "a", "b")) |
| 5174 | |
| 5175 | require.True(t, ss.Next()) |
| 5176 | s := ss.At() |
| 5177 | require.False(t, ss.Next()) |
| 5178 | |
| 5179 | it := s.Iterator(nil) |
| 5180 | actHistograms := make([]timedHistogram, 0, len(expHistograms)) |
| 5181 | for typ := it.Next(); typ != chunkenc.ValNone; typ = it.Next() { |
| 5182 | switch typ { |
| 5183 | case chunkenc.ValHistogram: |
| 5184 | t, h := it.AtHistogram(nil) |
| 5185 | actHistograms = append(actHistograms, timedHistogram{t: t, h: h}) |
| 5186 | case chunkenc.ValFloatHistogram: |
| 5187 | t, h := it.AtFloatHistogram(nil) |
| 5188 | actHistograms = append(actHistograms, timedHistogram{t: t, fh: h}) |
| 5189 | } |
| 5190 | } |
| 5191 | |
| 5192 | // We cannot compare StaleNAN with require.Equal, hence checking each histogram manually. |
| 5193 | require.Len(t, actHistograms, len(expHistograms)) |
| 5194 | actNumStale := 0 |
| 5195 | for i, eh := range expHistograms { |
| 5196 | ah := actHistograms[i] |
| 5197 | if floatHistogram { |
| 5198 | switch { |
| 5199 | case value.IsStaleNaN(eh.fh.Sum): |
| 5200 | actNumStale++ |
| 5201 | require.True(t, value.IsStaleNaN(ah.fh.Sum)) |
| 5202 | // To make require.Equal work. |
| 5203 | ah.fh.Sum = 0 |
| 5204 | eh.fh = eh.fh.Copy() |
| 5205 | eh.fh.Sum = 0 |
| 5206 | case i > 0: |
no test coverage detected
searching dependent graphs…