2023-09-14 09:57:31 -07:00
// Copyright 2023 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package annotations
import (
"errors"
"fmt"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/promql/parser/posrange"
)
// Annotations is a general wrapper for warnings and other information
// that is returned by the query API along with the results.
// Each individual annotation is modeled by a Go error.
// They are deduplicated based on the string returned by error.Error().
// The zero value is usable without further initialization, see New().
type Annotations map [ string ] error
// New returns new Annotations ready to use. Note that the zero value of
// Annotations is also fully usable, but using this method is often more
// readable.
func New ( ) * Annotations {
return & Annotations { }
}
// Add adds an annotation (modeled as a Go error) in-place and returns the
// modified Annotations for convenience.
func ( a * Annotations ) Add ( err error ) Annotations {
if * a == nil {
* a = Annotations { }
}
( * a ) [ err . Error ( ) ] = err
return * a
}
// Merge adds the contents of the second annotation to the first, modifying
// the first in-place, and returns the merged first Annotation for convenience.
func ( a * Annotations ) Merge ( aa Annotations ) Annotations {
if * a == nil {
2023-10-24 09:36:07 -07:00
if aa == nil {
return nil
}
2023-09-14 09:57:31 -07:00
* a = Annotations { }
}
for key , val := range aa {
( * a ) [ key ] = val
}
return * a
}
// AsErrors is a convenience function to return the annotations map as a slice
// of errors.
func ( a Annotations ) AsErrors ( ) [ ] error {
arr := make ( [ ] error , 0 , len ( a ) )
for _ , err := range a {
arr = append ( arr , err )
}
return arr
}
2024-07-06 02:05:00 -07:00
// AsStrings is a convenience function to return the annotations map as 2 slices
// of strings, separated into warnings and infos. The query string is used to get the
// line number and character offset positioning info of the elements which trigger an
// annotation. We limit the number of warnings and infos returned here with maxWarnings
// and maxInfos respectively (0 for no limit).
func ( a Annotations ) AsStrings ( query string , maxWarnings , maxInfos int ) ( warnings , infos [ ] string ) {
warnings = make ( [ ] string , 0 , maxWarnings + 1 )
infos = make ( [ ] string , 0 , maxInfos + 1 )
warnSkipped := 0
infoSkipped := 0
2023-09-14 09:57:31 -07:00
for _ , err := range a {
2023-11-02 13:45:07 -07:00
var anErr annoErr
if errors . As ( err , & anErr ) {
2023-09-14 09:57:31 -07:00
anErr . Query = query
err = anErr
}
2024-07-06 02:05:00 -07:00
switch {
case errors . Is ( err , PromQLInfo ) :
if maxInfos == 0 || len ( infos ) < maxInfos {
infos = append ( infos , err . Error ( ) )
} else {
infoSkipped ++
}
default :
if maxWarnings == 0 || len ( warnings ) < maxWarnings {
warnings = append ( warnings , err . Error ( ) )
} else {
warnSkipped ++
}
}
2023-09-14 09:57:31 -07:00
}
2024-07-06 02:05:00 -07:00
if warnSkipped > 0 {
warnings = append ( warnings , fmt . Sprintf ( "%d more warning annotations omitted" , warnSkipped ) )
2023-09-14 09:57:31 -07:00
}
2024-07-06 02:05:00 -07:00
if infoSkipped > 0 {
infos = append ( infos , fmt . Sprintf ( "%d more info annotations omitted" , infoSkipped ) )
}
return
2023-09-14 09:57:31 -07:00
}
2024-07-06 02:05:00 -07:00
// CountWarningsAndInfo counts and returns the number of warnings and infos in the
// annotations wrapper.
func ( a Annotations ) CountWarningsAndInfo ( ) ( countWarnings , countInfo int ) {
2024-05-08 04:58:24 -07:00
for _ , err := range a {
if errors . Is ( err , PromQLWarning ) {
countWarnings ++
}
if errors . Is ( err , PromQLInfo ) {
countInfo ++
}
}
2024-07-06 02:05:00 -07:00
return
2024-05-08 04:58:24 -07:00
}
2023-11-29 09:23:34 -08:00
//nolint:revive // error-naming.
2023-09-14 09:57:31 -07:00
var (
// Currently there are only 2 types, warnings and info.
// For now, info are visually identical with warnings as we have not updated
// the API spec or the frontend to show a different kind of warning. But we
// make the distinction here to prepare for adding them in future.
PromQLInfo = errors . New ( "PromQL info" )
PromQLWarning = errors . New ( "PromQL warning" )
feat: add limitk() and limit_ratio() operators (#12503)
* rebase 2024-07-01, picks previous renaming to `limitk()` and `limit_ratio()`
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* gofumpt -d -extra
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* more lint fixes
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* more lint fixes+
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* put limitk() and limit_ratio() behind --enable-feature=promql-experimental-functions
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* EnableExperimentalFunctions for TestConcurrentRangeQueries() also
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* use testutil.RequireEqual to fix tests, WIP equivalent thingie for require.Contains
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* lint fix
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* moar linting
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* rebase 2024-06-19
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* re-add limit(2, metric) testing for N=2 common series subset
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* move `ratio = param` to default switch case, for better readability
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* gofumpt -d -extra util/testutil/cmp.go
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* early break when reaching k elems in limitk(), should have always been so (!)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* small typo fix
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* no-change small break-loop rearrange for readability
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove IsNan(ratio) condition in switch-case, already handled as input validation
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* no-change adding some comments
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* no-change simplify fullMatrix() helper functions used for tests
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add `limitk(-1, metric)` testcase, which is handled as any k < 1 case
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* engine_test.go: no-change create `requireCommonSeries() helper func (moving code into it) for readability
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* rebase 2024-06-21
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* engine_test.go: HAPPY NOW about its code -> reorg, create and use simpleRangeQuery() function, less lines and more readable ftW \o/
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* move limitk(), limit_ratio() testing to promql/promqltest/testdata/limit.test
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove stale leftover after moving tests from engine_test.go to testdata/
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix flaky `limit_ratio(0.5, ...)` test case
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Update promql/engine.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Update promql/engine.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Update promql/engine.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix AddRatioSample() implementation to use a single conditional (instead of switch/case + fallback return)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* docs/querying/operators.md: document r < 0
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add negative limit_ratio() example to docs/querying/examples.md
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* move more extensive docu examples to docs/querying/operators.md
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* typo
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* small docu fix for poor-mans-normality-check, add it to limit.test ;)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* limit.test: expand "Poor man's normality check" to whole eval range
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* restore mistakenly removed existing small comment
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* expand poors-man-normality-check case(s)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Revert "expand poors-man-normality-check case(s)"
This reverts commit f69e1603b2ebe69c0a100197cfbcf6f81644b564, indeed too
flaky 0:)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove humor from docs/querying/operators.md
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix signoff
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add web/ui missing changes
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* expand limit_ratio test cases, cross-fingering they'll not be flaky
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove flaky test
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add missing warnings.Merge(ws) in instant-query return shortcut
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add missing LimitK||LimitRatio case to codemirror-promql/src/parser/parser.ts
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix ui-lint
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* actually fix returned warnings :]
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
---------
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
Co-authored-by: Julius Volz <julius.volz@gmail.com>
2024-07-03 13:18:57 -07:00
InvalidRatioWarning = fmt . Errorf ( "%w: ratio value should be between -1 and 1" , PromQLWarning )
2024-02-28 05:06:43 -08:00
InvalidQuantileWarning = fmt . Errorf ( "%w: quantile value should be between 0 and 1" , PromQLWarning )
BadBucketLabelWarning = fmt . Errorf ( "%w: bucket label %q is missing or has a malformed value" , PromQLWarning , model . BucketLabel )
MixedFloatsHistogramsWarning = fmt . Errorf ( "%w: encountered a mix of histograms and floats for" , PromQLWarning )
MixedClassicNativeHistogramsWarning = fmt . Errorf ( "%w: vector contains a mix of classic and native histograms for metric name" , PromQLWarning )
NativeHistogramNotCounterWarning = fmt . Errorf ( "%w: this native histogram metric is not a counter:" , PromQLWarning )
NativeHistogramNotGaugeWarning = fmt . Errorf ( "%w: this native histogram metric is not a gauge:" , PromQLWarning )
MixedExponentialCustomHistogramsWarning = fmt . Errorf ( "%w: vector contains a mix of histograms with exponential and custom buckets schemas for metric name" , PromQLWarning )
IncompatibleCustomBucketsHistogramsWarning = fmt . Errorf ( "%w: vector contains histograms with incompatible custom buckets for metric name" , PromQLWarning )
2023-09-14 09:57:31 -07:00
2023-10-15 02:32:56 -07:00
PossibleNonCounterInfo = fmt . Errorf ( "%w: metric might not be a counter, name does not end in _total/_sum/_count/_bucket:" , PromQLInfo )
2023-11-24 15:05:38 -08:00
HistogramQuantileForcedMonotonicityInfo = fmt . Errorf ( "%w: input to histogram_quantile needed to be fixed for monotonicity (see https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile) for metric name" , PromQLInfo )
2023-09-14 09:57:31 -07:00
)
type annoErr struct {
PositionRange posrange . PositionRange
Err error
Query string
}
func ( e annoErr ) Error ( ) string {
2023-10-25 03:10:42 -07:00
if e . Query == "" {
return e . Err . Error ( )
}
2023-09-14 09:57:31 -07:00
return fmt . Sprintf ( "%s (%s)" , e . Err , e . PositionRange . StartPosInput ( e . Query , 0 ) )
}
2023-10-27 09:38:32 -07:00
func ( e annoErr ) Unwrap ( ) error {
return e . Err
}
2023-09-14 09:57:31 -07:00
// NewInvalidQuantileWarning is used when the user specifies an invalid quantile
// value, i.e. a float that is outside the range [0, 1] or NaN.
2023-11-29 09:23:34 -08:00
func NewInvalidQuantileWarning ( q float64 , pos posrange . PositionRange ) error {
2023-09-14 09:57:31 -07:00
return annoErr {
PositionRange : pos ,
Err : fmt . Errorf ( "%w, got %g" , InvalidQuantileWarning , q ) ,
}
}
lint: Revamp our linting rules, mostly around doc comments
Several things done here:
- Set `max-issues-per-linter` to 0 so that we actually see all linter
warnings and not just 50 per linter. (As we also set
`max-same-issues` to 0, I assume this was the intention from the
beginning.)
- Stop using the golangci-lint default excludes (by setting
`exclude-use-default: false`. Those are too generous and don't match
our style conventions. (I have re-added some of the excludes
explicitly in this commit. See below.)
- Re-add the `errcheck` exclusion we have used so far via the
defaults.
- Exclude the signature requirement `govet` has for `Seek` methods
because we use non-standard `Seek` methods a lot. (But we keep other
requirements, while the default excludes completely disabled the
check for common method segnatures.)
- Exclude warnings about missing doc comments on exported symbols. (We
used to be pretty adamant about doc comments, but stopped that at
some point in the past. By now, we have about 500 missing doc
comments. We may consider reintroducing this check, but that's
outside of the scope of this commit. The default excludes of
golangci-lint essentially ignore doc comments completely.)
- By stop using the default excludes, we now get warnings back on
malformed doc comments. That's the most impactful change in this
commit. It does not enforce doc comments (again), but _if_ there is
a doc comment, it has to have the recommended form. (Most of the
changes in this commit are fixing this form.)
- Improve wording/spelling of some comments in .golangci.yml, and
remove an outdated comment.
- Leave `package-comments` inactive, but add a TODO asking if we
should change that.
- Add a new sub-linter `comment-spacings` (and fix corresponding
comments), which avoids missing spaces after the leading `//`.
Signed-off-by: beorn7 <beorn@grafana.com>
2024-08-22 04:59:36 -07:00
// NewInvalidRatioWarning is used when the user specifies an invalid ratio
feat: add limitk() and limit_ratio() operators (#12503)
* rebase 2024-07-01, picks previous renaming to `limitk()` and `limit_ratio()`
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* gofumpt -d -extra
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* more lint fixes
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* more lint fixes+
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* put limitk() and limit_ratio() behind --enable-feature=promql-experimental-functions
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* EnableExperimentalFunctions for TestConcurrentRangeQueries() also
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* use testutil.RequireEqual to fix tests, WIP equivalent thingie for require.Contains
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* lint fix
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* moar linting
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* rebase 2024-06-19
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* re-add limit(2, metric) testing for N=2 common series subset
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* move `ratio = param` to default switch case, for better readability
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* gofumpt -d -extra util/testutil/cmp.go
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* early break when reaching k elems in limitk(), should have always been so (!)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* small typo fix
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* no-change small break-loop rearrange for readability
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove IsNan(ratio) condition in switch-case, already handled as input validation
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* no-change adding some comments
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* no-change simplify fullMatrix() helper functions used for tests
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add `limitk(-1, metric)` testcase, which is handled as any k < 1 case
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* engine_test.go: no-change create `requireCommonSeries() helper func (moving code into it) for readability
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* rebase 2024-06-21
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* engine_test.go: HAPPY NOW about its code -> reorg, create and use simpleRangeQuery() function, less lines and more readable ftW \o/
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* move limitk(), limit_ratio() testing to promql/promqltest/testdata/limit.test
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove stale leftover after moving tests from engine_test.go to testdata/
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix flaky `limit_ratio(0.5, ...)` test case
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Update promql/engine.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Update promql/engine.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Update promql/engine.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix AddRatioSample() implementation to use a single conditional (instead of switch/case + fallback return)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* docs/querying/operators.md: document r < 0
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add negative limit_ratio() example to docs/querying/examples.md
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* move more extensive docu examples to docs/querying/operators.md
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* typo
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* small docu fix for poor-mans-normality-check, add it to limit.test ;)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* limit.test: expand "Poor man's normality check" to whole eval range
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* restore mistakenly removed existing small comment
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* expand poors-man-normality-check case(s)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* Revert "expand poors-man-normality-check case(s)"
This reverts commit f69e1603b2ebe69c0a100197cfbcf6f81644b564, indeed too
flaky 0:)
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove humor from docs/querying/operators.md
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix signoff
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add web/ui missing changes
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* expand limit_ratio test cases, cross-fingering they'll not be flaky
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* remove flaky test
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add missing warnings.Merge(ws) in instant-query return shortcut
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* add missing LimitK||LimitRatio case to codemirror-promql/src/parser/parser.ts
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* fix ui-lint
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
* actually fix returned warnings :]
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
---------
Signed-off-by: JuanJo Ciarlante <juanjosec@gmail.com>
Co-authored-by: Julius Volz <julius.volz@gmail.com>
2024-07-03 13:18:57 -07:00
// value, i.e. a float that is outside the range [-1, 1] or NaN.
func NewInvalidRatioWarning ( q , to float64 , pos posrange . PositionRange ) error {
return annoErr {
PositionRange : pos ,
Err : fmt . Errorf ( "%w, got %g, capping to %g" , InvalidRatioWarning , q , to ) ,
}
}
2023-09-14 09:57:31 -07:00
// NewBadBucketLabelWarning is used when there is an error parsing the bucket label
// of a classic histogram.
2023-11-29 09:23:34 -08:00
func NewBadBucketLabelWarning ( metricName , label string , pos posrange . PositionRange ) error {
2023-09-14 09:57:31 -07:00
return annoErr {
PositionRange : pos ,
Err : fmt . Errorf ( "%w of %q for metric name %q" , BadBucketLabelWarning , label , metricName ) ,
}
}
// NewMixedFloatsHistogramsWarning is used when the queried series includes both
// float samples and histogram samples for functions that do not support mixed
// samples.
2023-11-29 09:23:34 -08:00
func NewMixedFloatsHistogramsWarning ( metricName string , pos posrange . PositionRange ) error {
2023-09-14 09:57:31 -07:00
return annoErr {
PositionRange : pos ,
2024-02-25 11:26:52 -08:00
Err : fmt . Errorf ( "%w metric name %q" , MixedFloatsHistogramsWarning , metricName ) ,
}
}
// NewMixedFloatsHistogramsAggWarning is used when the queried series includes both
// float samples and histogram samples in an aggregation.
func NewMixedFloatsHistogramsAggWarning ( pos posrange . PositionRange ) error {
return annoErr {
PositionRange : pos ,
Err : fmt . Errorf ( "%w aggregation" , MixedFloatsHistogramsWarning ) ,
2023-09-14 09:57:31 -07:00
}
}
// NewMixedClassicNativeHistogramsWarning is used when the queried series includes
// both classic and native histograms.
2023-11-29 09:23:34 -08:00
func NewMixedClassicNativeHistogramsWarning ( metricName string , pos posrange . PositionRange ) error {
2023-09-14 09:57:31 -07:00
return annoErr {
PositionRange : pos ,
Err : fmt . Errorf ( "%w %q" , MixedClassicNativeHistogramsWarning , metricName ) ,
}
}
2024-01-17 08:06:35 -08:00
// NewNativeHistogramNotCounterWarning is used when histogramRate is called
// with isCounter set to true on a gauge histogram.
func NewNativeHistogramNotCounterWarning ( metricName string , pos posrange . PositionRange ) error {
return annoErr {
PositionRange : pos ,
Err : fmt . Errorf ( "%w %q" , NativeHistogramNotCounterWarning , metricName ) ,
}
}
// NewNativeHistogramNotGaugeWarning is used when histogramRate is called
// with isCounter set to false on a counter histogram.
func NewNativeHistogramNotGaugeWarning ( metricName string , pos posrange . PositionRange ) error {
return annoErr {
PositionRange : pos ,
Err : fmt . Errorf ( "%w %q" , NativeHistogramNotGaugeWarning , metricName ) ,
}
}
2024-02-28 05:06:43 -08:00
// NewMixedExponentialCustomHistogramsWarning is used when the queried series includes
// histograms with both exponential and custom buckets schemas.
func NewMixedExponentialCustomHistogramsWarning ( metricName string , pos posrange . PositionRange ) error {
return annoErr {
PositionRange : pos ,
Err : fmt . Errorf ( "%w %q" , MixedExponentialCustomHistogramsWarning , metricName ) ,
}
}
// NewIncompatibleCustomBucketsHistogramsWarning is used when the queried series includes
// custom buckets histograms with incompatible custom bounds.
func NewIncompatibleCustomBucketsHistogramsWarning ( metricName string , pos posrange . PositionRange ) error {
return annoErr {
PositionRange : pos ,
Err : fmt . Errorf ( "%w %q" , IncompatibleCustomBucketsHistogramsWarning , metricName ) ,
}
}
2023-10-15 23:02:45 -07:00
// NewPossibleNonCounterInfo is used when a named counter metric with only float samples does not
// have the suffixes _total, _sum, _count, or _bucket.
2023-11-29 09:23:34 -08:00
func NewPossibleNonCounterInfo ( metricName string , pos posrange . PositionRange ) error {
2023-10-04 03:53:55 -07:00
return annoErr {
PositionRange : pos ,
2023-10-06 04:09:32 -07:00
Err : fmt . Errorf ( "%w %q" , PossibleNonCounterInfo , metricName ) ,
2023-10-04 03:53:55 -07:00
}
}
2023-10-06 04:09:32 -07:00
// NewHistogramQuantileForcedMonotonicityInfo is used when the input (classic histograms) to
// histogram_quantile needs to be forced to be monotonic.
2023-11-29 09:23:34 -08:00
func NewHistogramQuantileForcedMonotonicityInfo ( metricName string , pos posrange . PositionRange ) error {
2023-09-14 09:57:31 -07:00
return annoErr {
PositionRange : pos ,
2023-10-06 04:09:32 -07:00
Err : fmt . Errorf ( "%w %q" , HistogramQuantileForcedMonotonicityInfo , metricName ) ,
2023-09-14 09:57:31 -07:00
}
}