Repository: prometheus/prometheus
File: tsdb/chunkenc/histogram.go (Go)

Code before:
		return
	}
	if h.CounterResetHint == histogram.CounterReset {
		// Always honor the explicit counter reset hint.
		counterResetHeader = CounterReset
		return
	}
	if value.IsStaleNaN(h.Sum) {
		// This is a stale sample whose buckets and spans don't matter.
		okToAppend = true
		return
	}
	if value.IsStaleNaN(a.sum) {
		// If the last sample was stale, then we can only accept stale
		// samples in this chunk.
		return
	}

	if h.Count < a.cnt {
		// There has been a counter reset.
		counterResetHeader = CounterReset
		return
	}

	if h.Schema != a.schema || h.ZeroThreshold != a.zThreshold {
		counterResetHeader = UnknownCounterReset
		return
	}

	if histogram.IsCustomBucketsSchema(h.Schema) && !histogram.FloatBucketsMatch(h.CustomValues, a.customValues) {
		counterResetHeader = CounterReset
		return
	}

	if h.ZeroCount < a.zCnt {
		// There has been a counter reset since ZeroThreshold didn't change.
		counterResetHeader = CounterReset
		return
	}

	var ok bool
	positiveInserts, backwardPositiveInserts, ok = expandIntSpansAndBuckets(a.pSpans, h.PositiveSpans, a.pBuckets, h.PositiveBuckets)
	if !ok {
		counterResetHeader = CounterReset
		return
	}
	negativeInserts, backwardNegativeInserts, ok = expandIntSpansAndBuckets(a.nSpans, h.NegativeSpans, a.nBuckets, h.NegativeBuckets)
	if !ok {
		counterResetHeader = CounterReset
		return
	}

Review comment (suggestion):
Let's add a comment that this case might or might not go along with a counter reset and that we do not want to invest the work of a full counter reset detection as long as #15346 is still open. And maybe even add a TODO to consider adding the counter reset detection here once #15346 is fixed.

Code after:
	backwardPositiveInserts, backwardNegativeInserts []Insert,
	okToAppend bool, counterResetHint CounterResetHeader,
) {
	counterResetHint = NotCounterReset
	if a.NumSamples() > 0 && a.GetCounterResetHeader() == GaugeType {
		return
	}
	if h.CounterResetHint == histogram.CounterReset {
		// Always honor the explicit counter reset hint.
		counterResetHint = CounterReset
		return
	}
	if value.IsStaleNaN(h.Sum) {
		// This is a stale sample whose buckets and spans don't matter.
		okToAppend = true
		return
	}
	if value.IsStaleNaN(a.sum) {
		// If the last sample was stale, then we can only accept stale
		// samples in this chunk.
		counterResetHint = UnknownCounterReset
		return
	}

	if h.Count < a.cnt {
		// There has been a counter reset.
		counterResetHint = CounterReset
		return
	}

	if h.Schema != a.schema || h.ZeroThreshold != a.zThreshold {
		// This case might or might not go along with a counter reset and
		// we do not want to invest the work of a full counter reset detection
		// as long as https://github.com/prometheus/prometheus/issues/15346 is still open.
		// TODO: consider adding the counter reset detection here once #15346 is fixed.
		counterResetHint = UnknownCounterReset
		return
	}

	if histogram.IsCustomBucketsSchema(h.Schema) && !histogram.FloatBucketsMatch(h.CustomValues, a.customValues) {
		counterResetHint = CounterReset
		return
	}

	if h.ZeroCount < a.zCnt {
		// There has been a counter reset since ZeroThreshold didn't change.
		counterResetHint = CounterReset
		return
	}

	var ok bool