sql,ui: provide a feature to reset the statements page immediately
I tried to reset the statements page on the UI by following the instructions in the info box:

but it didn't work. I set that value to 1 second, and nothing changed in the UI. I also tried setting the diagnostics.forced_stat_reset.interval setting to 1 second which didn't do anything.
Is that setting really about the statements page? It sounds slightly different - either way, it didn't work. Is this a bug in the setting, or the docs on that page, or something else?
cc @dt I hope we havent broken anything in the backend
@jordanlewis I have investigated this.
-
The settings (both of them) work as intended, however the new interval only kicks in after the current waiting period (using the previous configured value) is complete. We do not have a mechanism to force-activate the event when the interval is decreased. With the current implementation it would be hard to do.
-
I think there is a mismatch between what you want to do ("clear the statement stats") and what you were reading in the UI ("how to change the clear frequency").
I think the current behavior (where a new interval only becomes active after the current interval elapses) is adequate/appropriate for the goal announced in the UI ("how to change the frequency")
Meanwhile, there is no feature currently that answer the question "how to clear the statement stats NOW".
What matters most to you? Do you think we should change the title of the issue to "provide a feature that enables users to clear stats immediately"?
Ok, this makes sense. Yes, we should add a feature to clear the statement stats now. That is what was missing for the user that prompted me to file this issue.
We're currently working on changing how these stats are persisted, I'll add a user story to capture the need to clear stats immediately.
cc @couchand
OTOH what's the user's goal in clearing these stats at all? I do understand wanting some management settings to control the storage space used for insight tools like this, which could potentially include an option to clear the data (though I would expect you'd want that to apply to lots of systems beyond just this page).
@jordanlewis, I'd like to know more about what they're trying to accomplish that they want to clear them on-demand. I suspect it's to "zero them out", but that seems a bit at odds with the direction we're going here.
The use case was that they changed the workload/schema/something and were expecting to see a big difference in latency via the statements page, but couldn't find a way to see a before/after. Clearing it seems reasonable. Yes there are timeseries but there's more going on in the cluster than just the statement they were looking for.
Great. That use-case has already been considered and is core to our goals with this moving forward. I'd much rather take a holistic approach rather than continuing to try to pile on workarounds to our abusing the telemetry data for this purpose.
I'm already made uncomfortable by that tooltip: it's telling people to change their diagnostics reporting interval, which will affect the quality of the data we're getting.
Reviving this issue as the work in #45082 makes this much simpler to implement.
@asubiotto can you PTAL at this and help determine what we'd need to do here to support this capability?
Let's start with a function called crdb_internal.reset_statement_statistics() that immediately zeroes all statement statistics counters. There is already code that does this reset that lives on the sql Server called Server.ResetSQLStats.
The challenge is plumbing this into something that can hang off of an EvalContext for a builtin. It's kind of a tricky problem.
Once we have this, we can work on adding a call to this to adminServer (or its successor).
Just to clarify, Server.ResetSQLStats resets both statement stats and txn stats. Is that what we want? Or we only want to clear the statement stats in this case?
I think it'd probably be better to reset all stats. We can change that if there's need for it, but I think it doesn't make sense to have to think in different time horizons on the different pages (i.e. my transactions have stats since 2 hours ago, but my statement stats were reset 40 mins ago)
Thanks for the update!
Though I think we have a slight issue here, the current backend RPC endpoint resets both statement and txn stats upon invocation. The rationale is what Alfonso mentioned in the previous comment: it would be a bit confusing to think in different time horizons on different pages.
Do you think it would make sense to have a Clear Stats button on both pages that clears both statement and transaction stats?
Ah ok, updated to Clear SQL stats so it's generic across both pages

Looks great, I will get started implement this now. 😃
This is great! I wonder if we can get text to appear on hover that explains its both the transactions and statements pages? Even if not, this is awesome.
Yep agree it would be nice to add some messaging to explain this - maybe we could add a sentence to the current 'i' tooltip:
Statement history is cleared once an hour by default, which can be configured with the cluster setting
diagnostics.reporting.interval.
Clicking ‘Clear SQL stats’ will reset SQL stats on the statements and transactions pages.
cc @ianjevans
