Repository: prometheus/prometheus
File: tsdb/head_test.go (Go)

Code before:
	}{
		{
			name: "float_staleness_to_histogram",
			setupHistogram: func(app storage.Appender, lbls labels.Labels) error {
				h := &histogram.Histogram{
					Count:           3,
					Sum:             18.4,
					Schema:          1,
					PositiveSpans:   []histogram.Span{{Offset: 0, Length: 2}},
					PositiveBuckets: []int64{1, 1},
				}
				_, err := app.AppendHistogram(0, lbls, 1000, h, nil)
				return err
			},
		},
		{
			name: "float_staleness_to_float_histogram",
			setupHistogram: func(app storage.Appender, lbls labels.Labels) error {
				fh := &histogram.FloatHistogram{
					Count:           3,
					Sum:             18.4,
					Schema:          1,
					PositiveSpans:   []histogram.Span{{Offset: 0, Length: 2}},
					PositiveBuckets: []float64{1, 2},
				}
				_, err := app.AppendHistogram(0, lbls, 1000, nil, fh)
				return err
			},
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			head, _ := newTestHead(t, 1000, compression.None, false)
			defer func() {
				require.NoError(t, head.Close())
			}()

			lbls := labels.FromStrings("name", tc.name)

			// Helper to get counter values
			getFloatCounter := func() float64 {
				metric := &dto.Metric{}
				err := head.metrics.samplesAppended.WithLabelValues(sampleMetricTypeFloat).Write(metric)
				require.NoError(t, err)
				return metric.GetCounter().GetValue()
			}

			getHistogramCounter := func() float64 {
				metric := &dto.Metric{}
				err := head.metrics.samplesAppended.WithLabelValues(sampleMetricTypeHistogram).Write(metric)

Review comment (suggestion):
nit:
```suggestion
				_, err := app.AppendHistogram(0, lbls, 1000, nil, tsdbutil.GenerateTestFloatHistogram(1))
```

Code after:
	}{
		{
			name: "float_staleness_to_histogram",
			setupHistogram: func(app storage.Appender, lbls labels.Labels) error {
				_, err := app.AppendHistogram(0, lbls, 1000, tsdbutil.GenerateTestHistograms(1)[0], nil)
				return err
			},
		},
		{
			name: "float_staleness_to_float_histogram",
			setupHistogram: func(app storage.Appender, lbls labels.Labels) error {
				_, err := app.AppendHistogram(0, lbls, 1000, nil, tsdbutil.GenerateTestFloatHistograms(1)[0])
				return err
			},
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			head, _ := newTestHead(t, 1000, compression.None, false)
			defer func() {
				require.NoError(t, head.Close())
			}()

			lbls := labels.FromStrings("name", tc.name)

			// Helper to get counter values
			getSampleCounter := func(sampleType string) float64 {
				metric := &dto.Metric{}
				err := head.metrics.samplesAppended.WithLabelValues(sampleType).Write(metric)
				require.NoError(t, err)
				return metric.GetCounter().GetValue()
			}

			// Step 1: Establish a series with histogram data
			app := head.Appender(context.Background())
			err := tc.setupHistogram(app, lbls)
			require.NoError(t, err)
			require.NoError(t, app.Commit())

			// Step 2: Add a float staleness marker
			app = head.Appender(context.Background())
			_, err = app.Append(0, lbls, 2000, math.Float64frombits(value.StaleNaN))
			require.NoError(t, err)
			require.NoError(t, app.Commit())

			// Count what was actually stored by querying the series
			q, err := NewBlockQuerier(head, 0, 3000)
			require.NoError(t, err)
			defer q.Close()