Skip to content

fix(Tablet): remove nodeId from header and api requests for tablet #1461

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

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/containers/Header/breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ const getStorageGroupBreadcrumbs: GetBreadcrumbs<StorageGroupBreadcrumbsOptions>
};

const getTabletBreadcrumbs: GetBreadcrumbs<TabletBreadcrumbsOptions> = (options, query = {}) => {
const {tabletId, tabletType, nodeId, nodeRole, nodeActiveTab = TABLETS, tenantName} = options;
const {tabletId, tabletType, tenantName} = options;

const breadcrumbs = getNodeBreadcrumbs({nodeId, nodeRole, nodeActiveTab, tenantName}, query);
const breadcrumbs = tenantName
? getTenantBreadcrumbs(options, query)
: getClusterBreadcrumbs(options, query);

const lastItem = {
text: tabletId || headerKeyset('breadcrumbs.tablet'),
Expand Down
40 changes: 5 additions & 35 deletions src/containers/Tablet/Tablet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import {PageMetaWithAutorefresh} from '../../components/PageMeta/PageMeta';
import {getTabletPagePath} from '../../routes';
import {selectIsUserAllowedToMakeChanges} from '../../store/reducers/authentication/authentication';
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
import {nodeApi} from '../../store/reducers/node/node';
import {tabletApi} from '../../store/reducers/tablet';
import {EFlag} from '../../types/api/enums';
import type {TTabletStateInfo} from '../../types/api/tablet';
import {EType} from '../../types/api/tablet';
import type {ITabletPreparedHistoryItem} from '../../types/store/tablet';
import {cn} from '../../utils/cn';
import {CLUSTER_DEFAULT_TITLE} from '../../utils/constants';
Expand Down Expand Up @@ -59,12 +57,9 @@ const TABLET_PAGE_TABS = [
];

const tabletTabSchema = z.nativeEnum(TABLET_TABS_IDS).catch(TABLET_TABS_IDS.history);
const eTypeSchema = z.nativeEnum(EType).or(z.undefined()).catch(undefined);

const tabletQueryParams = {
nodeId: StringParam,
tenantName: StringParam,
type: StringParam,
clusterName: StringParam,
activeTab: StringParam,
};
Expand All @@ -74,18 +69,12 @@ export function Tablet() {

const {id} = useParams<{id: string}>();

const [
{
nodeId: queryNodeId,
tenantName: queryDatabase,
type: queryTabletType,
clusterName: queryClusterName,
},
] = useQueryParams(tabletQueryParams);
const [{tenantName: queryDatabase, clusterName: queryClusterName}] =
useQueryParams(tabletQueryParams);

const [autoRefreshInterval] = useAutoRefreshInterval();
const {currentData, isFetching, error} = tabletApi.useGetTabletQuery(
{id, database: queryDatabase ?? undefined, nodeId: queryNodeId ?? undefined},
{id, database: queryDatabase ?? undefined},
{pollingInterval: autoRefreshInterval},
);

Expand All @@ -96,24 +85,19 @@ export function Tablet() {
tablet.TenantId ? {tenantId: tablet.TenantId} : skipToken,
);

const nodeId = tablet.NodeId ?? queryNodeId ?? undefined;
const database = (tenantPath || queryDatabase) ?? undefined;

const nodeRole = useNodeRole(nodeId?.toString());

const tabletType = tablet.Type || eTypeSchema.parse(queryTabletType);
const tabletType = tablet.Type;

React.useEffect(() => {
dispatch(
setHeaderBreadcrumbs('tablet', {
nodeId,
nodeRole,
tenantName: queryDatabase ?? undefined,
tabletId: id,
tabletType,
}),
);
}, [dispatch, queryDatabase, id, nodeId, nodeRole, tabletType]);
}, [dispatch, queryDatabase, id, tabletType]);

const {Leader, Type} = tablet;
const metaItems: string[] = [];
Expand Down Expand Up @@ -246,17 +230,3 @@ function Channels({id, hiveId}: {id: string; hiveId: string}) {
</LoaderWrapper>
);
}

function useNodeRole(nodeId: string | undefined) {
const {currentData: node} = nodeApi.useGetNodeInfoQuery(nodeId ? {nodeId} : skipToken);

let nodeRole: 'Storage' | 'Compute' | undefined;

if (node) {
// Compute nodes have tenantName, storage nodes doesn't
const isStorage = !node?.Tenants?.[0];
nodeRole = isStorage ? 'Storage' : 'Compute';
}

return nodeRole;
}
2 changes: 0 additions & 2 deletions src/containers/Tablets/TabletsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ function getColumns({database}: {database?: string}) {
}

const tabletPath = getTabletPagePath(row.TabletId, {
nodeId: row.NodeId,
type: row.Type,
tenantName: database,
});

Expand Down
6 changes: 2 additions & 4 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,14 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
);
}
getTablet(
{id, database, nodeId}: {id: string; database?: string; nodeId?: string},
{id, database}: {id: string; database?: string},
{concurrentId, signal}: AxiosOptions = {},
) {
return this.get<TEvTabletStateResponse>(
this.getPath('/viewer/json/tabletinfo'),
{
enums: true,
database,
node_id: nodeId,
filter: `(TabletId=${id})`,
},
{
Expand All @@ -485,7 +484,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
);
}
getTabletHistory(
{id, database, nodeId}: {id: string; database?: string; nodeId?: string},
{id, database}: {id: string; database?: string},
{concurrentId, signal}: AxiosOptions = {},
) {
return this.get<UnmergedTEvTabletStateResponse>(
Expand All @@ -494,7 +493,6 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
enums: true,
merge: false,
database,
node_id: nodeId,
filter: `(TabletId=${id})`,
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/store/reducers/header/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface VDiskBreadcrumbsOptions extends PDiskBreadcrumbsOptions {
vDiskSlotId?: string | number;
}

export interface TabletBreadcrumbsOptions extends NodeBreadcrumbsOptions {
export interface TabletBreadcrumbsOptions extends TenantBreadcrumbsOptions {
tabletId?: string;
tabletType?: EType;
}
Expand Down
6 changes: 3 additions & 3 deletions src/store/reducers/tablet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export const tabletApi = api.injectEndpoints({
endpoints: (build) => ({
getTablet: build.query({
queryFn: async (
{id, database, nodeId}: {id: string; database?: string; nodeId?: string},
{id, database}: {id: string; database?: string; nodeId?: string},
{signal},
) => {
try {
const [tabletResponseData, historyResponseData, nodesList] = await Promise.all([
window.api.getTablet({id, database, nodeId}, {signal}),
window.api.getTabletHistory({id, database, nodeId}, {signal}),
window.api.getTablet({id, database}, {signal}),
window.api.getTabletHistory({id, database}, {signal}),
window.api.getNodesList({signal}),
]);
const nodeHostsMap = prepareNodeHostsMap(nodesList);
Expand Down
Loading