Skip to content

feat: add failed and slow queries to query stats#27536

Merged
davidby-influx merged 5 commits into
master-1.xfrom
DSB/query_stats
Jul 16, 2026
Merged

feat: add failed and slow queries to query stats#27536
davidby-influx merged 5 commits into
master-1.xfrom
DSB/query_stats

Conversation

@davidby-influx

Copy link
Copy Markdown
Contributor

Add

statQueriesFailed = "queriesFailed" // Number of queries that have failed.
statQueriesSlow = "queriesSlow" // Snapshot of in-flight queries running longer than log-queries-after.

Closes https://github.com/influxdata/feature-requests/issues/392

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the query executor’s _internal query statistics by adding two new metrics: total failed queries and a snapshot count of currently-running “slow” queries (running longer than log-queries-after). This aligns runtime monitoring with existing slow-query logging semantics and provides better observability for query failures.

Changes:

  • Add queriesFailed stat and increment it based on terminal errors, execution-context-emitted errors, and panics.
  • Add queriesSlow stat by computing an in-flight slow-query snapshot from the TaskManager using LogQueriesAfter.
  • Add unit tests covering queriesFailed counting behavior and SlowQueryCount() behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
query/task_manager.go Adds SlowQueryCount() to snapshot in-flight queries exceeding LogQueriesAfter.
query/executor.go Adds queriesFailed / queriesSlow stats and wires counting into execution + panic recovery paths.
query/executor_test.go Adds tests for queriesFailed semantics and slow-query snapshot counting.
query/execution_context.go Tracks whether an error Result has been sent/attempted via a new atomic failed flag.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread query/executor.go Outdated
Comment thread query/execution_context.go Outdated
davidby-influx and others added 2 commits July 14, 2026 15:38
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

query/executor.go:394

  • This error Result is sent directly on results without setting StatementID (so multi-statement queries can report the error against statement 0) and without honoring AbortCh (so a caller aborting can still leave this goroutine blocked on send). Use ctx.send with StatementID: i so AbortCh is respected and the statement index is correct.
						failed = true
						results <- &Result{
							Err: fmt.Errorf("unable to use system source '%s': use %s instead", s.Name, command),
						}
						break LOOP

Comment thread query/executor.go
davidby-influx and others added 2 commits July 14, 2026 16:08
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@davidby-influx davidby-influx marked this pull request as ready for review July 14, 2026 23:25

@devanbenz devanbenz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment about failed vs cancelled/interrupted queries.

Comment thread query/executor.go
}

if interrupted {
// A query killed or timed out between statements is a failed query,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider a cancelled query as failed? Or should we use a different metric for this i.e. CancelledQueries?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think canceled queries will be such a small percentage, we can consider them failed because of user unhappiness.

@devanbenz devanbenz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davidby-influx davidby-influx merged commit 1530040 into master-1.x Jul 16, 2026
9 checks passed
@davidby-influx davidby-influx deleted the DSB/query_stats branch July 16, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants