parent
b6beec4f57
commit
e28d16cfcf
|
@ -16,6 +16,7 @@
|
|||
- [#5502](https://github.com/influxdata/influxdb/issues/5502): Add checksum verification to TSM inspect tool
|
||||
- [#6444](https://github.com/influxdata/influxdb/pull/6444): Allow setting the config path through an environment variable and default config path.
|
||||
- [#3558](https://github.com/influxdata/influxdb/issues/3558): Support field math inside a WHERE clause.
|
||||
- [#6429](https://github.com/influxdata/influxdb/issues/6429): Log slow queries if they pass a configurable threshold.
|
||||
|
||||
### Bugfixes
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ type Config struct {
|
|||
ShardMapperTimeout toml.Duration `toml:"shard-mapper-timeout"`
|
||||
MaxConcurrentQueries int `toml:"max-concurrent-queries"`
|
||||
QueryTimeout toml.Duration `toml:"query-timeout"`
|
||||
LogQueriesAfter toml.Duration `toml:"log-queries-after"`
|
||||
MaxSelectPointN int `toml:"max-select-point"`
|
||||
MaxSelectSeriesN int `toml:"max-select-series"`
|
||||
MaxSelectBucketsN int `toml:"max-select-buckets"`
|
||||
|
|
|
@ -184,6 +184,7 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
|
|||
MaxSelectBucketsN: c.Cluster.MaxSelectBucketsN,
|
||||
}
|
||||
s.QueryExecutor.QueryTimeout = time.Duration(c.Cluster.QueryTimeout)
|
||||
s.QueryExecutor.LogQueriesAfter = time.Duration(c.Cluster.LogQueriesAfter)
|
||||
s.QueryExecutor.MaxConcurrentQueries = c.Cluster.MaxConcurrentQueries
|
||||
if c.Data.QueryLogEnabled {
|
||||
s.QueryExecutor.Logger = log.New(os.Stderr, "[query] ", log.LstdFlags)
|
||||
|
|
|
@ -105,6 +105,10 @@ type QueryExecutor struct {
|
|||
// Query execution timeout.
|
||||
QueryTimeout time.Duration
|
||||
|
||||
// Log queries if they are slower than this time.
|
||||
// If zero, slow queries will never be logged.
|
||||
LogQueriesAfter time.Duration
|
||||
|
||||
// Maximum number of concurrent queries.
|
||||
MaxConcurrentQueries int
|
||||
|
||||
|
@ -355,6 +359,20 @@ func (e *QueryExecutor) attachQuery(q *Query, database string, interrupt <-chan
|
|||
e.queries[qid] = query
|
||||
|
||||
go e.waitForQuery(qid, query.closing, interrupt, query.monitorCh)
|
||||
if e.LogQueriesAfter != 0 {
|
||||
go query.monitor(func(closing <-chan struct{}) error {
|
||||
t := time.NewTimer(e.LogQueriesAfter)
|
||||
defer t.Stop()
|
||||
|
||||
select {
|
||||
case <-t.C:
|
||||
e.Logger.Printf("Detected slow query: %s (qid: %d, database: %s, threshold: %s)",
|
||||
query.query, qid, query.database, e.LogQueriesAfter)
|
||||
case <-closing:
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
e.nextID++
|
||||
return qid, query, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue