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:db add kafka monitor #4359

Merged
merged 2 commits into from
Nov 29, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 33 additions & 12 deletions frontend/providers/dbprovider/src/pages/api/getSecretByName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,49 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
kubeconfig: await authSession(req)
});

const base = {
passwordKey: 'password',
usernameKey: 'username',
portKey: 'port',
hostKey: 'host'
};

const data = await (async () => {
const dbTypeMap = {
[DBTypeEnum.postgresql]: {
passwordKey: 'password',
...base,
connectKey: 'postgresql'
},
[DBTypeEnum.mongodb]: {
passwordKey: 'password',
...base,
connectKey: 'mongodb'
},
[DBTypeEnum.mysql]: {
passwordKey: 'password',
...base,
connectKey: 'mysql'
},
[DBTypeEnum.redis]: {
passwordKey: 'password',
...base,
connectKey: 'redis'
},
[DBTypeEnum.kafka]: {
passwordKey: 'password',
connectKey: 'kafka'
...base,
connectKey: 'kafka',
passwordKey: 'clientPassword',
usernameKey: 'clientUser',
portKey: 'endpoint',
hostKey: 'superusers'
},
[DBTypeEnum.qdrant]: {
passwordKey: 'password',
...base,
connectKey: 'qdrant'
},
[DBTypeEnum.nebula]: {
passwordKey: 'password',
...base,
connectKey: 'nebula'
},
[DBTypeEnum.weaviate]: {
passwordKey: 'password',
...base,
connectKey: 'weaviate'
}
};
Expand All @@ -69,13 +80,23 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
return Promise.reject('Get secret errpr');
}

const username = Buffer.from(secret.body.data['username'], 'base64').toString('utf-8');
const username = Buffer.from(
secret.body.data[dbTypeMap[dbType].usernameKey],
'base64'
).toString('utf-8');

const password = Buffer.from(
secret.body.data[dbTypeMap[dbType].passwordKey],
'base64'
).toString('utf-8');
const host = Buffer.from(secret.body.data['host'], 'base64').toString('utf-8');
const port = Buffer.from(secret.body.data['port'], 'base64').toString('utf-8');

const host = Buffer.from(secret.body.data[dbTypeMap[dbType].hostKey], 'base64').toString(
'utf-8'
);

const port = Buffer.from(secret.body.data[dbTypeMap[dbType].portKey], 'base64').toString(
'utf-8'
);

return {
username,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
data: body
});
} catch (err: any) {
console.log(err?.body, 'db get service name err');
console.log(err?.body, 'api:getServiceByName');
if (err?.body?.code === 404) {
return jsonRes(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
data: await GetStatefulSetByName({ name: temp, req })
});
} catch (err: any) {
console.log(err?.body, 'db get service name err');
console.log(err?.body, 'api:getStatefulSetByName');
jsonRes(res, {
code: 500,
error: err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
});

const { dbName, dbType, queryKey, start, end, step } = req.query;
console.log(dbName, dbType, queryKey);

const endTime = Date.now(); // 当前时间的时间戳
const startTime = endTime - 60 * 60 * 1000; // 前向推进1个小时的时间戳
Expand All @@ -80,6 +79,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
end: endTime / 1000,
step: '1m'
};
console.log(params, 'getMonitorData');

const result = await handleAxiosStream(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const AppDetail = ({
const { t } = useTranslation();

const { listNav } = useMemo(() => {
const PublicNetMigration = ['postgresql', 'apecloud-mysql'].includes(dbType);
const PublicNetMigration = ['postgresql', 'apecloud-mysql', 'mongodb'].includes(dbType);
const MigrateSupported = ['postgresql', 'mongodb', 'apecloud-mysql'].includes(dbType);
const BackupSupported = ['postgresql', 'mongodb', 'apecloud-mysql', 'redis'].includes(dbType);

Expand Down
27 changes: 0 additions & 27 deletions frontend/providers/template/delRoleBinding.ts

This file was deleted.

3 changes: 2 additions & 1 deletion service/license/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"Cluster Pay Success": "Buy {{clusterType}} Success",
"common": {
"input": {
"Repeat Value": "Repeat Value"
"Repeat Value": "Repeat Value",
"No Elements to Delete": "No Elements to Delete"
}
},
"Enter Save": "Enter Save"
Expand Down
3 changes: 2 additions & 1 deletion service/license/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"Cluster Pay Success": "购买 {{clusterType}} 成功",
"common": {
"input": {
"Repeat Value": "出入重复"
"Repeat Value": "出入重复",
"No Elements to Delete": "没有元素可以删除"
}
},
"Enter Save": "回车保存"
Expand Down
48 changes: 34 additions & 14 deletions service/license/src/components/Textarea/TagTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,37 @@ const TagTextarea = ({ defaultValues, onUpdate, inputStyle, ...props }: Props) =
const [tags, setTags] = useState<string[]>(defaultValues);

const onUpdateValue = useCallback(
(value?: string) => {
(value?: string, type: 'create' | 'delete' = 'create') => {
setFocus(false);
if (!value || !InputRef.current?.value) {
return;
}
if (tags.includes(value)) {
return toast({
status: 'error',
title: t('common.input.Repeat Value'),
position: 'top',
duration: 2000
});
if (type === 'create') {
if (!value || !InputRef.current?.value) {
return;
}
if (tags.includes(value)) {
return toast({
status: 'info',
title: t('common.input.Repeat Value'),
position: 'top',
duration: 2000
});
}
setTags([...tags, value]);
onUpdate([...tags, value]);
InputRef.current.value = '';
} else {
if (tags.length === 0) {
return toast({
status: 'info',
title: t('common.input.No Elements to Delete'),
position: 'top',
duration: 2000
});
}
// Delete the last element
tags.pop();
setTags(tags);
onUpdate(tags);
}
setTags([...tags, value]);
onUpdate([...tags, value]);
InputRef.current.value = '';
},
[onUpdate, t, tags, toast]
);
Expand All @@ -67,6 +82,7 @@ const TagTextarea = ({ defaultValues, onUpdate, inputStyle, ...props }: Props) =
setFocus(true);
}
}}
overflowY={'auto'}
>
<Flex alignItems={'center'} gap={2} flexWrap={'wrap'}>
{tags.map((tag, i) => (
Expand Down Expand Up @@ -108,6 +124,10 @@ const TagTextarea = ({ defaultValues, onUpdate, inputStyle, ...props }: Props) =
e.preventDefault();
onUpdateValue(InputRef.current?.value);
}
if (e.keyCode === 8 && InputRef.current?.value === '') {
e.preventDefault();
onUpdateValue(InputRef.current?.value, 'delete');
}
}}
{...inputStyle}
/>
Expand Down
21 changes: 13 additions & 8 deletions service/license/src/pages/cluster/components/CommandForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ import { useForm } from 'react-hook-form';
type CommandFormProps = {
basePath: string;
cloudVersion: string;
enterprise?: boolean;
};

export default function CommandForm({ basePath, cloudVersion }: CommandFormProps) {
export default function CommandForm({
basePath,
cloudVersion,
enterprise = false
}: CommandFormProps) {
const { isOpen, onOpen, onClose } = useDisclosure();
const [displayCommand, setDisplayCommand] = useState('');
const [copyCommand, setCopyCommand] = useState('');
Expand All @@ -42,7 +47,7 @@ export default function CommandForm({ basePath, cloudVersion }: CommandFormProps
basePath,
cloudVersion ? ` --cloud-version=${cloudVersion} ` : '',
' --image-registry=registry.cn-shanghai.aliyuncs.com ',
' --proxy-prefix=https://gh-proxy.com ',
enterprise ? '' : ' --proxy-prefix=https://mirror.ghproxy.com ',
masterIps ? ` --master-ips=${masterIps} ` : '',
nodeIps ? ` --node-ips=${nodeIps} ` : '',
data?.podSubnet ? ` --pod-cidr=${data?.podSubnet} ` : '',
Expand Down Expand Up @@ -148,7 +153,7 @@ export default function CommandForm({ basePath, cloudVersion }: CommandFormProps
fontWeight: 400
}}
w={'320px'}
h="50px"
h="80px"
defaultValues={getValues('masterIP') || []}
onUpdate={(e) => {
setValue('masterIP', e);
Expand All @@ -169,7 +174,7 @@ export default function CommandForm({ basePath, cloudVersion }: CommandFormProps
fontSize: '12px',
fontWeight: 400
}}
h="50px"
h="80px"
w={'320px'}
defaultValues={getValues('nodeIP') || []}
onUpdate={(e) => {
Expand All @@ -189,7 +194,7 @@ export default function CommandForm({ basePath, cloudVersion }: CommandFormProps
<Flex alignItems={'center'} justifyContent={'start'} gap={'40px'}>
<Label>ssh 密码</Label>
<Input
placeholder="不填则免密登录"
placeholder="默认免密登录"
{...register('sshPassword', {
required: true
})}
Expand All @@ -212,7 +217,7 @@ export default function CommandForm({ basePath, cloudVersion }: CommandFormProps
/>
</Flex>
<Flex alignItems={'center'} justifyContent={'start'} gap={'40px'}>
<Label>Sealos Cloud 端口</Label>
<Label>Cloud 端口</Label>
<Input
{...register('cloudPort', {
required: true
Expand All @@ -223,7 +228,7 @@ export default function CommandForm({ basePath, cloudVersion }: CommandFormProps
<Flex alignItems={'center'} justifyContent={'start'} gap={'40px'}>
<Label>证书路径</Label>
<Input
placeholder={'不填则使用 Sealos 提供的自签证书'}
placeholder={'默认使用 Sealos 提供的自签证书'}
{...register('certPath', {
required: false
})}
Expand All @@ -233,7 +238,7 @@ export default function CommandForm({ basePath, cloudVersion }: CommandFormProps
<Flex alignItems={'center'} justifyContent={'start'} gap={'40px'}>
<Label>证书 Key 路径</Label>
<Input
placeholder={'不填则使用 Sealos 提供的自签证书'}
placeholder={'默认使用 Sealos 提供的自签证书'}
{...register('certKeyPath', {
required: false
})}
Expand Down
3 changes: 2 additions & 1 deletion service/license/src/pages/cluster/components/Tutorial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export default function Tutorial({
<CommandForm
basePath={`tar xzvf ${fileNameParams} && cd sealos-cloud && bash install.sh `}
cloudVersion={ossVersion}
enterprise={true}
/>
</AccordionPanel>
</AccordionItem>
Expand All @@ -169,7 +170,7 @@ export default function Tutorial({
</AccordionButton>
<AccordionPanel py="20px" pl="40px" gap={'12px'}>
<CommandForm
basePath={`curl -sfL https://gh-proxy.com/https://raw.githubusercontent.com/labring/sealos/main/scripts/cloud/install.sh -o /tmp/install.sh && bash scripts/load-images.sh && /tmp/install.sh --zh `}
basePath={`curl -sfL https://mirror.ghproxy.com/https://raw.githubusercontent.com/labring/sealos/main/scripts/cloud/install.sh -o /tmp/install.sh && bash scripts/load-images.sh && bash /tmp/install.sh --zh `}
cloudVersion={ossVersion}
/>
<Center
Expand Down