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: unify cluster-ui stores for Statement and Transaction Page #72627

Merged
merged 1 commit into from
Nov 24, 2021

Conversation

Azhng
Copy link
Contributor

@Azhng Azhng commented Nov 10, 2021

Previously, on CC Conosle, Statement Page and Transaction Page were backed by
their own Redux stores and their own Redux Sagas. However, both Statement
and Transaction Page were backed by a single API endpoint, namely
/_status/statements. This resulted in unnecessary API calls and bugs
like #72009, which was caused by Reset SQL Stats sagas failing to
reset the Transaction Page Redux store.

This commit unifies the following Redux store and sagas into a single
store / sagas:

  1. Statement Page store / sagas
  2. Transaciton Page store / sagas
  3. Reset SQL Stats store / sagas

This greatly removed the code duplication and test duplication and simplify
the logic. Statement Page and Transaction Page can reuse the same store
by their own selectors.

Resolves #72009

Release note: None

CC Console:

cc.mov

DB Console:

Screen.Recording.2021-11-09.at.23.07.17.mov

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@Azhng Azhng force-pushed the unify-redux-store branch from 279f030 to ab15b8e Compare November 11, 2021 02:36
@Azhng Azhng requested a review from a team November 11, 2021 02:36
@Azhng Azhng marked this pull request as ready for review November 11, 2021 02:36
Copy link
Contributor

@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.

Reviewed 19 of 23 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @Azhng and @maryliag)


pkg/ui/workspaces/cluster-ui/src/store/sagas.ts, line 31 at r1 (raw file):

    fork(notifificationsSaga),
    fork(sqlStatsSaga),
    fork(terminateSaga),

what is this one for?


pkg/ui/workspaces/cluster-ui/src/store/sqlStats/sqlStats.sagas.spec.ts, line 54 at r1 (raw file):

    });

    it("requests combined SQL Stats if combined=true in the request message", () => {

nit: test also with combined false


pkg/ui/workspaces/db-console/src/redux/sqlStats/sqlStatsSagas.ts, line 33 at r1 (raw file):

    yield put(resetSQLStatsCompleteAction());
    yield put(invalidateStatements());
    yield put(refreshStatements() as any);

we don't want to refresh sql stats here?

@Azhng Azhng force-pushed the unify-redux-store branch from ab15b8e to d5f9d60 Compare November 17, 2021 19:40
Copy link
Contributor Author

@Azhng Azhng 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)


pkg/ui/workspaces/cluster-ui/src/store/sagas.ts, line 31 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

what is this one for?

Removed, I noticed we had an unused import for terminateSaga and thought we just missed it. I just remembered that we disabled that button already.


pkg/ui/workspaces/cluster-ui/src/store/sqlStats/sqlStats.sagas.spec.ts, line 54 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

nit: test also with combined false

Done.


pkg/ui/workspaces/db-console/src/redux/sqlStats/sqlStatsSagas.ts, line 33 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

we don't want to refresh sql stats here?

I am a bit uncertain about this. If we invalidate the state, this would cause the selector to return null, which in turn will trigger the componentDidUpdate() React component hook, which in turn will invoke the refreshStatement sagas anyway.

That's why I'm a bit not so sure if we should let the React component to handle this or if we should let the Sagas to handle this. Thoughts ?

Copy link
Contributor

@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.

Reviewed 1 of 23 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @Azhng and @maryliag)


pkg/ui/workspaces/db-console/src/redux/sqlStats/sqlStatsSagas.ts, line 33 at r1 (raw file):

Previously, Azhng (Archer Zhang) wrote…

I am a bit uncertain about this. If we invalidate the state, this would cause the selector to return null, which in turn will trigger the componentDidUpdate() React component hook, which in turn will invoke the refreshStatement sagas anyway.

That's why I'm a bit not so sure if we should let the React component to handle this or if we should let the Sagas to handle this. Thoughts ?

If we keep the refresh here, is the refreshStatement being called twice? (here and on the component did mount), or if we call it here it doesn't get called there again?
If is being called twice, there isn't need for the refresh here, otherwise we can keep this here

Previously, on CC Conosle, Statement Page and Transaction Page were backed by
their own Redux stores and their own Redux Sagas. However, both Statement
and Transaction Page were backed by a single API endpoint, namely
`/_status/statements`. This resulted in unnecessary API calls and bugs
like cockroachdb#72009, which was caused by Reset SQL Stats sagas failing to
reset the Transaction Page Redux store.

This commit unifies the following Redux store and sagas into a single
store / sagas:
1. Statement Page store / sagas
2. Transaciton Page store / sagas
3. Reset SQL Stats store / sagas

This greatly removed the code duplication and test duplication and simplify
the logic. Statement Page and Transaction Page can reuse the same store
by their own selectors.

Resolves cockroachdb#72009

Release note: None
@Azhng Azhng force-pushed the unify-redux-store branch from d5f9d60 to f35c4a8 Compare November 22, 2021 17:59
Copy link
Contributor Author

@Azhng Azhng 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)


pkg/ui/workspaces/db-console/src/redux/sqlStats/sqlStatsSagas.ts, line 33 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

If we keep the refresh here, is the refreshStatement being called twice? (here and on the component did mount), or if we call it here it doesn't get called there again?
If is being called twice, there isn't need for the refresh here, otherwise we can keep this here

Hmm thinking about this a bit more, if we refresh here, then yes refreshStatement() will called twice, (once here and once on the component did update).

However I think that is probably fine, since refreshStatement() is only issuing refresh redux actions. Since this is backed by a CachedDataReducer, two subsequent refresh actions will only result in API calls.

I think letting the saga to deal with the refresh would be ideal for the long term, as we move to use functional components and no longer rely on React lifecycle method in the future.

Added refreshStatements() call here.

Copy link
Contributor

@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.

:lgtm:

Reviewed 4 of 4 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @Azhng)

@Azhng
Copy link
Contributor Author

Azhng commented Nov 24, 2021

TFTR!

bors r=maryliag

@craig
Copy link
Contributor

craig bot commented Nov 24, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Nov 24, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Nov 24, 2021

Build failed:

@Azhng
Copy link
Contributor Author

Azhng commented Nov 24, 2021

bors r=maryliag

@craig craig bot merged commit 8fa3a38 into cockroachdb:master Nov 24, 2021
@craig
Copy link
Contributor

craig bot commented Nov 24, 2021

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clear SQL stats on the Transactions page does not work on serverless
3 participants