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 1 commit
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
35 changes: 4 additions & 31 deletions src/containers/Tablet/Tablet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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';
Expand Down Expand Up @@ -62,7 +61,6 @@ const tabletTabSchema = z.nativeEnum(TABLET_TABS_IDS).catch(TABLET_TABS_IDS.hist
const eTypeSchema = z.nativeEnum(EType).or(z.undefined()).catch(undefined);

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

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

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

Choose a reason for hiding this comment

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

IMHO, tablet type should't be passed in query as well.

In the scenario, where we navigate to specific tablet by changing tablet id, we will need to change tablet type together with tablet id, otherwise it will be incorrect.

I think it won't hurt much, if correct tablet type appear in breadcrumbs after data is loaded. Until it happens, there will be a placeholder icon with T type [T].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've thought about this, but finally decided to leave tablet type in query string, cause as for me it doesn't hurt much: even if it will be incorrect, it will be replaced when tablet info is loaded. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I just don't like passing much in query strings, we already have very long links and they become even longer with every update. So for me, if there is no much difference, it's better not to pass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, thats hurting truth! I agree with you! Lets get rid of query params if possible!

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 +88,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);

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 +233,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;
}
1 change: 0 additions & 1 deletion src/containers/Tablets/TabletsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +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