mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 00:13:30 +01:00
app/vmstorage: improve error logging when the request times out
This commit is contained in:
parent
e3999ac010
commit
b3d4ff7ee2
@ -1,6 +1,7 @@
|
|||||||
package transport
|
package transport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -381,6 +382,9 @@ func (s *Server) processVMSelectConn(bc *handshake.BufferedConn) error {
|
|||||||
// Remote client gracefully closed the connection.
|
// Remote client gracefully closed the connection.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if errors.Is(err, storage.ErrDeadlineExceeded) {
|
||||||
|
return fmt.Errorf("cannot process vmselect request in %d seconds: %w", ctx.timeout, err)
|
||||||
|
}
|
||||||
return fmt.Errorf("cannot process vmselect request: %w", err)
|
return fmt.Errorf("cannot process vmselect request: %w", err)
|
||||||
}
|
}
|
||||||
if err := bc.Flush(); err != nil {
|
if err := bc.Flush(); err != nil {
|
||||||
@ -399,6 +403,9 @@ type vmselectRequestCtx struct {
|
|||||||
sr storage.Search
|
sr storage.Search
|
||||||
mb storage.MetricBlock
|
mb storage.MetricBlock
|
||||||
|
|
||||||
|
// timeout in seconds for the current request
|
||||||
|
timeout uint64
|
||||||
|
|
||||||
// deadline in unix timestamp seconds for the current request.
|
// deadline in unix timestamp seconds for the current request.
|
||||||
deadline uint64
|
deadline uint64
|
||||||
}
|
}
|
||||||
@ -466,6 +473,9 @@ func (ctx *vmselectRequestCtx) writeDataBufBytes() error {
|
|||||||
const maxErrorMessageSize = 64 * 1024
|
const maxErrorMessageSize = 64 * 1024
|
||||||
|
|
||||||
func (ctx *vmselectRequestCtx) writeErrorMessage(err error) error {
|
func (ctx *vmselectRequestCtx) writeErrorMessage(err error) error {
|
||||||
|
if errors.Is(err, storage.ErrDeadlineExceeded) {
|
||||||
|
err = fmt.Errorf("cannot execute request in %d seconds: %w", ctx.timeout, err)
|
||||||
|
}
|
||||||
errMsg := err.Error()
|
errMsg := err.Error()
|
||||||
if len(errMsg) > maxErrorMessageSize {
|
if len(errMsg) > maxErrorMessageSize {
|
||||||
// Trim too long error message.
|
// Trim too long error message.
|
||||||
@ -520,6 +530,7 @@ func (s *Server) processVMSelectRequest(ctx *vmselectRequestCtx) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot read timeout for the request %q: %w", rpcName, err)
|
return fmt.Errorf("cannot read timeout for the request %q: %w", rpcName, err)
|
||||||
}
|
}
|
||||||
|
ctx.timeout = uint64(timeout)
|
||||||
ctx.deadline = fasttime.UnixTimestamp() + uint64(timeout)
|
ctx.deadline = fasttime.UnixTimestamp() + uint64(timeout)
|
||||||
|
|
||||||
switch rpcName {
|
switch rpcName {
|
||||||
|
@ -416,7 +416,7 @@ func (sq *SearchQuery) Unmarshal(src []byte) ([]byte, error) {
|
|||||||
|
|
||||||
func checkSearchDeadlineAndPace(deadline uint64) error {
|
func checkSearchDeadlineAndPace(deadline uint64) error {
|
||||||
if fasttime.UnixTimestamp() > deadline {
|
if fasttime.UnixTimestamp() > deadline {
|
||||||
return errDeadlineExceeded
|
return ErrDeadlineExceeded
|
||||||
}
|
}
|
||||||
storagepacelimiter.Search.WaitIfNeeded()
|
storagepacelimiter.Search.WaitIfNeeded()
|
||||||
return nil
|
return nil
|
||||||
|
@ -957,7 +957,8 @@ func (s *Storage) prefetchMetricNames(tsids []TSID, deadline uint64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var errDeadlineExceeded = fmt.Errorf("deadline exceeded")
|
// ErrDeadlineExceeded is returned when the request times out.
|
||||||
|
var ErrDeadlineExceeded = fmt.Errorf("deadline exceeded")
|
||||||
|
|
||||||
// DeleteMetrics deletes all the metrics matching the given tfss.
|
// DeleteMetrics deletes all the metrics matching the given tfss.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user