Skip to content

Commit

Permalink
Enhance logging and improve repository modals usability
Browse files Browse the repository at this point in the history
Updated logging statements to include additional context for better traceability. Enhanced repository modals with improved actions such as confirmation prompts, button customizations, and navigation to logs. Removed unused logger imports and refined UI components for consistency.
  • Loading branch information
SquirrelDevelopper committed Jan 2, 2025
1 parent 62b8bd8 commit c0bf166
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 30 deletions.
19 changes: 19 additions & 0 deletions client/src/components/Icons/CustomIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2688,3 +2688,22 @@ const QemuSvg = React.memo((props) => (
export const Qemu = (props: Partial<CustomIconComponentProps>) => (
<Icon component={QemuSvg} {...props} />
);

const SetActionSvg = React.memo((props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
viewBox="0 0 2048 2048"
{...props}
>
<path
fill="currentColor"
d="M1664 0v128H0V0h1664zm-649 512l-67 128H0V512h1015zM0 1024h747l-67 128H0v-128zm1512 0h568L1004 2048H747l304-640H691l535-1024h612l-326 640zm-559 896l807-768h-456l325-640h-325l-402 768h351l-304 640h4z"
/>
</svg>
));

export const SetAction = (props: Partial<CustomIconComponentProps>) => (
<Icon component={SetActionSvg} {...props} />
);
2 changes: 1 addition & 1 deletion client/src/pages/Admin/Logs/TaskLogsTerminalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const TaskLogsTerminalModal: React.FC<TaskLogsTerminalModalProps> = ({
setIsOpen(true);
}}
>
Show logs
Logs
</a>
<Modal
open={isOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const ContainerStacksSettings: React.FC = () => {
if (row.onError) {
return (
<Popover
overlayStyle={{ maxWidth: 450 }}
content={
<Space direction="vertical" size={'small'}>
<Typography.Text>
Expand Down
23 changes: 22 additions & 1 deletion client/src/pages/Admin/Settings/components/PlaybooksSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
UnorderedListOutlined,
} from '@ant-design/icons';
import { ProList } from '@ant-design/pro-components';
import { history } from '@umijs/max';
import {
Avatar,
Button,
Expand Down Expand Up @@ -327,14 +328,34 @@ const PlaybookSettings: React.FC = () => {
if (row.onError) {
return (
<Popover
overlayStyle={{ maxWidth: 450 }}
content={
<Space direction="vertical" size={'small'}>
<Space
direction="vertical"
size={'small'}
style={{ width: '100%' }}
>
<Typography.Text>
This repository is on error:
</Typography.Text>
<Typography.Text code style={{ fontSize: 13 }}>
{row.onErrorMessage}
</Typography.Text>
<Row justify="end">
<Col>
<Button
onClick={() =>
history.push({
pathname: '/admin/logs',
// @ts-expect-error lib missing type
search: `?moduleId=${row.uuid}`,
})
}
>
More logs
</Button>
</Col>
</Row>
</Space>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
putContainerStacksGitRepository,
syncToDatabaseContainerStacksGitRepository,
} from '@/services/rest/container-stacks-repositories';
import { DeleteOutlined, UnorderedListOutlined } from '@ant-design/icons';
import { ModalForm, ProForm } from '@ant-design/pro-components';
import { Avatar, Button, Dropdown, MenuProps, message } from 'antd';
import { history } from '@umijs/max';
import { Avatar, Button, Dropdown, MenuProps, message, Popconfirm } from 'antd';
import React from 'react';
import { API } from 'ssm-shared-lib';

Expand Down Expand Up @@ -114,17 +116,30 @@ const ContainerStacksGitRepositoryModal: React.FC<

const editionMode = props.selectedRecord
? [
<Button
key={'show-logs'}
icon={<UnorderedListOutlined />}
onClick={() =>
history.push({
pathname: '/admin/logs',
// @ts-expect-error lib missing type
search: `?moduleId=${props.selectedRecord.uuid}`,
})
}
>
Logs
</Button>,
<Dropdown.Button
key="dropdown"
type={'dashed'}
menu={{ items, onClick: onMenuClick }}
>
Actions
</Dropdown.Button>,
<Button
<Popconfirm
title="Are you sure to delete this repository?"
key="delete"
danger
onClick={async () => {
onConfirm={async () => {
if (props.selectedRecord && props.selectedRecord.uuid) {
await deleteContainerStacksGitRepository(
props.selectedRecord.uuid,
Expand All @@ -142,8 +157,10 @@ const ContainerStacksGitRepositoryModal: React.FC<
}
}}
>
Delete
</Button>,
<Button danger icon={<DeleteOutlined />}>
Delete
</Button>
</Popconfirm>,
]
: [];

Expand Down Expand Up @@ -190,6 +207,9 @@ const ContainerStacksGitRepositoryModal: React.FC<
}
}}
submitter={{
searchConfig: {
submitText: 'Save',
},
render: (_, defaultDoms) => {
return [...editionMode, ...defaultDoms];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
putPlaybooksGitRepository,
syncToDatabasePlaybooksGitRepository,
} from '@/services/rest/playbooks-repositories';
import { DeleteOutlined, UnorderedListOutlined } from '@ant-design/icons';
import { ModalForm, ProForm } from '@ant-design/pro-components';
import { Avatar, Button, Dropdown, MenuProps, message } from 'antd';
import { history } from '@umijs/max';
import { Avatar, Button, Dropdown, MenuProps, message, Popconfirm } from 'antd';
import React from 'react';
import { API } from 'ssm-shared-lib';

Expand Down Expand Up @@ -114,17 +116,30 @@ const PlaybooksGitRepositoryModal: React.FC<

const editionMode = props.selectedRecord
? [
<Button
key={'show-logs'}
icon={<UnorderedListOutlined />}
onClick={() =>
history.push({
pathname: '/admin/logs',
// @ts-expect-error lib missing type
search: `?moduleId=${props.selectedRecord.uuid}`,
})
}
>
Logs
</Button>,
<Dropdown.Button
key="dropdown"
type={'dashed'}
menu={{ items, onClick: onMenuClick }}
>
Actions
</Dropdown.Button>,
<Button
<Popconfirm
title="Are you sure to delete this repository?"
key="delete"
danger
onClick={async () => {
onConfirm={async () => {
if (props.selectedRecord && props.selectedRecord.uuid) {
await deletePlaybooksGitRepository(props.selectedRecord.uuid)
.then(() =>
Expand All @@ -140,8 +155,10 @@ const PlaybooksGitRepositoryModal: React.FC<
}
}}
>
Delete
</Button>,
<Button key="delete" danger icon={<DeleteOutlined />}>
Delete
</Button>
</Popconfirm>,
]
: [];

Expand Down Expand Up @@ -188,6 +205,9 @@ const PlaybooksGitRepositoryModal: React.FC<
}
}}
submitter={{
searchConfig: {
submitText: 'Save',
},
render: (_, defaultDoms) => {
return [...editionMode, ...defaultDoms];
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { SimpleIconsGit } from '@/components/Icons/CustomIcons';
import { SetAction, SimpleIconsGit } from '@/components/Icons/CustomIcons';
import DirectoryExclusionForm from '@/pages/Admin/Settings/components/subcomponents/forms/DirectoryExclusionForm';
import {
deletePlaybooksLocalRepository,
postPlaybooksLocalRepositories,
putPlaybooksLocalRepositories,
syncToDatabasePlaybooksLocalRepository,
} from '@/services/rest/playbooks-repositories';
import {
DeleteOutlined,
TableOutlined,
UnorderedListOutlined,
} from '@ant-design/icons';
import { ModalForm, ProForm, ProFormText } from '@ant-design/pro-components';
import { Avatar, Button, Dropdown, MenuProps, message } from 'antd';
import { history } from '@umijs/max';
import { Avatar, Button, Dropdown, MenuProps, message, Popconfirm } from 'antd';
import React, { FC, useState } from 'react';
import { API } from 'ssm-shared-lib';

Expand Down Expand Up @@ -53,19 +59,30 @@ const PlaybooksLocalRepositoryModal: FC<LocalRepositoryModalProps> = (
};
const editionMode = props.selectedRecord
? [
<Button
key={'show-logs'}
icon={<UnorderedListOutlined />}
onClick={() =>
history.push({
pathname: '/admin/logs',
// @ts-expect-error lib missing type
search: `?moduleId=${props.selectedRecord.uuid}`,
})
}
>
Logs
</Button>,
<Dropdown.Button
key="dropdown"
type={'dashed'}
menu={{ items, onClick: onMenuClick }}
>
Actions
</Dropdown.Button>,
<Button
<Popconfirm
key="delete"
danger
disabled={props.selectedRecord?.default === true}
loading={loading}
onClick={async () => {
title="Are you sure to delete this repository?"
onConfirm={async () => {
setLoading(true);
if (props.selectedRecord && props.selectedRecord.uuid) {
await deletePlaybooksLocalRepository(props.selectedRecord.uuid)
Expand All @@ -83,8 +100,15 @@ const PlaybooksLocalRepositoryModal: FC<LocalRepositoryModalProps> = (
setLoading(false);
}}
>
Delete
</Button>,
<Button
icon={<DeleteOutlined />}
danger
disabled={props.selectedRecord?.default === true}
loading={loading}
>
Delete
</Button>
</Popconfirm>,
]
: [];
return (
Expand Down Expand Up @@ -135,6 +159,9 @@ const PlaybooksLocalRepositoryModal: FC<LocalRepositoryModalProps> = (
}
}}
submitter={{
searchConfig: {
submitText: 'Save',
},
render: (_, defaultDoms) => {
return [...editionMode, ...defaultDoms];
},
Expand Down
2 changes: 0 additions & 2 deletions server/src/helpers/git/credential.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GitProcess } from 'dugite';
import { trim } from 'lodash';
import { SsmGit } from 'ssm-shared-lib';
import logger from '../../logger';
import { getRemoteUrl } from './inspect';

// TODO: support folderLocation as rawUrl like `/Users/linonetwo/Desktop/repo/playbooks-repository-sync-js/test/mockUpstreamRepo/credential` for test, or gitlab url.
Expand Down Expand Up @@ -107,7 +106,6 @@ export async function credentialOn(
throw new Error(`Unknown service type ${serviceType}`);
}
}
logger.error(gitUrlWithCredential);
await GitProcess.exec(['remote', 'add', remoteName, gitUrlWithCredential], directory);
await GitProcess.exec(['remote', 'set-url', remoteName, gitUrlWithCredential], directory);
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const httpLoggerOptions = {

// Define a custom error message
customErrorMessage: function (req, res, err) {
return `Request errored with status code: ${res.statusCode}`;
return `Request errored with status code: ${res.statusCode} - ${req.method} - ${req.url} - ${err.message}`;
},
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/middlewares/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const errorHandler = (err: Error, req: Request, res: Response, next: Next
if (err instanceof ApiError) {
ApiError.handle(err, res, req);
} else {
logger.error(err);
logger.error(`${err.message} - ${req.originalUrl} - ${req.method} - ${req.ip}`);
if (err.message === 'Unauthorized') {
ApiError.handle(new AuthFailureError('Unauthorized'), res, req);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class AbstractActionComponent extends EventManager {
throw new Error(`Automation with uuid ${this.automationUuid} not found`);
}
await AutomationRepo.setLastExecutionStatus(automation, 'failed');
this.childLogger.error('Automation failed');
this.childLogger.error(`Automation failed - error: ${optionalMessage || 'Unknown reason'}`);
this.emit(Events.AUTOMATION_FAILED, {
message: optionalMessage || `The automation "${this.moduleName}" failed`,
severity: 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class DockerVolumeActionComponent extends AbstractActionComponent {
this.childLogger.info(`Docker Volume Action - executeAction - for volume: ${volumeUuid}`);
const volume = await ContainerVolumeRepo.findByUuid(volumeUuid);
if (!volume) {
this.childLogger.error(`Volume not found for ${volumeUuid}`);
this.childLogger.error(
`Volume not found. (Volume uuid: ${volumeUuid}, Action: ${this.dockerVolumeAction})`,
);
success = false;
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class GitPlaybooksRepositoryComponent
try {
void Shell.FileSystemManager.createDirectory(this.directory, DIRECTORY_ROOT);
} catch (error: any) {
logger.warn(error);
this.childLogger.warn(error);
}
await clone({
...this.options,
Expand Down

0 comments on commit c0bf166

Please sign in to comment.