From 20b1f596f6fb16107ef0c244d240b0ad6da36829 Mon Sep 17 00:00:00 2001 From: Tobias Guggenmos Date: Mon, 3 Feb 2020 19:06:39 +0100 Subject: [PATCH] Fix build errors in rest of prometheus Signed-off-by: Tobias Guggenmos --- pkg/rulefmt/rulefmt.go | 4 ++-- rules/alerting.go | 7 ++++--- rules/manager.go | 3 ++- rules/recording.go | 7 ++++--- web/api/v1/api.go | 11 ++++++----- web/federate.go | 3 ++- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pkg/rulefmt/rulefmt.go b/pkg/rulefmt/rulefmt.go index 6971657ba..10b53f83b 100644 --- a/pkg/rulefmt/rulefmt.go +++ b/pkg/rulefmt/rulefmt.go @@ -24,7 +24,7 @@ import ( yaml "gopkg.in/yaml.v3" "github.com/prometheus/prometheus/pkg/timestamp" - "github.com/prometheus/prometheus/promql" + "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/template" ) @@ -156,7 +156,7 @@ func (r *RuleNode) Validate() (nodes []WrappedError) { err: errors.Errorf("field 'expr' must be set in rule"), node: &r.Expr, }) - } else if _, err := promql.ParseExpr(r.Expr.Value); err != nil { + } else if _, err := parser.ParseExpr(r.Expr.Value); err != nil { nodes = append(nodes, WrappedError{ err: errors.Wrapf(err, "could not parse expression"), node: &r.Expr, diff --git a/rules/alerting.go b/rules/alerting.go index 235e11d47..dc55e8a1e 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -34,6 +34,7 @@ import ( "github.com/prometheus/prometheus/pkg/rulefmt" "github.com/prometheus/prometheus/pkg/timestamp" "github.com/prometheus/prometheus/promql" + "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/template" "github.com/prometheus/prometheus/util/strutil" ) @@ -112,7 +113,7 @@ type AlertingRule struct { // The name of the alert. name string // The vector expression from which to generate alerts. - vector promql.Expr + vector parser.Expr // The duration for which a labelset needs to persist in the expression // output vector before an alert transitions from Pending to Firing state. holdDuration time.Duration @@ -144,7 +145,7 @@ type AlertingRule struct { // NewAlertingRule constructs a new AlertingRule. func NewAlertingRule( - name string, vec promql.Expr, hold time.Duration, + name string, vec parser.Expr, hold time.Duration, labels, annotations, externalLabels labels.Labels, restored bool, logger log.Logger, ) *AlertingRule { @@ -201,7 +202,7 @@ func (r *AlertingRule) Health() RuleHealth { } // Query returns the query expression of the alerting rule. -func (r *AlertingRule) Query() promql.Expr { +func (r *AlertingRule) Query() parser.Expr { return r.vector } diff --git a/rules/manager.go b/rules/manager.go index 9ae3b69b7..718e54aad 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -34,6 +34,7 @@ import ( "github.com/prometheus/prometheus/pkg/timestamp" "github.com/prometheus/prometheus/pkg/value" "github.com/prometheus/prometheus/promql" + "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/storage" ) @@ -993,7 +994,7 @@ func (m *Manager) LoadGroups( rules := make([]Rule, 0, len(rg.Rules)) for _, r := range rg.Rules { - expr, err := promql.ParseExpr(r.Expr.Value) + expr, err := parser.ParseExpr(r.Expr.Value) if err != nil { return nil, []error{errors.Wrap(err, fn)} } diff --git a/rules/recording.go b/rules/recording.go index 6c29d3217..cec1a0fad 100644 --- a/rules/recording.go +++ b/rules/recording.go @@ -26,13 +26,14 @@ import ( "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/pkg/rulefmt" "github.com/prometheus/prometheus/promql" + "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/util/strutil" ) // A RecordingRule records its vector expression into new timeseries. type RecordingRule struct { name string - vector promql.Expr + vector parser.Expr labels labels.Labels // Protects the below. mtx sync.Mutex @@ -47,7 +48,7 @@ type RecordingRule struct { } // NewRecordingRule returns a new recording rule. -func NewRecordingRule(name string, vector promql.Expr, lset labels.Labels) *RecordingRule { +func NewRecordingRule(name string, vector parser.Expr, lset labels.Labels) *RecordingRule { return &RecordingRule{ name: name, vector: vector, @@ -62,7 +63,7 @@ func (rule *RecordingRule) Name() string { } // Query returns the rule query expression. -func (rule *RecordingRule) Query() promql.Expr { +func (rule *RecordingRule) Query() parser.Expr { return rule.vector } diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 54eb2d570..09a76c8fa 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -44,6 +44,7 @@ import ( "github.com/prometheus/prometheus/pkg/timestamp" "github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/promql" + "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/rules" "github.com/prometheus/prometheus/scrape" "github.com/prometheus/prometheus/storage" @@ -300,8 +301,8 @@ func (api *API) Register(r *route.Router) { } type queryData struct { - ResultType promql.ValueType `json:"resultType"` - Result promql.Value `json:"result"` + ResultType parser.ValueType `json:"resultType"` + Result parser.Value `json:"result"` Stats *stats.QueryStats `json:"stats,omitempty"` } @@ -534,7 +535,7 @@ func (api *API) series(r *http.Request) apiFuncResult { var matcherSets [][]*labels.Matcher for _, s := range r.Form["match[]"] { - matchers, err := promql.ParseMetricSelector(s) + matchers, err := parser.ParseMetricSelector(s) if err != nil { return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil} } @@ -695,7 +696,7 @@ func (api *API) targetMetadata(r *http.Request) apiFuncResult { var err error if matchTarget != "" { - matchers, err = promql.ParseMetricSelector(matchTarget) + matchers, err = parser.ParseMetricSelector(matchTarget) if err != nil { return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil} } @@ -1282,7 +1283,7 @@ func (api *API) deleteSeries(r *http.Request) apiFuncResult { } for _, s := range r.Form["match[]"] { - matchers, err := promql.ParseMetricSelector(s) + matchers, err := parser.ParseMetricSelector(s) if err != nil { return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil} } diff --git a/web/federate.go b/web/federate.go index 6a525d0a8..e358a3dab 100644 --- a/web/federate.go +++ b/web/federate.go @@ -29,6 +29,7 @@ import ( "github.com/prometheus/prometheus/pkg/timestamp" "github.com/prometheus/prometheus/pkg/value" "github.com/prometheus/prometheus/promql" + "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/storage" ) @@ -54,7 +55,7 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) { var matcherSets [][]*labels.Matcher for _, s := range req.Form["match[]"] { - matchers, err := promql.ParseMetricSelector(s) + matchers, err := parser.ParseMetricSelector(s) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return