mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
Log the line when failing a PromQL test. (#4272)
Signed-off-by: Alin Sinpalean <alin.sinpalean@gmail.com>
This commit is contained in:
parent
d24d2acd11
commit
91ce63a140
|
@ -160,7 +160,7 @@ func (t *Test) parseEval(lines []string, i int) (int, *evalCmd, error) {
|
||||||
}
|
}
|
||||||
ts := testStartTime.Add(time.Duration(offset))
|
ts := testStartTime.Add(time.Duration(offset))
|
||||||
|
|
||||||
cmd := newEvalCmd(expr, ts)
|
cmd := newEvalCmd(expr, ts, i+1)
|
||||||
switch mod {
|
switch mod {
|
||||||
case "ordered":
|
case "ordered":
|
||||||
cmd.ordered = true
|
cmd.ordered = true
|
||||||
|
@ -303,6 +303,7 @@ func (cmd *loadCmd) append(a storage.Appender) error {
|
||||||
type evalCmd struct {
|
type evalCmd struct {
|
||||||
expr string
|
expr string
|
||||||
start time.Time
|
start time.Time
|
||||||
|
line int
|
||||||
|
|
||||||
fail, ordered bool
|
fail, ordered bool
|
||||||
|
|
||||||
|
@ -319,10 +320,11 @@ func (e entry) String() string {
|
||||||
return fmt.Sprintf("%d: %s", e.pos, e.vals)
|
return fmt.Sprintf("%d: %s", e.pos, e.vals)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEvalCmd(expr string, start time.Time) *evalCmd {
|
func newEvalCmd(expr string, start time.Time, line int) *evalCmd {
|
||||||
return &evalCmd{
|
return &evalCmd{
|
||||||
expr: expr,
|
expr: expr,
|
||||||
start: start,
|
start: start,
|
||||||
|
line: line,
|
||||||
|
|
||||||
metrics: map[uint64]labels.Labels{},
|
metrics: map[uint64]labels.Labels{},
|
||||||
expected: map[uint64]entry{},
|
expected: map[uint64]entry{},
|
||||||
|
@ -437,11 +439,11 @@ func (t *Test) exec(tc testCommand) error {
|
||||||
if cmd.fail {
|
if cmd.fail {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("error evaluating query %q: %s", cmd.expr, res.Err)
|
return fmt.Errorf("error evaluating query %q (line %d): %s", cmd.expr, cmd.line, res.Err)
|
||||||
}
|
}
|
||||||
defer q.Close()
|
defer q.Close()
|
||||||
if res.Err == nil && cmd.fail {
|
if res.Err == nil && cmd.fail {
|
||||||
return fmt.Errorf("expected error evaluating query but got none")
|
return fmt.Errorf("expected error evaluating query %q (line %d) but got none", cmd.expr, cmd.line)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := cmd.compareResult(res.Value)
|
err := cmd.compareResult(res.Value)
|
||||||
|
@ -454,7 +456,7 @@ func (t *Test) exec(tc testCommand) error {
|
||||||
q, _ = t.queryEngine.NewRangeQuery(t.storage, cmd.expr, cmd.start.Add(-time.Minute), cmd.start.Add(time.Minute), time.Minute)
|
q, _ = t.queryEngine.NewRangeQuery(t.storage, cmd.expr, cmd.start.Add(-time.Minute), cmd.start.Add(time.Minute), time.Minute)
|
||||||
rangeRes := q.Exec(t.context)
|
rangeRes := q.Exec(t.context)
|
||||||
if rangeRes.Err != nil {
|
if rangeRes.Err != nil {
|
||||||
return fmt.Errorf("error evaluating query %q in range mode: %s", cmd.expr, rangeRes.Err)
|
return fmt.Errorf("error evaluating query %q (line %d) in range mode: %s", cmd.expr, cmd.line, rangeRes.Err)
|
||||||
}
|
}
|
||||||
defer q.Close()
|
defer q.Close()
|
||||||
if cmd.ordered {
|
if cmd.ordered {
|
||||||
|
@ -477,7 +479,7 @@ func (t *Test) exec(tc testCommand) error {
|
||||||
err = cmd.compareResult(vec)
|
err = cmd.compareResult(vec)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error in %s %s rande mode: %s", cmd, cmd.expr, err)
|
return fmt.Errorf("error in %s %s (line %d) rande mode: %s", cmd, cmd.expr, cmd.line, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue