Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prometheus API set query version #1555

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/api/promql.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func HandleInstantQuery(r *httpRequestHandler) {
q := promql.Query{
Expr: r.FormValue("query"),
Options: promql.Options{
Version: r.version(),
Mode: data_model.InstantQuery,
Compat: true,
TimeNow: time.Now().Unix(),
Expand Down Expand Up @@ -72,6 +73,7 @@ func HandleRangeQuery(r *httpRequestHandler) {
q := promql.Query{
Expr: r.FormValue("query"),
Options: promql.Options{
Version: r.version(),
Compat: true,
Namespace: r.Header.Get("X-StatsHouse-Namespace"),
},
Expand Down Expand Up @@ -138,6 +140,7 @@ func HandlePromSeriesQuery(r *httpRequestHandler) {
End: end,
Expr: expr,
Options: promql.Options{
Version: r.version(),
Version3Start: r.Version3Start.Load(),
Limit: 1000,
Mode: data_model.TagsQuery,
Expand Down Expand Up @@ -212,6 +215,7 @@ func HandlePromLabelValuesQuery(r *httpRequestHandler) {
End: end,
Expr: expr,
Options: promql.Options{
Version: r.version(),
Version3Start: r.Version3Start.Load(),
Limit: 1000,
Mode: data_model.TagsQuery,
Expand Down
19 changes: 12 additions & 7 deletions internal/promql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,12 @@ func (ng Engine) Exec(ctx context.Context, h Handler, qry Query) (parser.Value,
}

func (ev *evaluator) Run() (parser.Value, func(), error) {
// parse query
if ev.t.Empty() {
return &TimeSeries{Time: []int64{}}, func() {}, nil
}
if e, ok := ev.ast.(*parser.StringLiteral); ok {
return String{T: ev.t.Start, V: e.Val}, func() {}, nil
}
if ev.t.Empty() {
return &TimeSeries{Time: []int64{}}, func() {}, nil
}
// evaluate query
ev.Tracef(ev.ast.String())
if ev.opt.Debug {
Expand Down Expand Up @@ -281,10 +280,12 @@ func (ng Engine) NewEvaluator(ctx context.Context, h Handler, qry Query) (evalua
Location: ng.location,
UTCOffset: ng.utcOffset,
})

if err != nil || ev.t.Empty() {
if err != nil {
return evaluator{}, Error{what: err}
}
if ev.t.Empty() {
return ev, nil
}
// evaluate reduction rules
ev.ars = make(map[parser.Expr]parser.Expr)
stepMin := ev.t.LODs[len(ev.t.LODs)-1].Step
Expand Down Expand Up @@ -1344,7 +1345,11 @@ func (ev *evaluator) getTagValue(metric *format.MetricMetaValue, tagX int, tagV
if err != nil {
return data_model.TagValue{}, err
}
return data_model.NewTagValueM(v), nil
if v != 0 {
return data_model.NewTagValueM(v), nil
} else {
return data_model.NewTagValue("", 0), nil
}
}
if tagX < 0 || len(metric.Tags) <= tagX {
return data_model.TagValue{}, ErrNotFound
Expand Down
Loading