mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44: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))
|
||||
|
||||
cmd := newEvalCmd(expr, ts)
|
||||
cmd := newEvalCmd(expr, ts, i+1)
|
||||
switch mod {
|
||||
case "ordered":
|
||||
cmd.ordered = true
|
||||
|
@ -303,6 +303,7 @@ func (cmd *loadCmd) append(a storage.Appender) error {
|
|||
type evalCmd struct {
|
||||
expr string
|
||||
start time.Time
|
||||
line int
|
||||
|
||||
fail, ordered bool
|
||||
|
||||
|
@ -319,10 +320,11 @@ func (e entry) String() string {
|
|||
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{
|
||||
expr: expr,
|
||||
start: start,
|
||||
line: line,
|
||||
|
||||
metrics: map[uint64]labels.Labels{},
|
||||
expected: map[uint64]entry{},
|
||||
|
@ -437,11 +439,11 @@ func (t *Test) exec(tc testCommand) error {
|
|||
if cmd.fail {
|
||||
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()
|
||||
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)
|
||||
|
@ -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)
|
||||
rangeRes := q.Exec(t.context)
|
||||
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()
|
||||
if cmd.ordered {
|
||||
|
@ -477,7 +479,7 @@ func (t *Test) exec(tc testCommand) error {
|
|||
err = cmd.compareResult(vec)
|
||||
}
|
||||
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:
|
||||
|
|
Loading…
Reference in a new issue