From 0d8990c743ddd00937f005719e010d52c9052a3c Mon Sep 17 00:00:00 2001 From: Bikash Date: Tue, 10 Sep 2024 16:48:33 +0545 Subject: [PATCH 1/4] cluster status issue --- gql-queries-generator/doc/queries.graphql | 13 ++++++ .../console/hooks/use-cluster-status-v2.tsx | 33 ++++++++------ .../server/gql/queries/cluster-queries.ts | 45 ++++++++++++++----- src/generated/gql/server.ts | 10 +++++ 4 files changed, 78 insertions(+), 23 deletions(-) diff --git a/gql-queries-generator/doc/queries.graphql b/gql-queries-generator/doc/queries.graphql index d15e9ea68..3e53ff5b0 100644 --- a/gql-queries-generator/doc/queries.graphql +++ b/gql-queries-generator/doc/queries.graphql @@ -394,6 +394,19 @@ query consoleGetCluster($name: String!) { } } +query consoleListClusterStatus($pagination: CursorPaginationIn) { + infra_listBYOKClusters(pagination: $pagination) { + edges { + node { + lastOnlineAt + metadata { + name + } + } + } + } +} + query consoleGetKubeConfig($name: String!) { infra_getCluster(name: $name) { adminKubeconfig { diff --git a/src/apps/console/hooks/use-cluster-status-v2.tsx b/src/apps/console/hooks/use-cluster-status-v2.tsx index 88b29301d..f7acb54ac 100644 --- a/src/apps/console/hooks/use-cluster-status-v2.tsx +++ b/src/apps/console/hooks/use-cluster-status-v2.tsx @@ -13,10 +13,10 @@ import { import { useSocketWatch } from '~/root/lib/client/helpers/socket/useWatch'; import useDebounce from '~/root/lib/client/hooks/use-debounce'; import { useConsoleApi } from '../server/gql/api-provider'; -import { IByocClusters } from '../server/gql/queries/byok-cluster-queries'; import { ExtractNodeType, parseNodes } from '../server/r-utils/common'; +import { IClustersStatus } from '../server/gql/queries/cluster-queries'; -type IClusterMap = { [key: string]: ExtractNodeType }; +type IClusterMap = { [key: string]: ExtractNodeType }; const ClusterStatusContext = createContext<{ clusters: IClusterMap; @@ -36,14 +36,15 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => { const listCluster = useCallback(async () => { try { - const cl = await api.listAllClusters(); - const parsed = parseNodes(cl.data).reduce( - (acc, c) => { - acc[c.metadata.name] = c; - return acc; + const cl = await api.listClusterStatus({ + pagination: { + first: 5, }, - {} as { [key: string]: ExtractNodeType }, - ); + }); + const parsed = parseNodes(cl.data).reduce((acc, c) => { + acc[c.metadata.name] = c; + return acc; + }, {} as IClusterMap); setClusters(parsed); return clusters; } catch (err) { @@ -56,8 +57,18 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => { const interval = setInterval(() => { listCluster(); }, 30 * 1000); + + const onlineEvent = () => { + setTimeout(() => { + listCluster(); + }, 3000); + }; + + window.addEventListener('online', onlineEvent); + return () => { clearInterval(interval); + window.removeEventListener('online', onlineEvent); }; }, []); @@ -73,10 +84,6 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => { setUpdate((p) => !p); }, topic); - useEffect(() => { - console.log('helre', topic); - }, [topic]); - return ( ; export type IClusters = NN; +export type IClustersStatus = NN< + ConsoleListClusterStatusQuery['infra_listClusters'] +>; export type IDnsHosts = NN['infra_listClusters']; @@ -50,7 +55,7 @@ export const clusterQueries = (executor: IExecutor) => ({ return data.infra_listClusters; }, vars(_: ConsoleListDnsHostsQueryVariables) {}, - } + }, ), createCluster: executor( @@ -65,7 +70,7 @@ export const clusterQueries = (executor: IExecutor) => ({ transformer: (data: ConsoleCreateClusterMutation) => data.infra_createCluster, vars(_: ConsoleCreateClusterMutationVariables) {}, - } + }, ), deleteCluster: executor( gql` @@ -77,7 +82,7 @@ export const clusterQueries = (executor: IExecutor) => ({ transformer: (data: ConsoleDeleteClusterMutation) => data.infra_deleteCluster, vars(_: ConsoleDeleteClusterMutationVariables) {}, - } + }, ), clustersCount: executor( gql` @@ -90,7 +95,7 @@ export const clusterQueries = (executor: IExecutor) => ({ { transformer: (data: ConsoleClustersCountQuery) => data.infra_listClusters, vars(_: ConsoleClustersCountQueryVariables) {}, - } + }, ), listAllClusters: executor( @@ -271,9 +276,8 @@ export const clusterQueries = (executor: IExecutor) => ({ { transformer: (data: ConsoleListAllClustersQuery) => data.byok_clusters, vars(_: ConsoleListAllClustersQueryVariables) {}, - } + }, ), - listClusters: executor( gql` query Infra_listClusterss( @@ -396,7 +400,7 @@ export const clusterQueries = (executor: IExecutor) => ({ { transformer: (data: ConsoleListClustersQuery) => data.infra_listClusters, vars(_: ConsoleListClustersQueryVariables) {}, - } + }, ), getCluster: executor( gql` @@ -502,7 +506,28 @@ export const clusterQueries = (executor: IExecutor) => ({ { transformer: (data: ConsoleGetClusterQuery) => data.infra_getCluster, vars(_: ConsoleGetClusterQueryVariables) {}, - } + }, + ), + listClusterStatus: executor( + gql` + query listCluster($pagination: CursorPaginationIn) { + infra_listBYOKClusters(pagination: $pagination) { + edges { + node { + lastOnlineAt + metadata { + name + } + } + } + } + } + `, + { + transformer: (data: ConsoleListClusterStatusQuery) => + data.infra_listBYOKClusters, + vars(_: ConsoleListClusterStatusQueryVariables) {}, + }, ), getKubeConfig: executor( gql` @@ -518,7 +543,7 @@ export const clusterQueries = (executor: IExecutor) => ({ { transformer: (data: ConsoleGetKubeConfigQuery) => data.infra_getCluster, vars(_: ConsoleGetClusterQueryVariables) {}, - } + }, ), updateCluster: executor( gql` @@ -532,6 +557,6 @@ export const clusterQueries = (executor: IExecutor) => ({ transformer: (data: ConsoleUpdateClusterMutation) => data.infra_updateCluster, vars(_: ConsoleUpdateClusterMutationVariables) {}, - } + }, ), }); diff --git a/src/generated/gql/server.ts b/src/generated/gql/server.ts index af30cf3df..92591c841 100644 --- a/src/generated/gql/server.ts +++ b/src/generated/gql/server.ts @@ -2192,6 +2192,16 @@ export type ConsoleGetClusterQuery = { }; }; +export type ConsoleListClusterStatusQueryVariables = Exact<{ + pagination?: InputMaybe; +}>; + +export type ConsoleListClusterStatusQuery = { + infra_listBYOKClusters?: { + edges: Array<{ node: { lastOnlineAt?: any; metadata: { name: string } } }>; + }; +}; + export type ConsoleGetKubeConfigQueryVariables = Exact<{ name: Scalars['String']['input']; }>; From 65f7996d2c5f30a10b6a1e6526f39d031f574efa Mon Sep 17 00:00:00 2001 From: Bikash Date: Tue, 10 Sep 2024 16:50:25 +0545 Subject: [PATCH 2/4] cluster status issue --- src/apps/console/hooks/use-cluster-status-v2.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/console/hooks/use-cluster-status-v2.tsx b/src/apps/console/hooks/use-cluster-status-v2.tsx index f7acb54ac..702360adf 100644 --- a/src/apps/console/hooks/use-cluster-status-v2.tsx +++ b/src/apps/console/hooks/use-cluster-status-v2.tsx @@ -38,7 +38,7 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => { try { const cl = await api.listClusterStatus({ pagination: { - first: 5, + first: 500, }, }); const parsed = parseNodes(cl.data).reduce((acc, c) => { From bf8349a04b38f2572acf50bd0c769be404a37290 Mon Sep 17 00:00:00 2001 From: Bikash Date: Tue, 10 Sep 2024 16:53:13 +0545 Subject: [PATCH 3/4] code refactor --- src/apps/console/hooks/use-cluster-status-v2.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/console/hooks/use-cluster-status-v2.tsx b/src/apps/console/hooks/use-cluster-status-v2.tsx index 702360adf..6b9475e1b 100644 --- a/src/apps/console/hooks/use-cluster-status-v2.tsx +++ b/src/apps/console/hooks/use-cluster-status-v2.tsx @@ -36,17 +36,17 @@ const ClusterStatusProvider = ({ children }: { children: ReactNode }) => { const listCluster = useCallback(async () => { try { - const cl = await api.listClusterStatus({ + const { data } = await api.listClusterStatus({ pagination: { first: 500, }, }); - const parsed = parseNodes(cl.data).reduce((acc, c) => { + const parsed = parseNodes(data).reduce((acc, c) => { acc[c.metadata.name] = c; return acc; }, {} as IClusterMap); setClusters(parsed); - return clusters; + return parsed; } catch (err) { console.error(err); return false; From 807ce737e7a7d8f0e323b1748c59e210ff5f8d47 Mon Sep 17 00:00:00 2001 From: Bikash Date: Tue, 10 Sep 2024 16:57:41 +0545 Subject: [PATCH 4/4] fixed ts error --- src/apps/console/server/gql/queries/cluster-queries.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/console/server/gql/queries/cluster-queries.ts b/src/apps/console/server/gql/queries/cluster-queries.ts index 4f0d1460b..6f475b889 100644 --- a/src/apps/console/server/gql/queries/cluster-queries.ts +++ b/src/apps/console/server/gql/queries/cluster-queries.ts @@ -26,7 +26,7 @@ import { export type ICluster = NN; export type IClusters = NN; export type IClustersStatus = NN< - ConsoleListClusterStatusQuery['infra_listClusters'] + ConsoleListClusterStatusQuery['infra_listBYOKClusters'] >; export type IDnsHosts = NN['infra_listClusters'];