Skip to content

Commit

Permalink
pkg/sqlutil: queryLogger must handle non-positive timoeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed May 23, 2024
1 parent ca92e91 commit 7a332d4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/sqlutil/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,14 @@ func (q *queryLogger) logTiming(ctx context.Context, start time.Time) {
}
timeout := deadline.Sub(start)

pct := float64(elapsed) / float64(timeout)
pct *= 100
var pct float64 // percent of timeout used
if timeout > 0 {
pct = float64(elapsed) / float64(timeout)
pct *= 100
} else {
timeout = 0
pct = 100
}

kvs := []any{"ms", elapsed.Milliseconds(), "timeout", timeout.Milliseconds(), "percent", strconv.FormatFloat(pct, 'f', 1, 64), "sql", q}

Expand Down

0 comments on commit 7a332d4

Please sign in to comment.