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

server: use stats activity tables on sql stats endpoint #102026

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

maryliag
Copy link
Contributor

@maryliag maryliag commented Apr 21, 2023

With the new sql stats tables that contain the top 500 rows based on most used column, this PR updates the calls on the sql stats endpoint to use the new flow:

flowchart TD;
    A[Compare the TS on ACTIVITY Table with the Requested TS] --> B{Is the requested time \nperiod completely \non the table?}
    B -- Yes --> C[SELECT on ACTIVITY table]
    C --> D{Had results?}
    D -- Yes --> E[Return RESULTS]
    D -- No --> F[SELECT on PERSISTED table]
    B -- No ----> F
    F --> G{Had results?}
    G -- Yes --> E
    G -- No --> H[SELECT on COMBINED table]
    H --> E
Loading

Part Of: #101948

A following PR will deal when selecting a column that is not one of the ones selected to generate the activity tables.

Release note (performance improvement): SQL Activity endpoints now use first a table with the top data for the most used cases. If there is no data available, it used the previous flow with persisted data and if that is also empty, uses in-memory.

@blathers-crl
Copy link

blathers-crl bot commented Apr 21, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@maryliag maryliag force-pushed the stats-endpoint branch 2 times, most recently from eba742b to 3cc443d Compare April 24, 2023 19:19
@maryliag maryliag marked this pull request as ready for review April 24, 2023 19:19
@maryliag maryliag requested review from a team and removed request for a team April 24, 2023 19:19
@maryliag maryliag added backport-23.1.x Flags PRs that need to be backported to 23.1 backport-23.1.0 labels Apr 24, 2023
Copy link
Contributor

@j82w j82w left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @maryliag)


-- commits line 9 at r3:
Can a test be added to make sure the fallback logic works?


pkg/server/combined_statement_stats.go line 83 at r3 (raw file):

	var err error
	showInternal := SQLStatsShowInternal.Get(&settings.SV)
	whereClause, orderAndLimit, args := getCombinedStatementsQueryClausesAndArgs(

getCombinedStatementsQueryClausesAndArgs should be updated so the order by and limit use the new columns in the activity table for the better perf.


pkg/server/combined_statement_stats.go line 97 at r3 (raw file):

		activityHasAllData, err = activityTablesHaveFullData(ctx, ie, testingKnobs, reqStartTime)
		if err != nil {
			return nil, serverError(ctx, err)

Should this just log the error and set activityHasAllData to false? That way even if the check fails the entire request can possibly succeed.


pkg/server/combined_statement_stats.go line 177 at r3 (raw file):

) (result bool, err error) {
	var auxDate time.Time
	dateFormat := "2006-01-02"

Why does it only have the date and not the time?


pkg/server/combined_statement_stats.go line 178 at r3 (raw file):

	var auxDate time.Time
	dateFormat := "2006-01-02"
	auxDate, err = time.Parse(dateFormat, "1970-01-01")

Should this be?
auxDate, err = time.Parse(dateFormat, reqStartTime)

Copy link
Contributor Author

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @j82w)


-- commits line 9 at r3:

Previously, j82w (Jake) wrote…

Can a test be added to make sure the fallback logic works?

The current tests that make calls to the endpoints already cover that case, we do have check when there is only in memory and then persisted. The results are as expected.


pkg/server/combined_statement_stats.go line 83 at r3 (raw file):

Previously, j82w (Jake) wrote…

getCombinedStatementsQueryClausesAndArgs should be updated so the order by and limit use the new columns in the activity table for the better perf.

All changes related to columns selection will come on a following PR, because I also need to include the cases where the column is not on the activity, and it was getting to big for one PR.

Also, since we're combining things, does it have a better performance on an aggregated column vs the statistics column? I thought the index would not matter at that point. Do we even have an aggregation for each specific column?


pkg/server/combined_statement_stats.go line 97 at r3 (raw file):

Previously, j82w (Jake) wrote…

Should this just log the error and set activityHasAllData to false? That way even if the check fails the entire request can possibly succeed.

Done


pkg/server/combined_statement_stats.go line 177 at r3 (raw file):

Previously, j82w (Jake) wrote…

Why does it only have the date and not the time?

Fixed


pkg/server/combined_statement_stats.go line 178 at r3 (raw file):

Previously, j82w (Jake) wrote…

Should this be?
auxDate, err = time.Parse(dateFormat, reqStartTime)

Actually should be now, because this is used for the case where you don't have any data on the table, so it returns this on the coalesce, meaning the min date is now. I don't want to be the same as the request because I compare at the end and if they're the same it means I have data, which is not the case.
I changed to use now

With the new sql stats tables that contain the top 500 rows
based on most used column, this PR updates the calls on the
sql stats endpoint to use the new flow:

```mermaid
flowchart TD;
    A[Compare the TS on ACTIVITY Table with the Requested TS] --> B{Is the requested time period completely on the table?}
    B -- Yes --> C[SELECT on ACTIVITY table]
    C --> D{Had results?}
    D -- Yes --> E[Return RESULTS]
    D -- No --> F[SELECT on PERSISTED table]
    B -- No ----> F
    F --> G{Had results?}
    G -- Yes --> E
    G -- No --> H[SELECT on COMBINED table]
    H --> E
```

Part Of: cockroachdb#101948

A following PR will deal when selecting a column that is not
one of the ones selected to generate the activity tables.

Release note (performance improvement): SQL Activity endpoints
now use first a table with the top data for the most used cases. If there
is no data available, it used the previous flow with persisted data and
if that is also empty, uses in-memory.
Copy link
Contributor

@j82w j82w left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@maryliag
Copy link
Contributor Author

TFTR!
bors r+

@craig
Copy link
Contributor

craig bot commented Apr 26, 2023

Build succeeded:

@craig craig bot merged commit 2066afb into cockroachdb:master Apr 26, 2023
@blathers-crl
Copy link

blathers-crl bot commented Apr 26, 2023

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 17128ce to blathers/backport-release-23.1-102026: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.1.x failed. See errors above.


error creating merge commit from 17128ce to blathers/backport-release-23.1.0-102026: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.1.0 failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@maryliag maryliag deleted the stats-endpoint branch April 26, 2023 13:56
maryliag added a commit to maryliag/cockroach that referenced this pull request Apr 26, 2023
This fix was made on the backport PRs from cockroachdb#102026,
but was missing on the original PR to master.

Part Of: cockroachdb#101948

Logs the error message, instead of returning an error,
so the endpoint can still work if there is an issue
on the activity tables.

Release note: None
craig bot pushed a commit that referenced this pull request Apr 27, 2023
102373: server: log instead of returning error r=maryliag a=maryliag

This fix was made on the backport PRs from #102026, but was missing on the original PR to master.

Part Of: #101948

Logs the error message, instead of returning an error, so the endpoint can still work if there is an issue on the activity tables.

Release note: None

Co-authored-by: maryliag <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants