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

Code before:
		return 0, storage.ErrCTNewerThanSample
	}

	var created bool
	s := a.head.series.getByID(chunks.HeadSeriesRef(ref))
	if s == nil {
		var err error
		s, created, err = a.getOrCreate(lset)
		if err != nil {
			return 0, err
		}
	}

	switch {
	case h != nil:
		zeroHistogram := &histogram.Histogram{}
		s.Lock()

		// TODO(krajorama): reorganize Commit() to handle samples in append order
		// not floats first and then histograms. Then we would not need to do this.
		// This whole "if" should be removed.
		if created && s.lastHistogramValue == nil && s.lastFloatHistogramValue == nil {
			s.lastHistogramValue = zeroHistogram
		}

		// Although we call `appendableHistogram` with oooHistogramsEnabled=true, for CTZeroSamples OOO is not allowed.
		// We set it to true to make this implementation as close as possible to the float implementation.
		isOOO, _, err := s.appendableHistogram(ct, zeroHistogram, a.headMaxt, a.minValidTime, a.oooTimeWindow)
		if err != nil {
			s.Unlock()
			if errors.Is(err, storage.ErrOutOfOrderSample) {
				return 0, storage.ErrOutOfOrderCT
			}
		}
		// OOO is not allowed because after the first scrape, CT will be the same for most (if not all) future samples.
		// This is to prevent the injected zero from being marked as OOO forever.
		if isOOO {
			s.Unlock()
			return 0, storage.ErrOutOfOrderCT
		}
		s.pendingCommit = true
		s.Unlock()
		a.histograms = append(a.histograms, record.RefHistogramSample{
			Ref: s.ref,
			T:   ct,
			H:   zeroHistogram,
		})
		a.histogramSeries = append(a.histogramSeries, s)
	case fh != nil:
		zeroFloatHistogram := &histogram.FloatHistogram{}
		s.Lock()

Review comment (suggestion):
```suggestion
		// For CTZeroSamples OOO is not allowed.
```

Code after:
		return 0, storage.ErrCTNewerThanSample
	}

	var created bool
	s := a.head.series.getByID(chunks.HeadSeriesRef(ref))
	if s == nil {
		var err error
		s, created, err = a.getOrCreate(lset)
		if err != nil {
			return 0, err
		}
	}

	switch {
	case h != nil:
		zeroHistogram := &histogram.Histogram{}
		s.Lock()

		// TODO(krajorama): reorganize Commit() to handle samples in append order
		// not floats first and then histograms. Then we would not need to do this.
		// This whole "if" should be removed.
		if created && s.lastHistogramValue == nil && s.lastFloatHistogramValue == nil {
			s.lastHistogramValue = zeroHistogram
		}

		// For CTZeroSamples OOO is not allowed.
		// We set it to true to make this implementation as close as possible to the float implementation.
		isOOO, _, err := s.appendableHistogram(ct, zeroHistogram, a.headMaxt, a.minValidTime, a.oooTimeWindow)
		if err != nil {
			s.Unlock()
			if errors.Is(err, storage.ErrOutOfOrderSample) {
				return 0, storage.ErrOutOfOrderCT
			}
		}
		// OOO is not allowed because after the first scrape, CT will be the same for most (if not all) future samples.
		// This is to prevent the injected zero from being marked as OOO forever.
		if isOOO {
			s.Unlock()
			return 0, storage.ErrOutOfOrderCT
		}
		s.pendingCommit = true
		s.Unlock()
		a.histograms = append(a.histograms, record.RefHistogramSample{
			Ref: s.ref,
			T:   ct,
			H:   zeroHistogram,
		})
		a.histogramSeries = append(a.histogramSeries, s)
	case fh != nil:
		zeroFloatHistogram := &histogram.FloatHistogram{}
		s.Lock()