@ -15,7 +15,6 @@ package v1
import (
"context"
"errors"
"fmt"
"math"
"math/rand"
@ -32,6 +31,7 @@ import (
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
@ -271,7 +271,7 @@ func (api *API) query(r *http.Request) apiFuncResult {
var err error
ts , err = parseTime ( t )
if err != nil {
err = fmt. Errorf ( "invalid parameter 'time': %s" , err )
err = errors. Wrapf ( err , "invalid parameter 'time'" )
return apiFuncResult { nil , & apiError { errorBadData , err } , nil , nil }
}
} else {
@ -283,7 +283,7 @@ func (api *API) query(r *http.Request) apiFuncResult {
var cancel context . CancelFunc
timeout , err := parseDuration ( to )
if err != nil {
err = fmt. Errorf ( "invalid parameter 'timeout': %s" , err )
err = errors. Wrapf ( err , "invalid parameter 'timeout'" )
return apiFuncResult { nil , & apiError { errorBadData , err } , nil , nil }
}
@ -293,7 +293,7 @@ func (api *API) query(r *http.Request) apiFuncResult {
qry , err := api . QueryEngine . NewInstantQuery ( api . Queryable , r . FormValue ( "query" ) , ts )
if err != nil {
err = fmt. Errorf ( "invalid parameter 'query': %s" , err )
err = errors. Wrapf ( err , "invalid parameter 'query'" )
return apiFuncResult { nil , & apiError { errorBadData , err } , nil , nil }
}
@ -318,12 +318,12 @@ func (api *API) query(r *http.Request) apiFuncResult {
func ( api * API ) queryRange ( r * http . Request ) apiFuncResult {
start , err := parseTime ( r . FormValue ( "start" ) )
if err != nil {
err = fmt. Errorf ( "invalid parameter 'start': %s" , err )
err = errors. Wrapf ( err , "invalid parameter 'start'" )
return apiFuncResult { nil , & apiError { errorBadData , err } , nil , nil }
}
end , err := parseTime ( r . FormValue ( "end" ) )
if err != nil {
err = fmt. Errorf ( "invalid parameter 'end': %s" , err )
err = errors. Wrapf ( err , "invalid parameter 'end'" )
return apiFuncResult { nil , & apiError { errorBadData , err } , nil , nil }
}
if end . Before ( start ) {
@ -333,7 +333,7 @@ func (api *API) queryRange(r *http.Request) apiFuncResult {
step , err := parseDuration ( r . FormValue ( "step" ) )
if err != nil {
err = fmt. Errorf ( "invalid parameter 'step': %s" , err )
err = errors. Wrapf ( err , "invalid parameter 'step'" )
return apiFuncResult { nil , & apiError { errorBadData , err } , nil , nil }
}
@ -354,7 +354,7 @@ func (api *API) queryRange(r *http.Request) apiFuncResult {
var cancel context . CancelFunc
timeout , err := parseDuration ( to )
if err != nil {
err = fmt. Errorf ( "invalid parameter 'timeout': %s" , err )
err = errors. Wrap ( err , "invalid parameter 'timeout'" )
return apiFuncResult { nil , & apiError { errorBadData , err } , nil , nil }
}
@ -421,7 +421,7 @@ func (api *API) labelValues(r *http.Request) apiFuncResult {
name := route . Param ( ctx , "name" )
if ! model . LabelNameRE . MatchString ( name ) {
return apiFuncResult { nil , & apiError { errorBadData , fmt . Errorf ( "invalid label name: %q" , name ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorBadData , errors . Errorf ( "invalid label name: %q" , name ) } , nil , nil }
}
q , err := api . Queryable . Querier ( ctx , math . MinInt64 , math . MaxInt64 )
if err != nil {
@ -444,10 +444,10 @@ var (
func ( api * API ) series ( r * http . Request ) apiFuncResult {
if err := r . ParseForm ( ) ; err != nil {
return apiFuncResult { nil , & apiError { errorBadData , fmt. Errorf ( "error parsing form values: %v" , err ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorBadData , errors. Wrapf ( err , "error parsing form values" ) } , nil , nil }
}
if len ( r . Form [ "match[]" ] ) == 0 {
return apiFuncResult { nil , & apiError { errorBadData , fmt. Errorf ( "no match[] parameter provided" ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorBadData , errors. New ( "no match[] parameter provided" ) } , nil , nil }
}
var start time . Time
@ -511,7 +511,7 @@ func (api *API) series(r *http.Request) apiFuncResult {
}
func ( api * API ) dropSeries ( r * http . Request ) apiFuncResult {
return apiFuncResult { nil , & apiError { errorInternal , fmt. Errorf ( "not implemented" ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorInternal , errors. New ( "not implemented" ) } , nil , nil }
}
// Target has the information for one target.
@ -599,7 +599,7 @@ func (api *API) targetMetadata(r *http.Request) apiFuncResult {
if s := r . FormValue ( "limit" ) ; s != "" {
var err error
if limit , err = strconv . Atoi ( s ) ; err != nil {
return apiFuncResult { nil , & apiError { errorBadData , fmt. Errorf ( "limit must be a number" ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorBadData , errors. New ( "limit must be a number" ) } , nil , nil }
}
}
@ -810,7 +810,7 @@ func (api *API) rules(r *http.Request) apiFuncResult {
Type : "recording" ,
}
default :
err := fmt . Errorf ( "failed to assert type of rule '%v'" , rule . Name ( ) )
err := errors . Errorf ( "failed to assert type of rule '%v'" , rule . Name ( ) )
return apiFuncResult { nil , & apiError { errorInternal , err } , nil , nil }
}
@ -933,10 +933,10 @@ func (api *API) deleteSeries(r *http.Request) apiFuncResult {
}
if err := r . ParseForm ( ) ; err != nil {
return apiFuncResult { nil , & apiError { errorBadData , fmt. Errorf ( "error parsing form values: %v" , err ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorBadData , errors. Wrap ( err , "error parsing form values" ) } , nil , nil }
}
if len ( r . Form [ "match[]" ] ) == 0 {
return apiFuncResult { nil , & apiError { errorBadData , fmt. Errorf ( "no match[] parameter provided" ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorBadData , errors. New ( "no match[] parameter provided" ) } , nil , nil }
}
var start time . Time
@ -991,7 +991,7 @@ func (api *API) snapshot(r *http.Request) apiFuncResult {
if r . FormValue ( "skip_head" ) != "" {
skipHead , err = strconv . ParseBool ( r . FormValue ( "skip_head" ) )
if err != nil {
return apiFuncResult { nil , & apiError { errorBadData , fmt. Errorf ( "unable to parse boolean 'skip_head' argument : %v ", err ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorBadData , errors. Wrapf ( err , "unable to parse boolean 'skip_head' argument ") } , nil , nil }
}
}
@ -1008,10 +1008,10 @@ func (api *API) snapshot(r *http.Request) apiFuncResult {
dir = filepath . Join ( snapdir , name )
)
if err := os . MkdirAll ( dir , 0777 ) ; err != nil {
return apiFuncResult { nil , & apiError { errorInternal , fmt. Errorf ( "create snapshot directory: %s" , err ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorInternal , errors. Wrap ( err , "create snapshot directory" ) } , nil , nil }
}
if err := db . Snapshot ( dir , ! skipHead ) ; err != nil {
return apiFuncResult { nil , & apiError { errorInternal , fmt. Errorf ( "create snapshot: %s" , err ) } , nil , nil }
return apiFuncResult { nil , & apiError { errorInternal , errors. Wrap ( err , "create snapshot" ) } , nil , nil }
}
return apiFuncResult { struct {
@ -1158,21 +1158,21 @@ func parseTime(s string) (time.Time, error) {
if t , err := time . Parse ( time . RFC3339Nano , s ) ; err == nil {
return t , nil
}
return time . Time { } , fmt . Errorf ( "cannot parse %q to a valid timestamp" , s )
return time . Time { } , errors . Errorf ( "cannot parse %q to a valid timestamp" , s )
}
func parseDuration ( s string ) ( time . Duration , error ) {
if d , err := strconv . ParseFloat ( s , 64 ) ; err == nil {
ts := d * float64 ( time . Second )
if ts > float64 ( math . MaxInt64 ) || ts < float64 ( math . MinInt64 ) {
return 0 , fmt . Errorf ( "cannot parse %q to a valid duration. It overflows int64" , s )
return 0 , errors . Errorf ( "cannot parse %q to a valid duration. It overflows int64" , s )
}
return time . Duration ( ts ) , nil
}
if d , err := model . ParseDuration ( s ) ; err == nil {
return time . Duration ( d ) , nil
}
return 0 , fmt . Errorf ( "cannot parse %q to a valid duration" , s )
return 0 , errors . Errorf ( "cannot parse %q to a valid duration" , s )
}
func marshalPointJSON ( ptr unsafe . Pointer , stream * jsoniter . Stream ) {