From 91ce63a1402ff2e2447eb0286ba0e0c17b64624a Mon Sep 17 00:00:00 2001 From: Alin Sinpalean Date: Thu, 14 Jun 2018 16:18:16 +0200 Subject: [PATCH] Log the line when failing a PromQL test. (#4272) Signed-off-by: Alin Sinpalean --- promql/test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/promql/test.go b/promql/test.go index 0b512881c..14a5f399f 100644 --- a/promql/test.go +++ b/promql/test.go @@ -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: