Repository: prometheus/prometheus
File: util/annotations/annotations.go (Go)

Code before:
}

// NewPossibleNonCounterInfo is used when a named counter metric with only float samples does not
// have the suffixes _total, _sum, _count, or _bucket.
func NewPossibleNonCounterInfo(metricName string, pos posrange.PositionRange) error {
	return &annoErr{
		PositionRange: pos,
		Err:           fmt.Errorf("%w %q", PossibleNonCounterInfo, metricName),
	}
}

// NewPossibleNonCounterLabelInfo is used when a named counter metric with only float samples does not
// have the __type__ label set to "counter".
func NewPossibleNonCounterLabelInfo(metricName, typeLabel string, pos posrange.PositionRange) error {
	return &annoErr{
		PositionRange: pos,
		Err:           fmt.Errorf("%w, got %q: %q", PossibleNonCounterLabelInfo, typeLabel, metricName),
	}
}

type histogramQuantileForcedMonotonicityErr struct {
	PositionRange                                                              posrange.PositionRange
	Err                                                                        error
	Query                                                                      string
	minTs, maxTs                                                               int64
	forcedMonotonicMinBucket, forcedMonotonicMaxBucket, forcedMonotonicMaxDiff float64
	count                                                                      int
}

func (e *histogramQuantileForcedMonotonicityErr) Error() string {
	if e.Query == "" {
		return e.Err.Error()
	}
	startTime := time.Unix(e.minTs/1000, 0).UTC().Format(time.RFC3339)
	endTime := time.Unix(e.maxTs/1000, 0).UTC().Format(time.RFC3339)
	return fmt.Sprintf("%s, from buckets %g to %g, with a max diff of %.2g, over %d samples from %s to %s (%s)", e.Err, e.forcedMonotonicMinBucket, e.forcedMonotonicMaxBucket, e.forcedMonotonicMaxDiff, e.count+1, startTime, endTime, e.PositionRange.StartPosInput(e.Query, 0))
}

func (e *histogramQuantileForcedMonotonicityErr) Unwrap() error {
	return e.Err
}

func (e *histogramQuantileForcedMonotonicityErr) SetQuery(query string) {
	e.Query = query
}

func (e *histogramQuantileForcedMonotonicityErr) Merge(other error) error {
	o := &histogramQuantileForcedMonotonicityErr{}
	ok := errors.As(other, &o)
	if !ok {
		return e

Review comment (suggestion):
Since the context of forced monotonicity is clear here, I think we can go for shorter names (like `minBucket` etc.) here.

Code after:
}

// NewPossibleNonCounterInfo is used when a named counter metric with only float samples does not
// have the suffixes _total, _sum, _count, or _bucket.
func NewPossibleNonCounterInfo(metricName string, pos posrange.PositionRange) error {
	return &annoErr{
		PositionRange: pos,
		Err:           fmt.Errorf("%w %q", PossibleNonCounterInfo, metricName),
	}
}

// NewPossibleNonCounterLabelInfo is used when a named counter metric with only float samples does not
// have the __type__ label set to "counter".
func NewPossibleNonCounterLabelInfo(metricName, typeLabel string, pos posrange.PositionRange) error {
	return &annoErr{
		PositionRange: pos,
		Err:           fmt.Errorf("%w, got %q: %q", PossibleNonCounterLabelInfo, typeLabel, metricName),
	}
}

type histogramQuantileForcedMonotonicityErr struct {
	PositionRange                 posrange.PositionRange
	Err                           error
	Query                         string
	minTs, maxTs                  int64
	minBucket, maxBucket, maxDiff float64
	count                         int
}

func (e *histogramQuantileForcedMonotonicityErr) Error() string {
	if e.Query == "" {
		return e.Err.Error()
	}
	startTime := time.Unix(e.minTs/1000, 0).UTC().Format(time.RFC3339)
	endTime := time.Unix(e.maxTs/1000, 0).UTC().Format(time.RFC3339)
	return fmt.Sprintf("%s, from buckets %g to %g, with a max diff of %.2g, over %d samples from %s to %s (%s)", e.Err, e.minBucket, e.maxBucket, e.maxDiff, e.count+1, startTime, endTime, e.PositionRange.StartPosInput(e.Query, 0))
}

func (e *histogramQuantileForcedMonotonicityErr) Unwrap() error {
	return e.Err
}

func (e *histogramQuantileForcedMonotonicityErr) SetQuery(query string) {
	e.Query = query
}

func (e *histogramQuantileForcedMonotonicityErr) Merge(other error) error {
	o := &histogramQuantileForcedMonotonicityErr{}
	ok := errors.As(other, &o)
	if !ok {
		return e