Skip to content
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

feat: add database hyperlink to logging service #2021

Merged
merged 3 commits into from
Mar 18, 2025
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
17 changes: 17 additions & 0 deletions src/components/LogsButton/LogsButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {FileText} from '@gravity-ui/icons';
import type {ButtonSize} from '@gravity-ui/uikit';
import {Button, Icon} from '@gravity-ui/uikit';

interface LogsButtonProps {
className?: string;
href: string;
size?: ButtonSize;
}

export function LogsButton({href, className, size = 'xs'}: LogsButtonProps) {
return (
<Button href={href} target="_blank" className={className} size={size} title="Database logs">
<Icon data={FileText} />
</Button>
);
}
22 changes: 15 additions & 7 deletions src/components/TenantNameWrapper/TenantNameWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DefinitionList, PopoverBehavior} from '@gravity-ui/uikit';
import {DefinitionList, Flex, PopoverBehavior} from '@gravity-ui/uikit';

import {getTenantPath} from '../../containers/Tenant/TenantPages';
import type {PreparedTenant} from '../../store/reducers/tenants/types';
Expand Down Expand Up @@ -39,19 +39,27 @@ export function TenantNameWrapper({tenant, additionalTenantsProps}: TenantNameWr
const isExternalLink = Boolean(backend);

const monitoringLink = additionalTenantsProps?.getMonitoringLink?.(tenant.Name, tenant.Type);
const logsLink = additionalTenantsProps?.getLogsLink?.(tenant.Name);

return (
<CellWithPopover
disabled={!isUserAllowedToMakeChanges || !monitoringLink}
disabled={!isUserAllowedToMakeChanges || (!monitoringLink && !logsLink)}
delayClosing={200}
content={
monitoringLink ? (
monitoringLink || logsLink ? (
<DefinitionList responsive>
<DefinitionList.Item name={i18n('field_links')}>
<LinkWithIcon
title={i18n('field_monitoring-link')}
url={monitoringLink}
/>
<Flex gap={2} wrap="wrap">
{monitoringLink && (
<LinkWithIcon
title={i18n('field_monitoring-link')}
url={monitoringLink}
/>
)}
{logsLink && (
<LinkWithIcon title={i18n('field_logs-link')} url={logsLink} />
)}
</Flex>
</DefinitionList.Item>
</DefinitionList>
) : null
Expand Down
1 change: 1 addition & 0 deletions src/components/TenantNameWrapper/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"field_links": "Links",
"field_monitoring-link": "Monitoring",
"field_logs-link": "Logs",
"context_unknown": "unknown database"
}
10 changes: 9 additions & 1 deletion src/containers/AppWithClusters/AppWithClusters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import React from 'react';
import type {Store} from '@reduxjs/toolkit';
import type {History} from 'history';

import type {GetMonitoringClusterLink, GetMonitoringLink} from '../../utils/monitoring';
import type {
GetLogsLink,
GetMonitoringClusterLink,
GetMonitoringLink,
} from '../../utils/monitoring';
import {
getMonitoringClusterLink as getMonitoringClusterLinkDefault,
getMonitoringLink as getMonitoringLinkDefault,
Expand All @@ -17,6 +21,7 @@ import {ExtendedTenant} from './ExtendedTenant/ExtendedTenant';
export interface AppWithClustersProps {
store: Store;
history: History;
getLogsLink?: GetLogsLink;
getMonitoringLink?: GetMonitoringLink;
getMonitoringClusterLink?: GetMonitoringClusterLink;
userSettings?: YDBEmbeddedUISettings;
Expand All @@ -26,6 +31,7 @@ export interface AppWithClustersProps {
export function AppWithClusters({
store,
history,
getLogsLink,
getMonitoringLink = getMonitoringLinkDefault,
getMonitoringClusterLink = getMonitoringClusterLinkDefault,
userSettings,
Expand All @@ -38,6 +44,7 @@ export function AppWithClusters({
return (
<ExtendedCluster
component={component}
getLogsLink={getLogsLink}
getMonitoringLink={getMonitoringLink}
getMonitoringClusterLink={getMonitoringClusterLink}
/>
Expand All @@ -49,6 +56,7 @@ export function AppWithClusters({
return (
<ExtendedTenant
component={component}
getLogsLink={getLogsLink}
getMonitoringLink={getMonitoringLink}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {cn} from '../../../utils/cn';
import {USE_CLUSTER_BALANCER_AS_BACKEND_KEY} from '../../../utils/constants';
import {useSetting} from '../../../utils/hooks';
import {useAdditionalNodesProps} from '../../../utils/hooks/useAdditionalNodesProps';
import type {GetMonitoringClusterLink, GetMonitoringLink} from '../../../utils/monitoring';
import type {
GetLogsLink,
GetMonitoringClusterLink,
GetMonitoringLink,
} from '../../../utils/monitoring';
import {getCleanBalancerValue, removeViewerPathname} from '../../../utils/parseBalancer';
import {getBackendFromNodeHost, getBackendFromRawNodeData} from '../../../utils/prepareBackend';
import type {Cluster} from '../../Cluster/Cluster';
Expand Down Expand Up @@ -63,6 +67,7 @@ const getAdditionalTenantsProps = (
balancer: string | undefined,
useClusterBalancerAsBackend: boolean | undefined,
getMonitoringLink?: GetMonitoringLink,
getLogsLink?: GetLogsLink,
) => {
const additionalTenantsProps: AdditionalTenantsProps = {};

Expand Down Expand Up @@ -99,18 +104,33 @@ const getAdditionalTenantsProps = (
};
}

if (clusterName && getLogsLink) {
additionalTenantsProps.getLogsLink = (dbName?: string) => {
if (dbName) {
return getLogsLink({
dbName,
clusterName,
});
}

return null;
};
}

return additionalTenantsProps;
};

interface ExtendedClusterProps {
component: typeof Cluster;
getMonitoringLink?: GetMonitoringLink;
getMonitoringClusterLink?: GetMonitoringClusterLink;
getLogsLink?: GetLogsLink;
}
export function ExtendedCluster({
component: ClusterComponent,
getMonitoringLink,
getMonitoringClusterLink,
getLogsLink,
}: ExtendedClusterProps) {
const additionalNodesProps = useAdditionalNodesProps();
const {name, balancer, monitoring} = useClusterBaseInfo();
Expand All @@ -132,6 +152,7 @@ export function ExtendedCluster({
balancer,
useClusterBalancerAsBackend,
getMonitoringLink,
getLogsLink,
)}
additionalNodesProps={additionalNodesProps}
/>
Expand Down
16 changes: 14 additions & 2 deletions src/containers/AppWithClusters/ExtendedTenant/ExtendedTenant.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import {useClusterBaseInfo} from '../../../store/reducers/cluster/cluster';
import type {ETenantType} from '../../../types/api/tenant';
import {useAdditionalNodesProps} from '../../../utils/hooks/useAdditionalNodesProps';
import type {GetMonitoringLink} from '../../../utils/monitoring';
import type {GetLogsLink, GetMonitoringLink} from '../../../utils/monitoring';
import type {Tenant} from '../../Tenant/Tenant';

export interface ExtendedTenantProps {
component: typeof Tenant;
getMonitoringLink?: GetMonitoringLink;
getLogsLink?: GetLogsLink;
}

export function ExtendedTenant({
component: TenantComponent,
getMonitoringLink,
getLogsLink,
}: ExtendedTenantProps) {
const {monitoring} = useClusterBaseInfo();
const {monitoring, name: clusterName} = useClusterBaseInfo();
const additionalNodesProps = useAdditionalNodesProps();

const additionalTenantProps = {
Expand All @@ -26,6 +28,16 @@ export function ExtendedTenant({
});
}

return null;
},
getLogsLink: (dbName?: string) => {
if (clusterName && dbName && getLogsLink) {
return getLogsLink({
dbName,
clusterName,
});
}

return null;
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
}

&__top {
display: flex;
align-items: center;
gap: 4px;

margin-bottom: 10px;

line-height: 24px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Loader} from '@gravity-ui/uikit';
import {Flex, Loader} from '@gravity-ui/uikit';

import {EntityStatus} from '../../../../components/EntityStatus/EntityStatus';
import {LogsButton} from '../../../../components/LogsButton/LogsButton';
import {MonitoringButton} from '../../../../components/MonitoringButton/MonitoringButton';
import {overviewApi} from '../../../../store/reducers/overview/overview';
import {TENANT_METRICS_TABS_IDS} from '../../../../store/reducers/tenant/constants';
Expand Down Expand Up @@ -150,15 +151,19 @@ export function TenantOverview({
}

const monitoringLink = additionalTenantProps?.getMonitoringLink?.(Name, Type);
const logsLink = additionalTenantProps?.getLogsLink?.(Name);

return (
<div className={b()}>
<div className={b('info')}>
<div className={b('top-label')}>{tenantType}</div>
<div className={b('top')}>
<Flex alignItems="center" gap="1" className={b('top')}>
{renderName()}
{monitoringLink && <MonitoringButton href={monitoringLink} />}
</div>
<Flex gap="2">
{monitoringLink && <MonitoringButton href={monitoringLink} />}
{logsLink && <LogsButton href={logsLink} />}
</Flex>
</Flex>
<MetricsCards
poolsCpuStats={poolsStats}
memoryStats={memoryStats}
Expand Down
1 change: 1 addition & 0 deletions src/types/additionalProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface AdditionalClusterProps {
export interface AdditionalTenantsProps {
prepareTenantBackend?: (backend: string | NodeAddress | undefined) => string | undefined;
getMonitoringLink?: (name?: string, type?: ETenantType) => string | null;
getLogsLink?: (name?: string) => string | null;
}

export type NodeAddress = Pick<TSystemStateInfo, 'Host' | 'Endpoints' | 'NodeId'>;
Expand Down
7 changes: 7 additions & 0 deletions src/utils/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,10 @@ export function parseMonitoringData(monitoring: string): ParsedMonitoringData |

return undefined;
}

interface GetLogsLinkProps {
dbName: string;
clusterName: string;
}

export type GetLogsLink = (props: GetLogsLinkProps) => string;
Loading