Skip to content

Commit

Permalink
Merge pull request #9143 from tinyspeck/sarabee-vtctlds
Browse files Browse the repository at this point in the history
[vtadmin-web] Add vtctlds view
  • Loading branch information
doeg authored Nov 4, 2021
2 parents 20d9777 + 5c25f61 commit 133acbe
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/local/vtadmin/discovery.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"vtctlds": [
{
"host": {
"fqdn": "localhost:15000",
"hostname": "localhost:15999"
}
}
Expand Down
11 changes: 11 additions & 0 deletions web/vtadmin/src/api/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ export const fetchGates = async () =>
},
});

export const fetchVtctlds = async () =>
vtfetchEntities({
endpoint: '/api/vtctlds',
extract: (res) => res.result.vtctlds,
transform: (e) => {
const err = pb.Vtctld.verify(e);
if (err) throw Error(err);
return pb.Vtctld.create(e);
},
});

export interface FetchKeyspaceParams {
clusterID: string;
name: string;
Expand Down
5 changes: 5 additions & 0 deletions web/vtadmin/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { Keyspace } from './routes/keyspace/Keyspace';
import { Tablet } from './routes/tablet/Tablet';
import { Backups } from './routes/Backups';
import { Shard } from './routes/shard/Shard';
import { Vtctlds } from './routes/Vtctlds';

export const App = () => {
return (
Expand Down Expand Up @@ -85,6 +86,10 @@ export const App = () => {
<Tablet />
</Route>

<Route path="/vtctlds">
<Vtctlds />
</Route>

<Route path="/vtexplain">
<VTExplain />
</Route>
Expand Down
1 change: 1 addition & 0 deletions web/vtadmin/src/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export enum Icons {
keyR = 'keyR',
keyS = 'keyS',
keyT = 'keyT',
keyV = 'keyV',
keyboard = 'keyboard',
link = 'link',
pageFirst = 'pageFirst',
Expand Down
6 changes: 5 additions & 1 deletion web/vtadmin/src/components/NavRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Link, NavLink } from 'react-router-dom';

import style from './NavRail.module.scss';
import logo from '../img/vitess-icon-color.svg';
import { useClusters, useGates, useKeyspaces, useSchemas, useTablets, useWorkflows } from '../hooks/api';
import { useClusters, useGates, useKeyspaces, useSchemas, useTablets, useVtctlds, useWorkflows } from '../hooks/api';
import { Icon, Icons } from './Icon';
import { getTableDefinitions } from '../util/tableDefinitions';

Expand All @@ -28,6 +28,7 @@ export const NavRail = () => {
const { data: gates = [] } = useGates();
const { data: schemas = [] } = useSchemas();
const { data: tablets = [] } = useTablets();
const { data: vtctlds = [] } = useVtctlds();
const { data: workflows = [] } = useWorkflows();

const tds = React.useMemo(() => getTableDefinitions(schemas), [schemas]);
Expand Down Expand Up @@ -65,6 +66,9 @@ export const NavRail = () => {
<li>
<NavRailLink icon={Icons.keyT} text="Tablets" to="/tablets" count={tablets.length} />
</li>
<li>
<NavRailLink icon={Icons.keyV} text="vtctlds" to="/vtctlds" count={vtctlds.length} />
</li>
</ul>

<ul className={style.navList}>
Expand Down
90 changes: 90 additions & 0 deletions web/vtadmin/src/components/routes/Vtctlds.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Copyright 2021 The Vitess Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { orderBy } from 'lodash';
import { useMemo } from 'react';
import { useVtctlds } from '../../hooks/api';
import { useSyncedURLParam } from '../../hooks/useSyncedURLParam';
import { filterNouns } from '../../util/filterNouns';
import { DataCell } from '../dataTable/DataCell';
import { DataFilter } from '../dataTable/DataFilter';
import { DataTable } from '../dataTable/DataTable';
import { ContentContainer } from '../layout/ContentContainer';
import { WorkspaceHeader } from '../layout/WorkspaceHeader';
import { WorkspaceTitle } from '../layout/WorkspaceTitle';

export const Vtctlds = () => {
const { data: vtctlds = [], ...q } = useVtctlds();
const { value: filter, updateValue: updateFilter } = useSyncedURLParam('filter');

const data = useMemo(() => {
const mapped = vtctlds.map((v) => ({
cluster: v.cluster?.name,
clusterID: v.cluster?.id,
hostname: v.hostname,
fqdn: v.FQDN,
}));

const filtered = filterNouns(filter, mapped);

return orderBy(filtered, ['cluster', 'hostname']);
}, [filter, vtctlds]);

const renderRows = (rows: typeof data) => {
return rows.map((row) => {
return (
<tr key={row.hostname}>
<DataCell>
<div className="font-weight-bold">
{row.fqdn ? (
<a href={`//${row.fqdn}`} rel="noopener noreferrer" target="_blank">
{row.hostname}
</a>
) : (
row.hostname
)}
</div>
</DataCell>
<DataCell>
{row.cluster}
<div className="font-size-small text-color-secondary">{row.clusterID}</div>
</DataCell>
</tr>
);
});
};

return (
<div>
<WorkspaceHeader>
<WorkspaceTitle>vtctlds</WorkspaceTitle>
</WorkspaceHeader>

<ContentContainer>
<DataFilter
autoFocus
onChange={(e) => updateFilter(e.target.value)}
onClear={() => updateFilter('')}
placeholder="Filter vtctlds"
value={filter || ''}
/>
<DataTable columns={['Hostname', 'Cluster']} data={data} renderRows={renderRows} />

{/* TODO skeleton placeholder */}
{!!q.isLoading && <div className="text-align-center">Loading</div>}
</ContentContainer>
</div>
);
};
7 changes: 7 additions & 0 deletions web/vtadmin/src/hooks/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
fetchTablets,
fetchVSchema,
FetchVSchemaParams,
fetchVtctlds,
fetchVTExplain,
fetchWorkflow,
fetchWorkflows,
Expand Down Expand Up @@ -92,6 +93,12 @@ export const useSchemas = (options?: UseQueryOptions<pb.Schema[], Error> | undef
export const useTablets = (options?: UseQueryOptions<pb.Tablet[], Error> | undefined) =>
useQuery(['tablets'], fetchTablets, options);

/**
* useVtctlds is a query hook that fetches all vtctlds across every cluster.
*/
export const useVtctlds = (options?: UseQueryOptions<pb.Vtctld[], Error> | undefined) =>
useQuery(['vtctlds'], fetchVtctlds, options);

/**
* useTablet is a query hook that fetches a single tablet by alias.
*/
Expand Down
1 change: 1 addition & 0 deletions web/vtadmin/src/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export { ReactComponent as KeyK } from './keyK.svg';
export { ReactComponent as KeyR } from './keyR.svg';
export { ReactComponent as KeyS } from './keyS.svg';
export { ReactComponent as KeyT } from './keyT.svg';
export { ReactComponent as KeyV } from './keyV.svg';
export { ReactComponent as Keyboard } from './keyboard.svg';
export { ReactComponent as Link } from './link.svg';
export { ReactComponent as PageFirst } from './pageFirst.svg';
Expand Down
4 changes: 4 additions & 0 deletions web/vtadmin/src/icons/keyV.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions web/vtadmin/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ table tbody td[rowSpan] {
text-align: right;
}

.text-align-center {
text-align: center;
}

.text-color-secondary {
color: var(--textColorSecondary);
}
Expand Down

0 comments on commit 133acbe

Please sign in to comment.