Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Transaction page inconsistent grouping of statement stats #59205

Closed
Tracked by #64743
sheaffej opened this issue Jan 20, 2021 · 2 comments · Fixed by #71967
Closed
Tracked by #64743

ui: Transaction page inconsistent grouping of statement stats #59205

sheaffej opened this issue Jan 20, 2021 · 2 comments · Fixed by #71967
Assignees
Labels
A-webui-general Issues on the DB Console that span multiple areas or don't have another clear category. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Comments

@sheaffej
Copy link
Collaborator

sheaffej commented Jan 20, 2021

I saw this while working with a customer, but have not been able to reproduce the behavior.

On the Transactions page in 20.2, we see a transaction with 2 similar statements. In the statement stats list (bottom of screen shot) the statement is listed twice, however the first listing has an execution count of 2 and the second has an execution count of 0. So it seems like some of the grouping and/or display logic in the statement stats list is mixing up the stats...or is displaying the statement twice when it should only be listed one with the aggregate stats.

transactions

Epic: CRDB-9867

@sheaffej sheaffej added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-webui-general Issues on the DB Console that span multiple areas or don't have another clear category. labels Jan 20, 2021
@awoods187
Copy link
Contributor

@Azhng
Copy link
Contributor

Azhng commented Sep 2, 2021

Currently started with the approach where we create a temporary in-memory SQL Stats to record all statements within an ongoing transaction, then flush the transaction to the actual SQL Stats once transaction is either committed or aborted. (This is when transaction fingerprint ID becomes available).

I realized an issue with the approach with using the temp SQL Stats approach while implementing it.

SET application_name = "app1";

BEGIN;

SELECT 1;                      -- stmt1
SELECT 1,1;                    -- stmt2  

SET application_name = "app2"; -- stmt3

SELECT 1,1,1;                  -- stmt4

COMMIT;

Our current behaviour would result stmt1 and stmt2 stored with application_name = app1. stmt3 and stmt4 are stored under application_name = app2. This is because we would swap out the application statistics object from app1 to app2 when the SET application_name is executed.

This introduce a problem for a new approach, when we swap out the application statistics object, we still don't have all the information to compute transaction fingerprint ID yet. This leaves us with few options:

  1. we do nothing, and we flush the stats from the Temp SQL Stats to the actual SQL Stats once the transaction is done executing. This is the easiest approach, but alters our behaviour when dealing with SET application_name = ...
  2. we maintain a list of application statistics objects in the Temp SQL Stats, and we keep track which application name is each statement executed under. We flush them to the corresponding application statistics object when the transaction is done executing. Personally, I'm not a fan of this option, it's very complicated and we need a lot of book keeping to ensure the correctness.
  3. we try a new approach: we don't create Temp SQL Stats at all. We would directly write all statement statistics into the main SQL Stats with a temporary transaction fingerprint ID. When the transaction is done executing, since we know the statement fingerprint IDs associated with that transaction and we know the transaction fingerprint ID, we go back to look up each individual statement statistics containing the new transaction fingerprint ID and we update the transaction fingerprint ID field. However, this introduces problems when the statement statistics are flushed to disk before we can come back to perform updates. Then we now just have inconsistent data. This can be addressed via some sort of special marker to inform the flusher to not flush statement statistics with temporary transaction fingerprint ID, but it's just introducing a more complexity.

My personal take: I would go with the first option. Since application_name is mostly passed in through connection string, using the SET application_name = ... statements within a transaction is an extremely weird thing to do. I personally feel like spending time and effort to support the backward compatibility with this weird usage of SET application_name = ... within a transaction. I would be really surprised to find users who are depending on that old behaviour and I'd argue it is fine for us to break the backward compatibility.

Azhng added a commit to Azhng/cockroach that referenced this issue Sep 4, 2021
Previously, SQL Stats's public writer interface is very limited
in its functionality. This was intentional back in the time where
SQL Stat's writer is injected into stats collector and directly
writes statistics into the in-memory store. However, as we move
to support grouping of statement statistics within an explicit
transaction, this limited interface becomes a hurdle for stats
collector to implement that behavior.
This commit restructure the SQL Stats Writer API to introduce
the concept of sqlstats.ApplicationStats, which maps to
ssmemstorage.Container struct. Now, sqlstats.Storage interface
would return the new sqlstats.ApplicationStats intead of
sqlstats.Writer to the connExecutor, which can be injected into
the sqlstats.StatsCollector.

This is the initial step to address cockroachdb#59205

Release justification: Low risk, high benefit changes to existing
functionality
Release note: None
@maryliag maryliag removed their assignment Sep 13, 2021
Azhng added a commit to Azhng/cockroach that referenced this issue Sep 15, 2021
Previously, SQL Stats's public writer interface is was very limited
in its functionality. This was intentional back in the time where
SQL Stat's writer was injected into the stats collector and directly
wrote statistics into the in-memory store. However, as we move
to support grouping statement statistics within an explicit
transaction, we need to create short-lived emphemeral sqlstats.Writer
to record statement statistics for explicit transactions, then merge
the stored statistics inside the emphemeral sqlstats.Writer into
the main SQLStats. However, this merge cannot be implemented with
the current sqlstats.Writer API, since the API does not allow statistics
to be fetched from the sqlstats.Writer.

This commit restructures the SQL Stats Writer API to introduce
the concept of sqlstats.ApplicationStats, which is backed by the
ssmemstorage.Container struct. Now, sqlstats.Storage interface
would return the new sqlstats.ApplicationStats intead of
sqlstats.Writer to the connExecutor, which can be injected into
the sqlstats.StatsCollector.

This is the initial step to address cockroachdb#59205

Release justification: Low risk, high benefit changes to existing
functionality
Release note: None
Azhng added a commit to Azhng/cockroach that referenced this issue Oct 6, 2021
fingerprintID

Previously, statement that are executed as part of different
transactions are grouped together resulting in one single
stats entry. This results in weird UX and makes it difficult
for developer to debug slow queries.
This commit groups statement statsitics based on its transaction
fingerprintIDs on top of the statement fingerprint ID.

Partially addresses cockroachdb#65106, cockroachdb#59205

Release note (bug fix): statement statsitics are now grouped by
the statement's corresponding transaction fingerprints.
Azhng added a commit to Azhng/cockroach that referenced this issue Oct 7, 2021
fingerprintID

Previously, statement that are executed as part of different
transactions are grouped together resulting in one single
stats entry. This results in weird UX and makes it difficult
for developer to debug slow queries.
This commit groups statement statsitics based on its transaction
fingerprintIDs on top of the statement fingerprint ID.

Partially addresses cockroachdb#65106, cockroachdb#59205

Release note (bug fix): statement statsitics are now grouped by
the statement's corresponding transaction fingerprints.
craig bot pushed a commit that referenced this issue Oct 7, 2021
70261: sql: group statement statistics based on its transaction fingerprintID r=matthewtodd a=Azhng

Depends on #69710

# First Commit

sql: plumb sqlstats.TestingKnobs down into ssmemstorage

This commit plumbs sqlstats.TestingKnobs into ssmemstorage
in order to allow later unit tests to manipulate times in the
tests.

Release note: None


# Second Commit

sql: remove GetStatementStats and GetTransactionStats API

Previsously, we had GetStatementStats and GetTransactionStats
exported as part of the interface for SQL Stats subsystem.
These two methods are only used within tests and nowhere else
in the code base.
This commit removes those two exported methods and rewrite the
tests to use the iterator API.

Release note: None

# Third Commit

sql: group statement statistics based on its transaction fingerprintID

Previously, statement that are executed as part of different
transactions are grouped together resulting in one single
stats entry. This results in weird UX and makes it difficult
for developer to debug slow queries.
This commit groups statement statsitics based on its transaction
fingerprintIDs on top of the statement fingerprint ID.

Partially addresses #65106, #59205

Release note (bug fix): statement statsitics are now grouped by
the statement's corresponding transaction fingerprints.

Co-authored-by: Azhng <archer.xn@gmail.com>
ericharmeling pushed a commit to ericharmeling/cockroach that referenced this issue Oct 20, 2021
fingerprintID

Previously, statement that are executed as part of different
transactions are grouped together resulting in one single
stats entry. This results in weird UX and makes it difficult
for developer to debug slow queries.
This commit groups statement statsitics based on its transaction
fingerprintIDs on top of the statement fingerprint ID.

Partially addresses cockroachdb#65106, cockroachdb#59205

Release note (bug fix): statement statsitics are now grouped by
the statement's corresponding transaction fingerprints.
Azhng added a commit to Azhng/cockroach that referenced this issue Oct 26, 2021
transaction fingerprint ID

Previously, transactionDetail page shows statement statistics aggregated
across **all** executions of that statement fingerprint. This led to
confusing UX and the statement statistics were subsequently removed
from transactionDetail page.
This commit reintroduces statement statistics on transactionDetail
page. The statistics now are only aggregated across the statement
fingerprints that are part of the selected transaction fingerprint.

Resolves cockroachdb#59205 cockroachdb#65106

Release note (ui change): transactionDetail page now shows statement
statistics scoped by the transaction fingeprint.
craig bot pushed a commit that referenced this issue Oct 26, 2021
71543: roachtest: disable prometheus for scrub r=otan a=otan

I'm unable to reproduce the error running roachtest myself, and it's the
only set of tests affected.

Resolves #71979

Release note: None

71927: sql/catalog/nstree: optimize with lazy initialization, pooling btrees r=ajwerner a=ajwerner

This change comes in response to
#66112 (comment).

The thrust of the change is to lazily initialize the data structures so that
when they are not used, they do not incur cost. Additionally, pool the
underlying tree so that when they are used, the allocations are effectively
free. This was originally deemed unimportant because the connExecutor
descs.Collection is long-lived. Unfortunately, others, as used for the
type resolve in distsql, are not.

```
name                                           old time/op    new time/op    delta
FlowSetup/vectorize=true/distribute=true-16       145µs ± 2%     139µs ± 3%   -3.94%  (p=0.000 n=19+20)
FlowSetup/vectorize=true/distribute=false-16      141µs ± 3%     134µs ± 2%   -4.66%  (p=0.000 n=18+19)
FlowSetup/vectorize=false/distribute=true-16      138µs ± 4%     132µs ± 4%   -4.23%  (p=0.000 n=20+20)
FlowSetup/vectorize=false/distribute=false-16     133µs ± 3%     127µs ± 3%   -4.41%  (p=0.000 n=20+19)

name                                           old alloc/op   new alloc/op   delta
FlowSetup/vectorize=true/distribute=true-16      38.1kB ± 3%    36.7kB ± 2%   -3.58%  (p=0.000 n=18+18)
FlowSetup/vectorize=true/distribute=false-16     36.2kB ± 0%    34.9kB ± 0%   -3.66%  (p=0.000 n=18+16)
FlowSetup/vectorize=false/distribute=true-16     42.6kB ± 0%    41.3kB ± 0%   -3.11%  (p=0.000 n=17+17)
FlowSetup/vectorize=false/distribute=false-16    41.0kB ± 0%    39.7kB ± 0%   -3.22%  (p=0.000 n=17+17)

name                                           old allocs/op  new allocs/op  delta
FlowSetup/vectorize=true/distribute=true-16         368 ± 0%       314 ± 0%  -14.67%  (p=0.000 n=16+17)
FlowSetup/vectorize=true/distribute=false-16        354 ± 0%       300 ± 0%  -15.25%  (p=0.000 n=17+17)
FlowSetup/vectorize=false/distribute=true-16        338 ± 1%       283 ± 1%  -16.13%  (p=0.000 n=19+19)
FlowSetup/vectorize=false/distribute=false-16       325 ± 0%       271 ± 0%  -16.62%  (p=0.000 n=18+18)
```

Omitting a release note because I'm doubtful this meaningfully shows up on its
own.

Release note: None

71960: ui: Added informative warning for insufficient privileges r=nathanstilwell a=nathanstilwell

<img width="972" alt="Screen Shot 2021-10-25 at 17 17 49" src="https://user-images.githubusercontent.com/397448/138772352-117456e1-10a8-475b-9b1c-79b0e2327558.png">

Previously, `/#/reports/nodes` would seem to hang in a loading state
indefinitely when a DB Console user wouldn't have admin privileges for
that endpoint. This was due to nodes data being empty from a 403
response.

An error is captured in the application state for this response, so
mapping this error as a prop to the component, the UI can distinguish
between the nodes data simply being empty and being empty due to a
restriction error.

<img width="827" alt="Screen Shot 2021-10-25 at 17 16 07" src="https://user-images.githubusercontent.com/397448/138772135-33321d34-9728-489b-8549-1c8bd55cf650.png">

Detecting this error, we render an `<InlineAlert />` to notify the user
of their lack of privileges.

Release note (ui change): All Nodes report notifies user is they need
more privileges to view information.

71966: ui: default filter on Transaction and Statement pages now exclude internals r=maryliag a=maryliag

Previously, the default value when no App filter was
selected on Transactions and Statements page, we were showing
all data, now we're excluding internal transaction/statements.

Fixes #70544

Release note (ui change): The default value when no App is selected
on Transactions and Statements filter is now excluding internal
Transactions and Statements.

71967: server,ui: transactionDetail page now shows statement stats scoped by transaction fingerprint ID r=matthewtodd a=Azhng

Previously, transactionDetail page shows statement statistics aggregated
across **all** executions of that statement fingerprint. This led to
confusing UX and the statement statistics were subsequently removed
from transactionDetail page.
This commit reintroduces statement statistics on transactionDetail
page. The statistics now are only aggregated across the statement
fingerprints that are part of the selected transaction fingerprint.

Resolves #59205 #65106

Release note (ui change): transactionDetail page now shows statement
statistics scoped by the transaction fingeprint.



https://user-images.githubusercontent.com/9267198/138916095-c91895d5-6f34-49b7-87dd-81f375b3f582.mov



71987: sql: skip TestSavepoints r=nkodali a=jbowens

Refs: #70220

Reason: flaky test

Generated by bin/skip-test.

Release justification: non-production code changes

Release note: None

Co-authored-by: Oliver Tan <otan@cockroachlabs.com>
Co-authored-by: Andrew Werner <awerner32@gmail.com>
Co-authored-by: Nathan Stilwell <nathanstilwell@cockroachlabs.com>
Co-authored-by: Marylia Gutierrez <marylia@cockroachlabs.com>
Co-authored-by: Azhng <archer.xn@gmail.com>
Co-authored-by: Jackson Owens <jackson@cockroachlabs.com>
@craig craig bot closed this as completed in d798002 Oct 26, 2021
@craig craig bot closed this as completed in #71967 Oct 26, 2021
Azhng added a commit to Azhng/cockroach that referenced this issue Nov 18, 2021
Previously, SQL Stats's public writer interface was very limited
in its functionality. This was intentional back in the time where
SQL Stat's writer was injected into the stats collector and directly
wrote statistics into the in-memory store. However, as we move
to support grouping statement statistics within an explicit
transaction, we need to create short-lived emphemeral sqlstats.Writer
to record statement statistics for explicit transactions, then merge
the stored statistics inside the emphemeral sqlstats.Writer into
the main SQLStats. However, this merge cannot be implemented with
the current sqlstats.Writer API, since the API does not allow statistics
to be fetched from the sqlstats.Writer.

This commit restructures the SQL Stats Writer API to introduce
the concept of sqlstats.ApplicationStats, which is backed by the
ssmemstorage.Container struct. Now, sqlstats.Storage interface
would return the new sqlstats.ApplicationStats intead of
sqlstats.Writer to the connExecutor, which can be injected into
the sqlstats.StatsCollector.

This is the initial step to address cockroachdb#59205

Release justification: Low risk, high benefit changes to existing
functionality
Release note: None
Azhng added a commit to Azhng/cockroach that referenced this issue Nov 18, 2021
fingerprintID

Previously, statement that are executed as part of different
transactions are grouped together resulting in one single
stats entry. This results in weird UX and makes it difficult
for developer to debug slow queries.
This commit groups statement statsitics based on its transaction
fingerprintIDs on top of the statement fingerprint ID.

Partially addresses cockroachdb#65106, cockroachdb#59205

Release note (bug fix): statement statsitics are now grouped by
the statement's corresponding transaction fingerprints.
Azhng added a commit to Azhng/cockroach that referenced this issue Nov 18, 2021
Previously, SQL Stats's public writer interface was very limited
in its functionality. This was intentional back in the time where
SQL Stat's writer was injected into the stats collector and directly
wrote statistics into the in-memory store. However, as we move
to support grouping statement statistics within an explicit
transaction, we need to create short-lived emphemeral sqlstats.Writer
to record statement statistics for explicit transactions, then merge
the stored statistics inside the emphemeral sqlstats.Writer into
the main SQLStats. However, this merge cannot be implemented with
the current sqlstats.Writer API, since the API does not allow statistics
to be fetched from the sqlstats.Writer.

This commit restructures the SQL Stats Writer API to introduce
the concept of sqlstats.ApplicationStats, which is backed by the
ssmemstorage.Container struct. Now, sqlstats.Storage interface
would return the new sqlstats.ApplicationStats intead of
sqlstats.Writer to the connExecutor, which can be injected into
the sqlstats.StatsCollector.

This is the initial step to address cockroachdb#59205

Release justification: Low risk, high benefit changes to existing
functionality
Release note: None
Azhng added a commit to Azhng/cockroach that referenced this issue Nov 18, 2021
fingerprintID

Previously, statement that are executed as part of different
transactions are grouped together resulting in one single
stats entry. This results in weird UX and makes it difficult
for developer to debug slow queries.
This commit groups statement statsitics based on its transaction
fingerprintIDs on top of the statement fingerprint ID.

Partially addresses cockroachdb#65106, cockroachdb#59205

Release note (bug fix): statement statsitics are now grouped by
the statement's corresponding transaction fingerprints.
Azhng added a commit to Azhng/cockroach that referenced this issue Nov 19, 2021
Previously, SQL Stats's public writer interface was very limited
in its functionality. This was intentional back in the time where
SQL Stat's writer was injected into the stats collector and directly
wrote statistics into the in-memory store. However, as we move
to support grouping statement statistics within an explicit
transaction, we need to create short-lived emphemeral sqlstats.Writer
to record statement statistics for explicit transactions, then merge
the stored statistics inside the emphemeral sqlstats.Writer into
the main SQLStats. However, this merge cannot be implemented with
the current sqlstats.Writer API, since the API does not allow statistics
to be fetched from the sqlstats.Writer.

This commit restructures the SQL Stats Writer API to introduce
the concept of sqlstats.ApplicationStats, which is backed by the
ssmemstorage.Container struct. Now, sqlstats.Storage interface
would return the new sqlstats.ApplicationStats intead of
sqlstats.Writer to the connExecutor, which can be injected into
the sqlstats.StatsCollector.

This is the initial step to address cockroachdb#59205

Release justification: Low risk, high benefit changes to existing
functionality
Release note: None
Azhng added a commit to Azhng/cockroach that referenced this issue Nov 19, 2021
fingerprintID

Previously, statement that are executed as part of different
transactions are grouped together resulting in one single
stats entry. This results in weird UX and makes it difficult
for developer to debug slow queries.
This commit groups statement statsitics based on its transaction
fingerprintIDs on top of the statement fingerprint ID.

Partially addresses cockroachdb#65106, cockroachdb#59205

Release note (bug fix): statement statsitics are now grouped by
the statement's corresponding transaction fingerprints.
Azhng added a commit to Azhng/cockroach that referenced this issue Nov 19, 2021
…d by

transaction fingerprint ID

Previously, the transactionDetail page showed statement statistics aggregated
across **all** executions of that statement fingerprint. This led to
confusing UX and the statement statistics were subsequently removed
from transactionDetail page.
This commit reintroduces statement statistics on the transactionDetail
page. The statistics now are only aggregated across the statement
fingerprints that are part of the selected transaction fingerprint.

Resolves cockroachdb#59205 cockroachdb#65106

Release note (ui change): transactionDetail page now shows statement
statistics scoped by the transaction fingeprint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-webui-general Issues on the DB Console that span multiple areas or don't have another clear category. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Projects
None yet
5 participants