Skip to content

ui: Add search and filtering to the databases pages#92589

Merged
craig[bot] merged 1 commit intomasterfrom
databases-page
Jan 5, 2023
Merged

ui: Add search and filtering to the databases pages#92589
craig[bot] merged 1 commit intomasterfrom
databases-page

Conversation

@gtr
Copy link
Copy Markdown

@gtr gtr commented Nov 28, 2022

Part Of #68826, #68825.

Previously, the databases and databases details pages did not contain
search and filter components that the txns and stmts pages did. This
change adds search and filter components to both the databases and
databases details pages. The search box filters by database/table name
while the filter allows filtering by node and region.

Databases Page video.

Tables Page video.

Release note (ui change): the databases page and the databases details
pages each now contain search and filter components, allowing the
ability to search and filter through databases and their tables.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@gtr gtr linked an issue Nov 29, 2022 that may be closed by this pull request
@gtr gtr marked this pull request as ready for review November 29, 2022 15:56
@gtr gtr requested a review from a team November 29, 2022 19:03
Copy link
Copy Markdown
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.

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


-- commits line 2 at r1:
Nit: you can't use Fixes because it still needs to be done on CC Console, so this should be Part Of, and you should include on the commit message


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 51 at r1 (raw file):

  calculateActiveFilters,
} from "src/queryFilter";
import { nodeRegions } from "src/transactionsPage/transactions.fixture";

fixture files are used for testing, if you need a new struct type, it should be created on another location

Copy link
Copy Markdown
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.

Nice work!
What happens when you're on Database details and change from tables to grants?

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


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 372 at r2 (raw file):

      {
        app: filters.app,
        timeNumber: filters.timeNumber,

you don't need to sync values that you don't actually show filters for


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 415 at r2 (raw file):

        table => {
          if (regionsSelected.length == 0 && nodesSelected.length == 0) return true;
          if (isTenant) return true;

why is returning true for tenants?


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 752 at r2 (raw file):

    const activeFilters = calculateActiveFilters(filters);

    const nodes = isTenant

tenants will have a list of nodes, we just don't show nodes info when is tenant, we hide that and show only region info


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 758 at r2 (raw file):

        .sort();

    const regions = isTenant

tenants do have regions


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 51 at r2 (raw file):

  handleFiltersFromQueryString
} from "../queryFilter";
import { merge} from "lodash";

nit: you need the space after merge


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 413 at r2 (raw file):

      {
        app: filters.app,
        timeNumber: filters.timeNumber,

ditto: sync only the values you're using on this filter


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 447 at r2 (raw file):

        db => {
          if (regionsSelected.length == 0 && nodesSelected.length == 0) return true;
          if (isTenant) return true;

same question: why returning true on this case?


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 599 at r2 (raw file):

  render(): React.ReactElement {
    this.columns.find(c => c.name === "nodeRegions").showByDefault = true;

curious: why this change?


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 620 at r2 (raw file):

        .sort();

    console.log("nodes:", Object.keys(nodeRegions).join(","));

remove this log


pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.spec.ts line 201 at r2 (raw file):

      lastError: null,
      name: "system",
      nodes: [],

if you want to test, you should add actual values for the cases where it loaded and have no error

Copy link
Copy Markdown
Author

@gtr gtr left a comment

Choose a reason for hiding this comment

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

Good question! My most recent update makes it so that when you're on the Database details page and change from tables to grants, the filters component gets hidden. The search box still works because it looks at the table name column.

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


-- commits line 2 at r1:

Previously, maryliag (Marylia Gutierrez) wrote…

Nit: you can't use Fixes because it still needs to be done on CC Console, so this should be Part Of, and you should include on the commit message

Done.


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 51 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

fixture files are used for testing, if you need a new struct type, it should be created on another location

Good catch! I added a selector for nodeRegions in the Redux layer.


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 372 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

you don't need to sync values that you don't actually show filters for

Removed all the values except nodes and regions.


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 415 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

why is returning true for tenants?

I was under the assumption that if the cluster is a tenant cluster, then the node/region would be irrelevant. Removed this line.


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 752 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

tenants will have a list of nodes, we just don't show nodes info when is tenant, we hide that and show only region info

Oh okay, got it! I removed the isTenant check for this line but added a check to the Filter's showNodes option to only show nodes when it is not a tenant and then the length of the nodes is greater than 1:

showNodes={!isTenant && nodes.length > 1}

pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 758 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

tenants do have regions

Fixed.


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 51 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

nit: you need the space after merge

Done.


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 413 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

ditto: sync only the values you're using on this filter

Done.


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 447 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

same question: why returning true on this case?

Removed this line.


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 599 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

curious: why this change?

I left this in by accident! Reverted back.


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 620 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

remove this log

Done.

Code quote:

console.log("

pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.spec.ts line 201 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

if you want to test, you should add actual values for the cases where it loaded and have no error

I added test cases for different nodes:

driver.assertDatabaseProperties("system", {
    ...
    nodes: [1, 2, 4],
    ...
    nodesByRegionString: "undefined(n1,n2,n4)",
    ...
 });

But I am unable to define a region; currently it displays undefined.

Copy link
Copy Markdown
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 3 of 6 files at r1, 1 of 3 files at r2, 6 of 6 files at r3, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @gtr)


-- commits line 4 at r3:
tip: if you just type #68826 github automatically creates the link for you, so you don't need to worry


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 415 at r2 (raw file):

Previously, gtr (Gerardo Torres Castro) wrote…

I was under the assumption that if the cluster is a tenant cluster, then the node/region would be irrelevant. Removed this line.

The line is still here :)


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 413 at r2 (raw file):

Previously, gtr (Gerardo Torres Castro) wrote…

Done.

Still seeing all the non-used value


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 447 at r2 (raw file):

Previously, gtr (Gerardo Torres Castro) wrote…

Removed this line.

Still seeing


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 611 at r3 (raw file):

    } = this.props;

    console.log("databasesPage.isTenant =", isTenant);

remove this log


pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.spec.ts line 380 at r3 (raw file):

});

// function makeStateWithNodeRegions() {

remove unused function/comment

Copy link
Copy Markdown
Author

@gtr gtr 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 4 at r3:

Previously, maryliag (Marylia Gutierrez) wrote…

tip: if you just type #68826 github automatically creates the link for you, so you don't need to worry

Got it! I had done this on the GitHub's description but not the git commit comment.


pkg/ui/workspaces/cluster-ui/src/databaseDetailsPage/databaseDetailsPage.tsx line 415 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

The line is still here :)

Oops, deleted.

Code quote:

if (isTenant) return true;

pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 413 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

Still seeing all the non-used value

Done.


pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 447 at r2 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

Still seeing

Done.

Code quote:

 if (isTenant) return true;

pkg/ui/workspaces/cluster-ui/src/databasesPage/databasesPage.tsx line 611 at r3 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

remove this log

Done.


pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.spec.ts line 380 at r3 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

remove unused function/comment

Done.

Code quote:

makeStateWithNodeRegions()

@gtr gtr force-pushed the databases-page branch 4 times, most recently from 4383f1b to 3fb09f0 Compare December 9, 2022 16:42
@gtr
Copy link
Copy Markdown
Author

gtr commented Dec 9, 2022

Updates on the pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.spec.ts test file:

In order to test the database properties (specifically nodes and nodesByRegionString, it was necessary to introduce a stubNodesUI function to the fakeAPI in order to stub in information about which nodes belong to which regions:

export function stubNodesUI(
  response: cockroach.server.serverpb.INodesResponseExternal,
) {
  stubGet(`/nodes_ui`, NodesResponse.encode(response), STATUS_PREFIX);
}

The assertion happens after we fill in the database details and node/region info:

driver.assertDatabaseProperties("system", {
    ...
    name: "system",
    nodes: [1, 2, 4],
    sizeInBytes: 7168,
    tableCount: 2,
    rangeCount: 3,
    nodesByRegionString: "gcp-us-east1(n1,n2,n4)",
    ...
});

driver.assertDatabaseProperties("test", {
    ...
    name: "test",
    nodes: [3, 5, 6],
    sizeInBytes: 1234,
    tableCount: 1,
    rangeCount: 42,
    nodesByRegionString: "gcp-europe-west1(n3,n6), gcp-europe-west2(n5)",
    ...
});

The next part of testing this function involves recognizing whether the cluster is a tenant cluster. If so, we redact node information and only show the regions for nodesByRegionString, e.g. "gcp-europe-west1(n3,n6), gcp-europe-west2(n5)" becomes "gcp-europe-west1, gcp-europe-west2". This was a little more difficult to test since from my understanding, we don't support multi tenant on db-console so when connecting the state to the props in pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.ts, I hardcoded a value for isTenant:

// Hardcoded isTenant value for db-console.
const isTenant = false;

However, I modified the functions that generate the nodesByRegionString value to be aware of the isTenant value. So if we change the isTenant hardcoded value to true, this is what we see in the UI:

image

The region column and the region filter only displays the region names. However, I'm still not entirely convinced that we should hard code this value since there would be three places where we would have to do so:

  • db-console/src/views/databases/databasesPage/redux.ts
  • db-console/src/views/databases/databaseDetailsPage/redux.ts
  • db-console/src/views/databases/databaseTablePage/redux.ts

Part of #68826, #68825.

Previously, the databases and databases details pages did not contain
search and filter components that the txns and stmts pages did. This
change adds search and filter components to both the databases and
databases details pages. The search box filters by database/table name
while the filter allows filtering by node and region.

Release note (ui change): the databases page and the databases details
pages each now contain search and filter components, allowing the
ability to search and filter through databases and their tables.
Copy link
Copy Markdown
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.

The value for isTenant is only set when the page comes from CC on the props, but we don't set it when coming from DB console, this way the value will be undefined and when doing checks of isTenant? it will only be true when coming from CC, but undefined from DB console.
Because we only use on the page itself, we don't need to worry about setting a value for DB console, but now because you changed some of the functions definitions/parameter on the redux file, then you indeed need to hard code a value to be passed on.

Reviewed 10 of 10 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @gtr)

@gtr
Copy link
Copy Markdown
Author

gtr commented Jan 5, 2023

The value for isTenant is only set when the page comes from CC on the props, but we don't set it when coming from DB console, this way the value will be undefined and when doing checks of isTenant? it will only be true when coming from CC, but undefined from DB console. Because we only use on the page itself, we don't need to worry about setting a value for DB console, but now because you changed some of the functions definitions/parameter on the redux file, then you indeed need to hard code a value to be passed on.

Reviewed 10 of 10 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @gtr)

Okay that makes sense, TFTR!

@gtr
Copy link
Copy Markdown
Author

gtr commented Jan 5, 2023

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 5, 2023

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.

ui: add search to the databases pages

3 participants