mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
web : use Go standard package
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
6a124427fa
commit
05fba53e57
|
@ -41,13 +41,6 @@ issues:
|
||||||
text: "import 'github.com/pkg/errors' is not allowed"
|
text: "import 'github.com/pkg/errors' is not allowed"
|
||||||
linters:
|
linters:
|
||||||
- depguard
|
- depguard
|
||||||
- path: web/
|
|
||||||
linters:
|
|
||||||
- errorlint
|
|
||||||
- path: web/
|
|
||||||
text: "import 'github.com/pkg/errors' is not allowed"
|
|
||||||
linters:
|
|
||||||
- depguard
|
|
||||||
- linters:
|
- linters:
|
||||||
- godot
|
- godot
|
||||||
source: "^// ==="
|
source: "^// ==="
|
||||||
|
|
|
@ -17,8 +17,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// FloatHistogram is similar to Histogram but uses float64 for all
|
// FloatHistogram is similar to Histogram but uses float64 for all
|
||||||
|
@ -602,19 +600,19 @@ func (h *FloatHistogram) AllReverseBucketIterator() BucketIterator[float64] {
|
||||||
// create false positives here.
|
// create false positives here.
|
||||||
func (h *FloatHistogram) Validate() error {
|
func (h *FloatHistogram) Validate() error {
|
||||||
if err := checkHistogramSpans(h.NegativeSpans, len(h.NegativeBuckets)); err != nil {
|
if err := checkHistogramSpans(h.NegativeSpans, len(h.NegativeBuckets)); err != nil {
|
||||||
return errors.Wrap(err, "negative side")
|
return fmt.Errorf("negative side: %w", err)
|
||||||
}
|
}
|
||||||
if err := checkHistogramSpans(h.PositiveSpans, len(h.PositiveBuckets)); err != nil {
|
if err := checkHistogramSpans(h.PositiveSpans, len(h.PositiveBuckets)); err != nil {
|
||||||
return errors.Wrap(err, "positive side")
|
return fmt.Errorf("positive side: %w", err)
|
||||||
}
|
}
|
||||||
var nCount, pCount float64
|
var nCount, pCount float64
|
||||||
err := checkHistogramBuckets(h.NegativeBuckets, &nCount, false)
|
err := checkHistogramBuckets(h.NegativeBuckets, &nCount, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "negative side")
|
return fmt.Errorf("negative side: %w", err)
|
||||||
}
|
}
|
||||||
err = checkHistogramBuckets(h.PositiveBuckets, &pCount, false)
|
err = checkHistogramBuckets(h.PositiveBuckets, &pCount, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "positive side")
|
return fmt.Errorf("positive side: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -14,11 +14,10 @@
|
||||||
package histogram
|
package histogram
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -361,18 +360,12 @@ func checkHistogramSpans(spans []Span, numBuckets int) error {
|
||||||
var spanBuckets int
|
var spanBuckets int
|
||||||
for n, span := range spans {
|
for n, span := range spans {
|
||||||
if n > 0 && span.Offset < 0 {
|
if n > 0 && span.Offset < 0 {
|
||||||
return errors.Wrap(
|
return fmt.Errorf("span number %d with offset %d: %w", n+1, span.Offset, ErrHistogramSpanNegativeOffset)
|
||||||
ErrHistogramSpanNegativeOffset,
|
|
||||||
fmt.Sprintf("span number %d with offset %d", n+1, span.Offset),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
spanBuckets += int(span.Length)
|
spanBuckets += int(span.Length)
|
||||||
}
|
}
|
||||||
if spanBuckets != numBuckets {
|
if spanBuckets != numBuckets {
|
||||||
return errors.Wrap(
|
return fmt.Errorf("spans need %d buckets, have %d buckets: %w", spanBuckets, numBuckets, ErrHistogramSpansBucketsMismatch)
|
||||||
ErrHistogramSpansBucketsMismatch,
|
|
||||||
fmt.Sprintf("spans need %d buckets, have %d buckets", spanBuckets, numBuckets),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -391,10 +384,7 @@ func checkHistogramBuckets[BC BucketCount, IBC InternalBucketCount](buckets []IB
|
||||||
c = buckets[i]
|
c = buckets[i]
|
||||||
}
|
}
|
||||||
if c < 0 {
|
if c < 0 {
|
||||||
return errors.Wrap(
|
return fmt.Errorf("bucket number %d has observation count of %v: %w", i+1, c, ErrHistogramNegativeBucketCount)
|
||||||
ErrHistogramNegativeBucketCount,
|
|
||||||
fmt.Sprintf("bucket number %d has observation count of %v", i+1, c),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
last = c
|
last = c
|
||||||
*count += BC(c)
|
*count += BC(c)
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -338,35 +337,29 @@ func (h *Histogram) ToFloat() *FloatHistogram {
|
||||||
// the total h.Count).
|
// the total h.Count).
|
||||||
func (h *Histogram) Validate() error {
|
func (h *Histogram) Validate() error {
|
||||||
if err := checkHistogramSpans(h.NegativeSpans, len(h.NegativeBuckets)); err != nil {
|
if err := checkHistogramSpans(h.NegativeSpans, len(h.NegativeBuckets)); err != nil {
|
||||||
return errors.Wrap(err, "negative side")
|
return fmt.Errorf("negative side: %w", err)
|
||||||
}
|
}
|
||||||
if err := checkHistogramSpans(h.PositiveSpans, len(h.PositiveBuckets)); err != nil {
|
if err := checkHistogramSpans(h.PositiveSpans, len(h.PositiveBuckets)); err != nil {
|
||||||
return errors.Wrap(err, "positive side")
|
return fmt.Errorf("positive side: %w", err)
|
||||||
}
|
}
|
||||||
var nCount, pCount uint64
|
var nCount, pCount uint64
|
||||||
err := checkHistogramBuckets(h.NegativeBuckets, &nCount, true)
|
err := checkHistogramBuckets(h.NegativeBuckets, &nCount, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "negative side")
|
return fmt.Errorf("negative side: %w", err)
|
||||||
}
|
}
|
||||||
err = checkHistogramBuckets(h.PositiveBuckets, &pCount, true)
|
err = checkHistogramBuckets(h.PositiveBuckets, &pCount, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "positive side")
|
return fmt.Errorf("positive side: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sumOfBuckets := nCount + pCount + h.ZeroCount
|
sumOfBuckets := nCount + pCount + h.ZeroCount
|
||||||
if math.IsNaN(h.Sum) {
|
if math.IsNaN(h.Sum) {
|
||||||
if sumOfBuckets > h.Count {
|
if sumOfBuckets > h.Count {
|
||||||
return errors.Wrap(
|
return fmt.Errorf("%d observations found in buckets, but the Count field is %d: %w", sumOfBuckets, h.Count, ErrHistogramCountNotBigEnough)
|
||||||
ErrHistogramCountNotBigEnough,
|
|
||||||
fmt.Sprintf("%d observations found in buckets, but the Count field is %d", sumOfBuckets, h.Count),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if sumOfBuckets != h.Count {
|
if sumOfBuckets != h.Count {
|
||||||
return errors.Wrap(
|
return fmt.Errorf("%d observations found in buckets, but the Count field is %d: %w", sumOfBuckets, h.Count, ErrHistogramCountMismatch)
|
||||||
ErrHistogramCountMismatch,
|
|
||||||
fmt.Sprintf("%d observations found in buckets, but the Count field is %d", sumOfBuckets, h.Count),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
@ -33,7 +34,6 @@ import (
|
||||||
"github.com/grafana/regexp"
|
"github.com/grafana/regexp"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/munnerz/goautoneg"
|
"github.com/munnerz/goautoneg"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/prometheus/common/route"
|
"github.com/prometheus/common/route"
|
||||||
|
@ -317,7 +317,7 @@ func (api *API) ClearCodecs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUnavailStatusOnTSDBNotReady(r apiFuncResult) apiFuncResult {
|
func setUnavailStatusOnTSDBNotReady(r apiFuncResult) apiFuncResult {
|
||||||
if r.err != nil && errors.Cause(r.err.err) == tsdb.ErrNotReady {
|
if r.err != nil && errors.Is(r.err.err, tsdb.ErrNotReady) {
|
||||||
r.err.typ = errorUnavailable
|
r.err.typ = errorUnavailable
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
|
@ -415,7 +415,7 @@ type QueryData struct {
|
||||||
|
|
||||||
func invalidParamError(err error, parameter string) apiFuncResult {
|
func invalidParamError(err error, parameter string) apiFuncResult {
|
||||||
return apiFuncResult{nil, &apiError{
|
return apiFuncResult{nil, &apiError{
|
||||||
errorBadData, errors.Wrapf(err, "invalid parameter %q", parameter),
|
errorBadData, fmt.Errorf("invalid parameter %q: %w", parameter, err),
|
||||||
}, nil, nil}
|
}, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,17 +624,15 @@ func returnAPIError(err error) *apiError {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cause := errors.Unwrap(err)
|
var eqc promql.ErrQueryCanceled
|
||||||
if cause == nil {
|
var eqt promql.ErrQueryTimeout
|
||||||
cause = err
|
var es promql.ErrStorage
|
||||||
}
|
switch {
|
||||||
|
case errors.As(err, &eqc):
|
||||||
switch cause.(type) {
|
|
||||||
case promql.ErrQueryCanceled:
|
|
||||||
return &apiError{errorCanceled, err}
|
return &apiError{errorCanceled, err}
|
||||||
case promql.ErrQueryTimeout:
|
case errors.As(err, &eqt):
|
||||||
return &apiError{errorTimeout, err}
|
return &apiError{errorTimeout, err}
|
||||||
case promql.ErrStorage:
|
case errors.As(err, &es):
|
||||||
return &apiError{errorInternal, err}
|
return &apiError{errorInternal, err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,7 +707,7 @@ func (api *API) labelValues(r *http.Request) (result apiFuncResult) {
|
||||||
name := route.Param(ctx, "name")
|
name := route.Param(ctx, "name")
|
||||||
|
|
||||||
if !model.LabelNameRE.MatchString(name) {
|
if !model.LabelNameRE.MatchString(name) {
|
||||||
return apiFuncResult{nil, &apiError{errorBadData, errors.Errorf("invalid label name: %q", name)}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("invalid label name: %q", name)}, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
start, err := parseTimeParam(r, "start", MinTime)
|
start, err := parseTimeParam(r, "start", MinTime)
|
||||||
|
@ -797,7 +795,7 @@ func (api *API) series(r *http.Request) (result apiFuncResult) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
return apiFuncResult{nil, &apiError{errorBadData, errors.Wrapf(err, "error parsing form values")}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %w", err)}, nil, nil}
|
||||||
}
|
}
|
||||||
if len(r.Form["match[]"]) == 0 {
|
if len(r.Form["match[]"]) == 0 {
|
||||||
return apiFuncResult{nil, &apiError{errorBadData, errors.New("no match[] parameter provided")}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorBadData, errors.New("no match[] parameter provided")}, nil, nil}
|
||||||
|
@ -1028,7 +1026,7 @@ func (api *API) targets(r *http.Request) apiFuncResult {
|
||||||
case err == nil && lastErrStr == "":
|
case err == nil && lastErrStr == "":
|
||||||
return ""
|
return ""
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return errors.Wrapf(err, lastErrStr).Error()
|
return fmt.Errorf("%s: %w", lastErrStr, err).Error()
|
||||||
default:
|
default:
|
||||||
return lastErrStr
|
return lastErrStr
|
||||||
}
|
}
|
||||||
|
@ -1347,7 +1345,7 @@ type RecordingRule struct {
|
||||||
|
|
||||||
func (api *API) rules(r *http.Request) apiFuncResult {
|
func (api *API) rules(r *http.Request) apiFuncResult {
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
return apiFuncResult{nil, &apiError{errorBadData, errors.Wrapf(err, "error parsing form values")}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %w", err)}, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
queryFormToSet := func(values []string) map[string]struct{} {
|
queryFormToSet := func(values []string) map[string]struct{} {
|
||||||
|
@ -1367,7 +1365,7 @@ func (api *API) rules(r *http.Request) apiFuncResult {
|
||||||
typ := strings.ToLower(r.URL.Query().Get("type"))
|
typ := strings.ToLower(r.URL.Query().Get("type"))
|
||||||
|
|
||||||
if typ != "" && typ != "alert" && typ != "record" {
|
if typ != "" && typ != "alert" && typ != "record" {
|
||||||
return invalidParamError(errors.Errorf("not supported value %q", typ), "type")
|
return invalidParamError(fmt.Errorf("not supported value %q", typ), "type")
|
||||||
}
|
}
|
||||||
|
|
||||||
returnAlerts := typ == "" || typ == "alert"
|
returnAlerts := typ == "" || typ == "alert"
|
||||||
|
@ -1453,7 +1451,7 @@ func (api *API) rules(r *http.Request) apiFuncResult {
|
||||||
Type: "recording",
|
Type: "recording",
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
err := errors.Errorf("failed to assert type of rule '%v'", rule.Name())
|
err := fmt.Errorf("failed to assert type of rule '%v'", rule.Name())
|
||||||
return apiFuncResult{nil, &apiError{errorInternal, err}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorInternal, err}, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1560,7 +1558,7 @@ func (api *API) serveTSDBStatus(r *http.Request) apiFuncResult {
|
||||||
}
|
}
|
||||||
metrics, err := api.gatherer.Gather()
|
metrics, err := api.gatherer.Gather()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apiFuncResult{nil, &apiError{errorInternal, fmt.Errorf("error gathering runtime status: %s", err)}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorInternal, fmt.Errorf("error gathering runtime status: %w", err)}, nil, nil}
|
||||||
}
|
}
|
||||||
chunkCount := int64(math.NaN())
|
chunkCount := int64(math.NaN())
|
||||||
for _, mF := range metrics {
|
for _, mF := range metrics {
|
||||||
|
@ -1636,7 +1634,7 @@ func (api *API) deleteSeries(r *http.Request) apiFuncResult {
|
||||||
return apiFuncResult{nil, &apiError{errorUnavailable, errors.New("admin APIs disabled")}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorUnavailable, errors.New("admin APIs disabled")}, nil, nil}
|
||||||
}
|
}
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
return apiFuncResult{nil, &apiError{errorBadData, errors.Wrap(err, "error parsing form values")}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorBadData, fmt.Errorf("error parsing form values: %w", err)}, nil, nil}
|
||||||
}
|
}
|
||||||
if len(r.Form["match[]"]) == 0 {
|
if len(r.Form["match[]"]) == 0 {
|
||||||
return apiFuncResult{nil, &apiError{errorBadData, errors.New("no match[] parameter provided")}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorBadData, errors.New("no match[] parameter provided")}, nil, nil}
|
||||||
|
@ -1675,7 +1673,7 @@ func (api *API) snapshot(r *http.Request) apiFuncResult {
|
||||||
if r.FormValue("skip_head") != "" {
|
if r.FormValue("skip_head") != "" {
|
||||||
skipHead, err = strconv.ParseBool(r.FormValue("skip_head"))
|
skipHead, err = strconv.ParseBool(r.FormValue("skip_head"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return invalidParamError(errors.Wrapf(err, "unable to parse boolean"), "skip_head")
|
return invalidParamError(fmt.Errorf("unable to parse boolean: %w", err), "skip_head")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1687,10 +1685,10 @@ func (api *API) snapshot(r *http.Request) apiFuncResult {
|
||||||
dir = filepath.Join(snapdir, name)
|
dir = filepath.Join(snapdir, name)
|
||||||
)
|
)
|
||||||
if err := os.MkdirAll(dir, 0o777); err != nil {
|
if err := os.MkdirAll(dir, 0o777); err != nil {
|
||||||
return apiFuncResult{nil, &apiError{errorInternal, errors.Wrap(err, "create snapshot directory")}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorInternal, fmt.Errorf("create snapshot directory: %w", err)}, nil, nil}
|
||||||
}
|
}
|
||||||
if err := api.db.Snapshot(dir, !skipHead); err != nil {
|
if err := api.db.Snapshot(dir, !skipHead); err != nil {
|
||||||
return apiFuncResult{nil, &apiError{errorInternal, errors.Wrap(err, "create snapshot")}, nil, nil}
|
return apiFuncResult{nil, &apiError{errorInternal, fmt.Errorf("create snapshot: %w", err)}, nil, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiFuncResult{struct {
|
return apiFuncResult{struct {
|
||||||
|
@ -1805,7 +1803,7 @@ func parseTimeParam(r *http.Request, paramName string, defaultValue time.Time) (
|
||||||
}
|
}
|
||||||
result, err := parseTime(val)
|
result, err := parseTime(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Time{}, errors.Wrapf(err, "Invalid time value for '%s'", paramName)
|
return time.Time{}, fmt.Errorf("Invalid time value for '%s': %w", paramName, err)
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
@ -1830,21 +1828,21 @@ func parseTime(s string) (time.Time, error) {
|
||||||
case maxTimeFormatted:
|
case maxTimeFormatted:
|
||||||
return MaxTime, nil
|
return MaxTime, nil
|
||||||
}
|
}
|
||||||
return time.Time{}, errors.Errorf("cannot parse %q to a valid timestamp", s)
|
return time.Time{}, fmt.Errorf("cannot parse %q to a valid timestamp", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDuration(s string) (time.Duration, error) {
|
func parseDuration(s string) (time.Duration, error) {
|
||||||
if d, err := strconv.ParseFloat(s, 64); err == nil {
|
if d, err := strconv.ParseFloat(s, 64); err == nil {
|
||||||
ts := d * float64(time.Second)
|
ts := d * float64(time.Second)
|
||||||
if ts > float64(math.MaxInt64) || ts < float64(math.MinInt64) {
|
if ts > float64(math.MaxInt64) || ts < float64(math.MinInt64) {
|
||||||
return 0, errors.Errorf("cannot parse %q to a valid duration. It overflows int64", s)
|
return 0, fmt.Errorf("cannot parse %q to a valid duration. It overflows int64", s)
|
||||||
}
|
}
|
||||||
return time.Duration(ts), nil
|
return time.Duration(ts), nil
|
||||||
}
|
}
|
||||||
if d, err := model.ParseDuration(s); err == nil {
|
if d, err := model.ParseDuration(s); err == nil {
|
||||||
return time.Duration(d), nil
|
return time.Duration(d), nil
|
||||||
}
|
}
|
||||||
return 0, errors.Errorf("cannot parse %q to a valid duration", s)
|
return 0, fmt.Errorf("cannot parse %q to a valid duration", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseMatchersParam(matchers []string) ([][]*labels.Matcher, error) {
|
func parseMatchersParam(matchers []string) ([][]*labels.Matcher, error) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ package v1
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -33,7 +34,6 @@ import (
|
||||||
"github.com/prometheus/prometheus/util/stats"
|
"github.com/prometheus/prometheus/util/stats"
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
config_util "github.com/prometheus/common/config"
|
config_util "github.com/prometheus/common/config"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
@ -2974,7 +2974,7 @@ func (f *fakeDB) WALReplayStatus() (tsdb.WALReplayStatus, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAdminEndpoints(t *testing.T) {
|
func TestAdminEndpoints(t *testing.T) {
|
||||||
tsdb, tsdbWithError, tsdbNotReady := &fakeDB{}, &fakeDB{err: errors.New("some error")}, &fakeDB{err: errors.Wrap(tsdb.ErrNotReady, "wrap")}
|
tsdb, tsdbWithError, tsdbNotReady := &fakeDB{}, &fakeDB{err: errors.New("some error")}, &fakeDB{err: fmt.Errorf("wrap: %w", tsdb.ErrNotReady)}
|
||||||
snapshotAPI := func(api *API) apiFunc { return api.snapshot }
|
snapshotAPI := func(api *API) apiFunc { return api.snapshot }
|
||||||
cleanAPI := func(api *API) apiFunc { return api.cleanTombstones }
|
cleanAPI := func(api *API) apiFunc { return api.cleanTombstones }
|
||||||
deleteAPI := func(api *API) apiFunc { return api.deleteSeries }
|
deleteAPI := func(api *API) apiFunc { return api.deleteSeries }
|
||||||
|
@ -3354,7 +3354,7 @@ func TestParseTimeParam(t *testing.T) {
|
||||||
asTime: time.Time{},
|
asTime: time.Time{},
|
||||||
asError: func() error {
|
asError: func() error {
|
||||||
_, err := parseTime("baz")
|
_, err := parseTime("baz")
|
||||||
return errors.Wrapf(err, "Invalid time value for '%s'", "foo")
|
return fmt.Errorf("Invalid time value for '%s': %w", "foo", err)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,6 +15,7 @@ package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -24,7 +25,6 @@ import (
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/grafana/regexp"
|
"github.com/grafana/regexp"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/common/route"
|
"github.com/prometheus/common/route"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -21,7 +22,6 @@ import (
|
||||||
|
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
"github.com/prometheus/common/expfmt"
|
"github.com/prometheus/common/expfmt"
|
||||||
|
@ -86,7 +86,7 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
|
||||||
q, err := h.localStorage.Querier(mint, maxt)
|
q, err := h.localStorage.Querier(mint, maxt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
federationErrors.Inc()
|
federationErrors.Inc()
|
||||||
if errors.Cause(err) == tsdb.ErrNotReady {
|
if errors.Is(err, tsdb.ErrNotReady) {
|
||||||
http.Error(w, err.Error(), http.StatusServiceUnavailable)
|
http.Error(w, err.Error(), http.StatusServiceUnavailable)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ package web
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -25,7 +26,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
@ -238,15 +238,15 @@ type notReadyReadStorage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (notReadyReadStorage) Querier(int64, int64) (storage.Querier, error) {
|
func (notReadyReadStorage) Querier(int64, int64) (storage.Querier, error) {
|
||||||
return nil, errors.Wrap(tsdb.ErrNotReady, "wrap")
|
return nil, fmt.Errorf("wrap: %w", tsdb.ErrNotReady)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (notReadyReadStorage) StartTime() (int64, error) {
|
func (notReadyReadStorage) StartTime() (int64, error) {
|
||||||
return 0, errors.Wrap(tsdb.ErrNotReady, "wrap")
|
return 0, fmt.Errorf("wrap: %w", tsdb.ErrNotReady)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (notReadyReadStorage) Stats(string, int) (*tsdb.Stats, error) {
|
func (notReadyReadStorage) Stats(string, int) (*tsdb.Stats, error) {
|
||||||
return nil, errors.Wrap(tsdb.ErrNotReady, "wrap")
|
return nil, fmt.Errorf("wrap: %w", tsdb.ErrNotReady)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regression test for https://github.com/prometheus/prometheus/issues/7181.
|
// Regression test for https://github.com/prometheus/prometheus/issues/7181.
|
||||||
|
@ -396,7 +396,7 @@ func TestFederationWithNativeHistograms(t *testing.T) {
|
||||||
l := labels.Labels{}
|
l := labels.Labels{}
|
||||||
for {
|
for {
|
||||||
et, err := p.Next()
|
et, err := p.Next()
|
||||||
if err == io.EOF {
|
if err != nil && errors.Is(err, io.EOF) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -40,7 +40,6 @@ import (
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/grafana/regexp"
|
"github.com/grafana/regexp"
|
||||||
"github.com/mwitkow/go-conntrack"
|
"github.com/mwitkow/go-conntrack"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
io_prometheus_client "github.com/prometheus/client_model/go"
|
io_prometheus_client "github.com/prometheus/client_model/go"
|
||||||
|
@ -732,7 +731,7 @@ func (h *Handler) runtimeInfo() (api_v1.RuntimeInfo, error) {
|
||||||
|
|
||||||
metrics, err := h.gatherer.Gather()
|
metrics, err := h.gatherer.Gather()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return status, errors.Errorf("error gathering runtime status: %s", err)
|
return status, fmt.Errorf("error gathering runtime status: %w", err)
|
||||||
}
|
}
|
||||||
for _, mF := range metrics {
|
for _, mF := range metrics {
|
||||||
switch *mF.Name {
|
switch *mF.Name {
|
||||||
|
|
Loading…
Reference in a new issue