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: add selected period as part of cached key #77450

Merged
merged 1 commit into from
Mar 10, 2022

Conversation

maryliag
Copy link
Contributor

@maryliag maryliag commented Mar 7, 2022

Previously, the fingerprint id and the app names were used
as a key for a statement details cache. This commits adds
the start and end time (when existing) to the key, so
the details are correctly assigned to the selected period.

This commit also rounds the selected value period to the hour,
since that is what is used on the persisted statistics, with
the start value keeping the hour and the end value adding one
hour, for example:
start: 17:45:23 -> 17:00:00
end: 20:14:32 -> 21:00:00

Partially addresses #72129

Release note: None
Release Justification: Low risk, high benefit change

@maryliag maryliag requested a review from a team March 7, 2022 19:56
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

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

Hmm seems like a couple unit tests are failing

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


-- commits, line 42 at r2:
nit: dup release justification


pkg/ui/workspaces/cluster-ui/src/util/appStats/appStats.ts, line 302 at r2 (raw file):

      if (apps[i].includes("$ internal")) {
        apps[i] = "$ internal";
      }

I just realized that, wouldn't we have multiple $ internal app names in the app_names field in this case 🤔, Perhaps we can use a Set here?


pkg/ui/workspaces/db-console/src/redux/apiReducers.ts, line 15 at r2 (raw file):

import moment from "moment";
import { util } from "@cockroachlabs/cluster-ui";
const { generateStmtDetailsToID } = util;

Hmm, can we directly import generateStmtDetailsToID here? Since appStats package does have a top-level index.ts for package wide export

@maryliag maryliag force-pushed the changetime branch 2 times, most recently from 562d368 to 6f287bb Compare March 9, 2022 17:38
Copy link
Contributor

@matthewtodd matthewtodd left a comment

Choose a reason for hiding this comment

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

Other than test failures, :lgtm:

Reviewed 5 of 9 files at r2, 30 of 30 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @maryliag)

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 (and 1 stale) (waiting on @Azhng and @matthewtodd)


-- commits, line 42 at r2:

Previously, Azhng (Archer Zhang) wrote…

nit: dup release justification

Fixed


pkg/ui/workspaces/cluster-ui/src/util/appStats/appStats.ts, line 302 at r2 (raw file):

Previously, Azhng (Archer Zhang) wrote…

I just realized that, wouldn't we have multiple $ internal app names in the app_names field in this case 🤔, Perhaps we can use a Set here?

Fixed


pkg/ui/workspaces/db-console/src/redux/apiReducers.ts, line 15 at r2 (raw file):

Previously, Azhng (Archer Zhang) wrote…

Hmm, can we directly import generateStmtDetailsToID here? Since appStats package does have a top-level index.ts for package wide export

The util is imported as its own name, and that one has its own imported files, so for the utils and api we need to import this way

Code quote:

const { generateStmtDetailsToID } = util;

Previously, the fingerprint id and the app names were used
as a key for a statement details cache. This commits adds
the start and end time (when existing) to the key, so
the details are correctly assigned to the selected period.

This commit also rounds the selected value period to the hour,
since that is what is used on the persisted statistics, with
the start value keeping the hour and the end value adding one
hour, for example:
start: 17:45:23  ->  17:00:00
end:   20:14:32  ->  21:00:00

Partially addresses cockroachdb#72129

Release note: None
Release Justification: Low risk, high benefit change
Copy link
Contributor

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

Reviewed 1 of 3 files at r4.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng, @maryliag, and @matthewtodd)


pkg/ui/workspaces/cluster-ui/src/util/dataFromServer.ts, line 20 at r5 (raw file):

  OIDCAutoLogin: boolean;
  OIDCLoginEnabled: boolean;
  OIDCButtonText: string;

Hmm, what are these new fields for 🤔, are they related to the CI test failures somehow ?

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 (and 1 stale) (waiting on @Azhng and @matthewtodd)


pkg/ui/workspaces/cluster-ui/src/util/dataFromServer.ts, line 20 at r5 (raw file):

Previously, Azhng (Archer Zhang) wrote…

Hmm, what are these new fields for 🤔, are they related to the CI test failures somehow ?

related to test failures

Copy link
Contributor

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng, @maryliag, and @matthewtodd)


pkg/ui/workspaces/cluster-ui/src/util/dataFromServer.ts, line 20 at r5 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

related to test failures

Out of curiosity, how did this fix the CI failure ?

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! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng and @matthewtodd)


pkg/ui/workspaces/cluster-ui/src/util/dataFromServer.ts, line 20 at r5 (raw file):

Previously, Azhng (Archer Zhang) wrote…

Out of curiosity, how did this fix the CI failure ?

This interface exists on both db console and cluster-ui, and the cluster-ui was missing those fields. Our guess is that it was always importing the one from db console first (for tests, etc), but I added a new dependency on package.json and that must have changed some order of import and was getting the one from here first, which was missing those fields and creating the failure.
It's weird that never happened before but it was bound to happen any day and my Pr was the "lucky" one

Copy link
Contributor

@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! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng, @maryliag, and @matthewtodd)


pkg/ui/workspaces/cluster-ui/src/util/dataFromServer.ts, line 20 at r5 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

This interface exists on both db console and cluster-ui, and the cluster-ui was missing those fields. Our guess is that it was always importing the one from db console first (for tests, etc), but I added a new dependency on package.json and that must have changed some order of import and was getting the one from here first, which was missing those fields and creating the failure.
It's weird that never happened before but it was bound to happen any day and my Pr was the "lucky" one

that's pretty interesting :D

Copy link
Contributor

@jocrl jocrl 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! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @Azhng, @jocrl, @maryliag, and @matthewtodd)


pkg/ui/workspaces/cluster-ui/src/store/statementDetails/statementDetails.sagas.ts, line 32 at r5 (raw file):

  action: PayloadAction<StatementDetailsRequest>,
): any {
  const key = action?.payload

So I'm suspecting that in your #77215 PR which added this function, that this action?.payload ... : "" was added in order to mimic the getStatements vs getCombinedStatements forking in sqlStats.sagas.ts's requestSQLStatsSaga.

Now that we know what that forking was about, should there actually be a forking here? Is there actually a use case where the key should be ""? I'm thinking not since action in the function signature is required, and because I'm not sure what a "" key would mean.

Code quote:

  const key = action?.payload
    ? generateStmtDetailsToID(
        action.payload.fingerprint_id,
        action.payload.app_names.toString(),
        action.payload.start,
        action.payload.end,
      )
    : "";

pkg/ui/workspaces/cluster-ui/src/timeScaleDropdown/utils.ts, line 90 at r5 (raw file):

};

export const toRoundedDateRange = (

Could you add a comment explaining the cluster setting in the back end that this is tied to?

Separately, I know we don't currently expose the setting to users. But does this front end assumption of the aggregation interval (I think it's aggregation interval?) limit our ability to develop and test front end functionality? E.g., if we want to generate data to test that aggregation intervals are correctly combined, one way would be to lower the aggregation interval so that you don't actually have to wait an hour. Or if you want to generate data to test that the time picker works correctly to retrieve different data.

If this rounding does affect dev-ability, one could in theory modify this function to change the number when developing. But that becomes one more thing to have to know to change, and runs the risk of accidentally being checked in + administrative back and forth if PRs accidentally check it in.

@maryliag
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Mar 10, 2022

Build succeeded:

@craig craig bot merged commit 8d046fc into cockroachdb:master Mar 10, 2022
@maryliag maryliag deleted the changetime branch March 10, 2022 19:45
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.

5 participants