Repository: prometheus/prometheus
File: model/histogram/generic.go (Go)

Code before:
	ErrHistogramCustomBucketsInvalid  = errors.New("histogram custom bounds must be in strictly increasing order")
	ErrHistogramCustomBucketsInfinite = errors.New("histogram custom bounds must be finite")
	ErrHistogramsIncompatibleSchema   = errors.New("cannot apply this operation on histograms with a mix of exponential and custom bucket schemas")
	ErrHistogramsIncompatibleBounds   = errors.New("cannot apply this operation on custom buckets histograms with different custom bounds")
	ErrHistogramsInvalidSchema        = errors.New("histogram has an invalid schema, which must be between -4 and 8 for exponential buckets, or -53 for custom buckets")
)

func IsCustomBucketsSchema(s int32) bool {
	return s == CustomBucketsSchema
}

func IsExponentialSchema(s int32) bool {
	return s >= ExponentialSchemaMin && s <= ExponentialSchemaMax
}

func IsExponentialSchemaReserved(s int32) bool {
	return s >= ExponentialSchemaMinReserved && s <= ExponentialSchemaMaxReserved
}

func IsValidSchema(s int32) bool {
	return IsCustomBucketsSchema(s) || IsExponentialSchema(s)
}

// IsAcceptibleSchema returns bool if we accept the schema, but need to reduce
// resolution to the nearest supported schema.
func IsAcceptibleSchema(s int32) bool {
	return IsCustomBucketsSchema(s) || IsExponentialSchemaReserved(s)
}

// BucketCount is a type constraint for the count in a bucket, which can be
// float64 (for type FloatHistogram) or uint64 (for type Histogram).
type BucketCount interface {
	float64 | uint64
}

// InternalBucketCount is used internally by Histogram and FloatHistogram. The
// difference to the BucketCount above is that Histogram internally uses deltas
// between buckets rather than absolute counts (while FloatHistogram uses
// absolute counts directly). Go type parameters don't allow type
// specialization. Therefore, where special treatment of deltas between buckets
// vs. absolute counts is important, this information has to be provided as a
// separate boolean parameter "deltaBuckets".
type InternalBucketCount interface {
	float64 | int64
}

// Bucket represents a bucket with lower and upper limit and the absolute count
// of samples in the bucket. It also specifies if each limit is inclusive or
// not. (Mathematically, inclusive limits create a closed interval, and
// non-inclusive limits an open interval.)
//

Review comment (suggestion):
```suggestion
func IsAcceptableSchema(s int32) bool {
```

"Acceptible" is quite outdated.

Code after:
	ErrHistogramCustomBucketsInvalid    = errors.New("histogram custom bounds must be in strictly increasing order")
	ErrHistogramCustomBucketsInfinite   = errors.New("histogram custom bounds must be finite")
	ErrHistogramsIncompatibleSchema     = errors.New("cannot apply this operation on histograms with a mix of exponential and custom bucket schemas")
	ErrHistogramsIncompatibleBounds     = errors.New("cannot apply this operation on custom buckets histograms with different custom bounds")
	ErrHistogramCustomBucketsZeroCount  = errors.New("custom buckets: must have zero count of 0")
	ErrHistogramCustomBucketsZeroThresh = errors.New("custom buckets: must have zero threshold of 0")
	ErrHistogramCustomBucketsNegSpans   = errors.New("custom buckets: must not have negative spans")
	ErrHistogramCustomBucketsNegBuckets = errors.New("custom buckets: must not have negative buckets")
	ErrHistogramExpSchemaCustomBounds   = errors.New("histogram with exponential schema must not have custom bounds")
	ErrHistogramsInvalidSchema          = fmt.Errorf("histogram has an invalid schema, which must be between %d and %d for exponential buckets, or %d for custom buckets", ExponentialSchemaMin, ExponentialSchemaMax, CustomBucketsSchema)
	ErrHistogramsUnknownSchema          = fmt.Errorf("histogram has an unknown schema, which must be between %d and %d for exponential buckets, or %d for custom buckets", ExponentialSchemaMinReserved, ExponentialSchemaMaxReserved, CustomBucketsSchema)
)

func InvalidSchemaError(s int32) error {
	return fmt.Errorf("%w, got schema %d", ErrHistogramsInvalidSchema, s)
}

func UnknownSchemaError(s int32) error {
	return fmt.Errorf("%w, got schema %d", ErrHistogramsUnknownSchema, s)
}

func IsCustomBucketsSchema(s int32) bool {
	return s == CustomBucketsSchema
}

func IsExponentialSchema(s int32) bool {
	return s >= ExponentialSchemaMin && s <= ExponentialSchemaMax
}

func IsExponentialSchemaReserved(s int32) bool {
	return s >= ExponentialSchemaMinReserved && s <= ExponentialSchemaMaxReserved
}

func IsValidSchema(s int32) bool {
	return IsCustomBucketsSchema(s) || IsExponentialSchema(s)
}

// IsKnownSchema returns bool if we known and accept the schema, but need to
// reduce resolution to the nearest supported schema.
func IsKnownSchema(s int32) bool {
	return IsCustomBucketsSchema(s) || IsExponentialSchemaReserved(s)
}

// BucketCount is a type constraint for the count in a bucket, which can be
// float64 (for type FloatHistogram) or uint64 (for type Histogram).
type BucketCount interface {
	float64 | uint64
}

// InternalBucketCount is used internally by Histogram and FloatHistogram. The
// difference to the BucketCount above is that Histogram internally uses deltas