From 700649c1a7afc20915269647084e73583e792bed Mon Sep 17 00:00:00 2001 From: maryliag Date: Fri, 2 Dec 2022 15:23:50 -0500 Subject: [PATCH] ui: fix link for index from insights Previously, the link to index details on the drop index insights was using the URL format used by DB Console only. This commit updates to use the correct format when loading from CC Console. Fix #92944 Release note (bug fix): Fix link to index details on drop index insights on CC Console. --- .../cluster-ui/src/api/schemaInsightsApi.ts | 5 ++++- .../schemaInsights/indexUsageStatsRec.spec.ts | 5 +++++ .../schemaInsights/schemaInsights.fixture.ts | 2 ++ .../workspaces/cluster-ui/src/insights/types.ts | 1 + .../src/insightsTable/insightsTable.tsx | 17 ++++++++++------- .../schemaInsights/schemaInsights.sagas.spec.ts | 1 + 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pkg/ui/workspaces/cluster-ui/src/api/schemaInsightsApi.ts b/pkg/ui/workspaces/cluster-ui/src/api/schemaInsightsApi.ts index e3a7c1f6fd34..dd5a12a4e6c8 100644 --- a/pkg/ui/workspaces/cluster-ui/src/api/schemaInsightsApi.ts +++ b/pkg/ui/workspaces/cluster-ui/src/api/schemaInsightsApi.ts @@ -35,6 +35,7 @@ export type ClusterIndexUsageStatistic = { database_id: number; database_name: string; unused_threshold: string; + schema_name: string; }; type CreateIndexRecommendationsResponse = { @@ -68,12 +69,13 @@ function clusterIndexUsageStatsToSchemaInsight( results[key] = { type: "DropIndex", database: row.database_name, - query: `DROP INDEX ${row.table_name}@${row.index_name};`, + query: `DROP INDEX ${row.schema_name}.${row.table_name}@${row.index_name};`, indexDetails: { table: row.table_name, indexID: row.index_id, indexName: row.index_name, lastUsed: result.reason, + schema: row.schema_name, }, }; } @@ -136,6 +138,7 @@ const dropUnusedIndexQuery: SchemaInsightQuery = { t.name as table_name, t.parent_id as database_id, t.database_name, + t.schema_name, (SELECT value FROM crdb_internal.cluster_settings WHERE variable = 'sql.index_recommendation.drop_unused_duration') AS unused_threshold FROM "".crdb_internal.index_usage_statistics AS us JOIN "".crdb_internal.table_indexes as ti ON us.index_id = ti.index_id AND us.table_id = ti.descriptor_id diff --git a/pkg/ui/workspaces/cluster-ui/src/insights/schemaInsights/indexUsageStatsRec.spec.ts b/pkg/ui/workspaces/cluster-ui/src/insights/schemaInsights/indexUsageStatsRec.spec.ts index 14e176f4b2e6..117a2be9d38a 100644 --- a/pkg/ui/workspaces/cluster-ui/src/insights/schemaInsights/indexUsageStatsRec.spec.ts +++ b/pkg/ui/workspaces/cluster-ui/src/insights/schemaInsights/indexUsageStatsRec.spec.ts @@ -30,6 +30,7 @@ describe("recommendDropUnusedIndex", () => { table_name: "test_table", database_id: 1, database_name: "test_db", + schema_name: "public", unused_threshold: "10h0m0s", }; it("should not recommend index to be dropped", () => { @@ -49,6 +50,7 @@ describe("recommendDropUnusedIndex", () => { table_name: "test_table", database_id: 1, database_name: "test_db", + schema_name: "public", unused_threshold: "10h0m0s", }; it("should recommend index to be dropped with the reason that the index is never used", () => { @@ -68,6 +70,7 @@ describe("recommendDropUnusedIndex", () => { table_name: "test_table", database_id: 1, database_name: "test_db", + schema_name: "public", unused_threshold: "0h30m0s", }; it("should recommend index to be dropped with the reason that it has exceeded the configured index unuse duration", () => { @@ -92,6 +95,7 @@ describe("recommendDropUnusedIndex", () => { table_name: "test_table", database_id: 1, database_name: "test_db", + schema_name: "public", unused_threshold: "10h0m0s", }; it("should not recommend index to be dropped", () => { @@ -113,6 +117,7 @@ describe("recommendDropUnusedIndex", () => { table_name: "test_table", database_id: 1, database_name: "test_db", + schema_name: "public", unused_threshold: "0h30m0s", }; it("should recommend index to be dropped with the reason that it has exceeded the configured index unuse duration", () => { diff --git a/pkg/ui/workspaces/cluster-ui/src/insights/schemaInsights/schemaInsights.fixture.ts b/pkg/ui/workspaces/cluster-ui/src/insights/schemaInsights/schemaInsights.fixture.ts index cbf4463f93fa..ba4f9469cbad 100644 --- a/pkg/ui/workspaces/cluster-ui/src/insights/schemaInsights/schemaInsights.fixture.ts +++ b/pkg/ui/workspaces/cluster-ui/src/insights/schemaInsights/schemaInsights.fixture.ts @@ -19,6 +19,7 @@ export const SchemaInsightsPropsFixture: SchemaInsightsViewProps = { table: "table_name", indexID: 1, indexName: "index_name", + schema: "public", lastUsed: "This index has not been used and can be removed for better write performance.", }, @@ -30,6 +31,7 @@ export const SchemaInsightsPropsFixture: SchemaInsightsViewProps = { table: "table_name2", indexID: 2, indexName: "index_name2", + schema: "public", lastUsed: "This index has not been used in over 9 days, 5 hours, and 3 minutes and can be removed for better write performance.", }, diff --git a/pkg/ui/workspaces/cluster-ui/src/insights/types.ts b/pkg/ui/workspaces/cluster-ui/src/insights/types.ts index 52dbb13820ea..fc860e48b28d 100644 --- a/pkg/ui/workspaces/cluster-ui/src/insights/types.ts +++ b/pkg/ui/workspaces/cluster-ui/src/insights/types.ts @@ -340,6 +340,7 @@ export interface InsightRecommendation { export interface indexDetails { table: string; + schema: string; indexID: number; indexName: string; lastUsed?: string; diff --git a/pkg/ui/workspaces/cluster-ui/src/insightsTable/insightsTable.tsx b/pkg/ui/workspaces/cluster-ui/src/insightsTable/insightsTable.tsx index 2e159da43fba..2ba6352c28de 100644 --- a/pkg/ui/workspaces/cluster-ui/src/insightsTable/insightsTable.tsx +++ b/pkg/ui/workspaces/cluster-ui/src/insightsTable/insightsTable.tsx @@ -110,6 +110,7 @@ function descriptionCell( insightRec: InsightRecommendation, showQuery: boolean, disableStmtLink: boolean, + isCockroachCloud: boolean, ): React.ReactElement { const stmtLink = showQuery || isIndexRec(insightRec) ? ( @@ -125,6 +126,11 @@ function descriptionCell( {"."} ); + + const indexLink = isCockroachCloud + ? `databases/${insightRec.database}/${insightRec.indexDetails?.schema}/${insightRec.indexDetails?.table}/${insightRec.indexDetails?.indexName}` + : `database/${insightRec.database}/table/${insightRec.indexDetails?.table}/index/${insightRec.indexDetails?.indexName}`; + switch (insightRec.type) { case "CreateIndex": case "ReplaceIndex": @@ -143,10 +149,7 @@ function descriptionCell( <>
Index: {" "} - + {insightRec.indexDetails.indexName}
@@ -312,7 +315,7 @@ const isIndexRec = (rec: InsightRecommendation) => { }; export function makeInsightsColumns( - hideAction: boolean, + isCockroachCloud: boolean, showQuery?: boolean, disableStmtLink?: boolean, ): ColumnDescriptor[] { @@ -327,13 +330,13 @@ export function makeInsightsColumns( name: "details", title: insightsTableTitles.details(), cell: (item: InsightRecommendation) => - descriptionCell(item, showQuery, disableStmtLink), + descriptionCell(item, showQuery, disableStmtLink, isCockroachCloud), sort: (item: InsightRecommendation) => item.type, }, { name: "action", title: insightsTableTitles.actions(), - cell: (item: InsightRecommendation) => actionCell(item, hideAction), + cell: (item: InsightRecommendation) => actionCell(item, isCockroachCloud), }, ]; } diff --git a/pkg/ui/workspaces/cluster-ui/src/store/schemaInsights/schemaInsights.sagas.spec.ts b/pkg/ui/workspaces/cluster-ui/src/store/schemaInsights/schemaInsights.sagas.spec.ts index 20fddcadf407..d4c0abfbd5d4 100644 --- a/pkg/ui/workspaces/cluster-ui/src/store/schemaInsights/schemaInsights.sagas.spec.ts +++ b/pkg/ui/workspaces/cluster-ui/src/store/schemaInsights/schemaInsights.sagas.spec.ts @@ -49,6 +49,7 @@ describe("SchemaInsights sagas", () => { table: "test_table", indexName: "test_idx", indexID: 1, + schema: "public", lastUsed: "2022-08-22T22:30:02Z", }, },