mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
app/vmselect: log slow queries if their execution time exceeds -search.logSlowQueryDuration
This commit is contained in:
parent
628708ad76
commit
2ff996e276
1 changed files with 16 additions and 0 deletions
|
@ -1,16 +1,21 @@
|
||||||
package promql
|
package promql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||||
"github.com/VictoriaMetrics/metrics"
|
"github.com/VictoriaMetrics/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var logSlowQueryDuration = flag.Duration("search.logSlowQueryDuration", 5*time.Second, "Log queries with execution time exceeding this value. Zero disables slow query logging")
|
||||||
|
|
||||||
// ExpandWithExprs expands WITH expressions inside q and returns the resulting
|
// ExpandWithExprs expands WITH expressions inside q and returns the resulting
|
||||||
// PromQL without WITH expressions.
|
// PromQL without WITH expressions.
|
||||||
func ExpandWithExprs(q string) (string, error) {
|
func ExpandWithExprs(q string) (string, error) {
|
||||||
|
@ -24,6 +29,17 @@ func ExpandWithExprs(q string) (string, error) {
|
||||||
|
|
||||||
// Exec executes q for the given ec until the deadline.
|
// Exec executes q for the given ec until the deadline.
|
||||||
func Exec(ec *EvalConfig, q string) ([]netstorage.Result, error) {
|
func Exec(ec *EvalConfig, q string) ([]netstorage.Result, error) {
|
||||||
|
if *logSlowQueryDuration > 0 {
|
||||||
|
startTime := time.Now()
|
||||||
|
defer func() {
|
||||||
|
d := time.Since(startTime)
|
||||||
|
if d >= *logSlowQueryDuration {
|
||||||
|
logger.Infof("slow query: duration=%s, start=%d, end=%d, step=%d, accountID=%d, projectID=%d, query=%q",
|
||||||
|
d, ec.Start/1000, ec.End/1000, ec.Step/1000, ec.AuthToken.AccountID, ec.AuthToken.ProjectID, q)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
ec.validate()
|
ec.validate()
|
||||||
|
|
||||||
e, err := parsePromQLWithCache(q)
|
e, err := parsePromQLWithCache(q)
|
||||||
|
|
Loading…
Reference in a new issue