From 3827bde7d2e1cb10ca99002bc955997939fba9b3 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Mon, 15 Jul 2024 10:33:42 +0800 Subject: [PATCH 01/14] Revert "feat: for github" This reverts commit a5d83b149dd70fe1ff4435227de4ff18f4e6bcc7. --- apps/server/src/mysql/some.sql | 19 +++++++++++++++++++ apps/web/src/const/index.ts | 2 +- apps/web/src/main.tsx | 2 +- .../home/components/chartModal/index.tsx | 14 ++------------ 4 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 apps/server/src/mysql/some.sql diff --git a/apps/server/src/mysql/some.sql b/apps/server/src/mysql/some.sql new file mode 100644 index 0000000..4299948 --- /dev/null +++ b/apps/server/src/mysql/some.sql @@ -0,0 +1,19 @@ +-- 版本表添加 note 字段用于存储调度配置时的备注 +ALTER TABLE version add COLUMN note varchar(256) NULL COMMENT '备注'; + + + +-- 任务表添加 previewImg 字段用于存储检测结果的首屏图片预览 +ALTER TABLE task add COLUMN previewImg LONGTEXT NULL COMMENT '结果的首屏图片预览'; + + + +-- 产品表添加 emails 字段用于接收数据周报邮件 +ALTER TABLE project add COLUMN emails varchar(256) NULL COMMENT '子产品相关人员邮箱,用于接收数据周报邮件'; + + + + +-- 版本表添加 sort 字段用于版本排序 +ALTER TABLE version add COLUMN sort int NULL DEFAULT 1 COMMENT '排序序号'; + diff --git a/apps/web/src/const/index.ts b/apps/web/src/const/index.ts index 0cf4862..ba2ac8d 100644 --- a/apps/web/src/const/index.ts +++ b/apps/web/src/const/index.ts @@ -43,7 +43,7 @@ export const IS_USEFUL_TEXT = [ */ const scoreColor = { orangeMin: 50, - greenMin: 90, + greenMin: 80, }; export const getScoreColor = (score: number) => { diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsx index 6616c40..30d17d4 100644 --- a/apps/web/src/main.tsx +++ b/apps/web/src/main.tsx @@ -10,7 +10,7 @@ import Routers from './routers'; import './main.less'; const yiceRole = localStorage.getItem('yice-role'); -!yiceRole && localStorage.setItem('yice-role', YICE_ROLE.ADMIN); +!yiceRole && localStorage.setItem('yice-role', YICE_ROLE.USER); ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( diff --git a/apps/web/src/views/home/components/chartModal/index.tsx b/apps/web/src/views/home/components/chartModal/index.tsx index 0f0aefb..183b746 100644 --- a/apps/web/src/views/home/components/chartModal/index.tsx +++ b/apps/web/src/views/home/components/chartModal/index.tsx @@ -189,18 +189,8 @@ export default function ChartModal(props: IProps) { const tabItems = [ { label: '性能评分趋势图', key: 'project', children: renderProjectChart() }, - { - label: '构建产物大小分析图', - key: 'file-size', - disabled: true, - children: renderFileSizeChart(), - }, - { - label: '版本构建性能图', - key: 'version-build', - disabled: true, - children: renderBuildChart(), - }, + { label: '构建产物大小分析图', key: 'file-size', children: renderFileSizeChart() }, + { label: '版本构建性能图', key: 'version-build', children: renderBuildChart() }, ]; const tabBarExtraContent = () => { From 1eb96dffe9b5fe6ddf888f2d77a05316a61decd1 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Mon, 15 Jul 2024 10:39:19 +0800 Subject: [PATCH 02/14] fix: sendAll need fileSizeChartData --- .../email/controllers/email.controller.ts | 38 +++++++++++++------ .../modules/email/services/email.service.ts | 11 +++--- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/apps/server/src/modules/email/controllers/email.controller.ts b/apps/server/src/modules/email/controllers/email.controller.ts index 76f186a..9698745 100644 --- a/apps/server/src/modules/email/controllers/email.controller.ts +++ b/apps/server/src/modules/email/controllers/email.controller.ts @@ -36,18 +36,18 @@ export class EmailController { try { await this.sendProject({ projectId, emails }); } catch (error) {} - console.log(formatDate(), ` ${name}, 定时发送单个子产品的数据周报到指定邮箱`); + console.log(formatDate(), ` ${name}, 发送【单个子产品】的数据周报到指定邮箱`); } }); } async handleSendAll() { if (process.env.DEFAULT_EMAIL) { - this.sendAll({ emails: process.env.DEFAULT_EMAIL }); - console.log(formatDate(), ' 定时发送所有子产品的数据周报到指定邮箱'); + console.log(formatDate(), ' 发送【所有子产品】的数据周报到指定邮箱'); + await this.sendAll({ emails: process.env.DEFAULT_EMAIL }); } } - @ApiOperation({ summary: '发送邮件' }) + @ApiOperation({ summary: '发送【单个子产品】的数据周报到指定邮箱' }) @HttpCode(HttpStatus.OK) @Post('sendProjectMail') async sendProject(@Body() { projectId, emails: _emails }) { @@ -92,7 +92,7 @@ export class EmailController { } } - @ApiOperation({ summary: '定时发送所有子产品的数据周报到指定邮箱' }) + @ApiOperation({ summary: '发送【所有子产品】的数据周报到指定邮箱' }) @HttpCode(HttpStatus.OK) @Post('sendAll') async sendAll(@Body() { emails = process.env.DEFAULT_EMAIL }) { @@ -102,40 +102,54 @@ export class EmailController { } const [startTime, endTime] = lastWeekRange; + const [startMonthTime, endMonthTime] = lastMonthRange; let projectList = await this.projectService.findAll(); projectList = projectList.filter((project) => project.name !== '汇总'); - const promiseList = projectList.map((project) => { + const projectChartDataPromiseList = projectList.map((project) => { return this.chartService.projectChart({ projectId: project.projectId, startTime, endTime, }); }); + const fileSizeChartPromiseList = projectList.map((project) => { + return this.chartService.fileSizeChart({ + projectId: project.projectId, + startTime: startMonthTime, + endTime: endMonthTime, + }); + }); + + const chartDataList = []; + const projectChartDataResults = await Promise.all(projectChartDataPromiseList); + const fileSizeChartDataResults = await Promise.all(fileSizeChartPromiseList); - const projectChartDataList = []; - const projectChartDataResults = await Promise.all(promiseList); for (let i = 0; i < projectChartDataResults.length; i++) { if (projectChartDataResults[i].versionNameList?.length) { const { projectId, name } = projectList[i]; - projectChartDataList.push({ + chartDataList.push({ projectId, name, projectChartData: projectChartDataResults[i], + fileSizeChartData: fileSizeChartDataResults[i], }); } } - if (projectChartDataList.length) { + if (chartDataList.length) { const result = await this.emailService.sendMailAllProject( emails, - projectChartDataList, + chartDataList, lastWeekRange ); return result; } } catch (error) { - throw new HttpException(`尝试发送所有子产品的数据周报失败, ${error}`, HttpStatus.OK); + throw new HttpException( + `尝试发送【所有子产品】的数据周报失败, ${error}`, + HttpStatus.OK + ); } } } diff --git a/apps/server/src/modules/email/services/email.service.ts b/apps/server/src/modules/email/services/email.service.ts index eecf212..b105d3f 100644 --- a/apps/server/src/modules/email/services/email.service.ts +++ b/apps/server/src/modules/email/services/email.service.ts @@ -36,22 +36,23 @@ export class EmailService { } // 定时发送所有子产品的数据周报到指定邮箱 - async sendMailAllProject(emails, projectChartDataList = [], lastWeekRange) { + async sendMailAllProject(emails, chartDataList = [], lastWeekRange) { const [_, __, startTime, endTime] = lastWeekRange; if (emails?.split(',')?.length) { - const html = renderChart(projectChartDataList); + const html = renderChart(chartDataList); try { const result = await this.mailerService.sendMail({ to: emails?.split(','), subject: `【数栈子产品】易测数据周报(${startTime}~${endTime})`, // 标题 html, }); - console.log(formatDate(), ' 发送所有子产品的数据周报成功', result); + + console.log(formatDate(), ' 发送【所有子产品】的数据周报成功', result); return result; } catch (error) { - console.log(formatDate(), ' 尝试发送所有子产品的数据周报失败', error); - throw new HttpException('尝试发送所有子产品的数据周报失败', HttpStatus.OK); + console.log(formatDate(), ' 尝试发送【所有子产品】的数据周报失败', error); + throw new HttpException('尝试发送【所有子产品】的数据周报失败', HttpStatus.OK); } } } From 489027a5608b5c9de75f1123f804e557734b654a Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Mon, 15 Jul 2024 14:46:39 +0800 Subject: [PATCH 03/14] chore: use pm2 --- .dockerignore | 3 --- .gitignore | 1 - .gitlab-ci.yml | 2 +- README.md | 2 +- apps/server/package.json | 5 +---- docker/Dockerfile.server | 25 ++++++++++--------------- docker/build.sh | 4 ++++ docs/docker.md | 12 +++++++----- package.json | 2 -- pm2/config.json | 4 ++-- scripts/deploy.mjs | 2 +- scripts/report-fileSize.js | 9 ++++----- scripts/start-test.sh | 2 +- scripts/start.sh | 2 +- 14 files changed, 33 insertions(+), 42 deletions(-) diff --git a/.dockerignore b/.dockerignore index b68d41e..57bc006 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,11 +15,8 @@ DEPLOY.md .env.* # 检测结果 -**/yice-report/*.html **/yice-report/**/*.html -# compiled output -dist node_modules # OS diff --git a/.gitignore b/.gitignore index 72d45d9..c755fed 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,6 @@ node_modules !.vscode/extensions.json # 检测结果 -**/yice-report/*.html **/yice-report/**/*.html yice-performance*.tar.gz diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 26997fe..855f6ac 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,7 +3,7 @@ before_script: - echo $CI_COMMIT_REF_NAME - whoami - - pnpm i --reporter=silent + - pnpm install --reporter=silent stages: - prettier diff --git a/README.md b/README.md index cb1d63f..cfc02da 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ cd yice-performance ### 服务启动 -- 安装服务依赖:`pnpm i` +- 安装服务依赖:`pnpm install` - 运行 node 服务和前端页面:`pnpm dev` > 服务配置项 `.env` 文件中的属性按实际填写即可,建议本地新建一个 `.env.local` 文件,配置一些较隐私的内容,这个文件不会被 git 感知且配置项的优先级大于 `.env` 文件。 diff --git a/apps/server/package.json b/apps/server/package.json index 7207703..09de395 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -1,10 +1,7 @@ { - "name": "yice-performance", + "name": "yice-performance-server", "version": "1.0.0", - "description": "", - "author": "", "private": true, - "license": "UNLICENSED", "scripts": { "dev": "NODE_ENV=development nest start --watch", "build": "NODE_ENV=production nest build", diff --git a/docker/Dockerfile.server b/docker/Dockerfile.server index 939d4dc..9bf4ee3 100644 --- a/docker/Dockerfile.server +++ b/docker/Dockerfile.server @@ -27,7 +27,7 @@ RUN apt-get update -y \ && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-khmeros fonts-kacst fonts-freefont-ttf libxss1 --no-install-recommends \ && rm -rf /var/lib/apt/lists/* \ && apt-get remove -y wget gnupg -# deb [arch=amd6 配置可能会在 /etc/apt/sources.list.d/google.list 和 /etc/apt/sources.list.d/google-chrome.list 中重复,再尝试一次 +# deb [arch=amd64 配置可能会在 /etc/apt/sources.list.d/google.list 和 /etc/apt/sources.list.d/google-chrome.list 中重复,再尝试一次 RUN rm -rf /etc/apt/sources.list.d/google-chrome.list \ && apt-get update -y \ && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-khmeros fonts-kacst fonts-freefont-ttf libxss1 --no-install-recommends @@ -38,7 +38,7 @@ RUN apt-get update -y && apt-get install -y curl \ && apt-get remove -y curl \ && apt-get install -y nodejs \ && npm config set registry https://registry.npmmirror.com/ \ - && npm install pnpm@6.35.1 -g + && npm install pnpm@6.35.1 pm2 -g # 设置工作目录 WORKDIR /yice-performance @@ -46,26 +46,21 @@ WORKDIR /yice-performance # 拷贝代码安装依赖 COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json ./ COPY apps/server/package.json ./apps/server/ -COPY apps/web/package.json ./apps/web/ -RUN pnpm install +RUN pnpm install --production -# 复制项目文件 -COPY apps/ ./apps/ +# 拷贝打包产物和配置文件 +COPY apps/server/dist ./apps/server/dist +COPY apps/web/dist ./apps/web/dist +COPY pm2 ./pm2 COPY .env ./ -# 减少 node_modules 的磁盘占用 -RUN pnpm build \ - && find . -name "node_modules" -type d -prune -exec rm -rf '{}' + \ - && pnpm install --production - -# 暴露端口 -EXPOSE 4000 # 定义环境变量 ENV NODE_ENV=production # Dockerfile 中需指定 chromium 路径 ENV PUPPETEER_EXECUTABLE_PATH='google-chrome-stable' -VOLUME [ "/yice-performance/apps/server/yice-report" ] +EXPOSE 4000 +VOLUME ["/yice-performance/apps/server/yice-report", "/yice-performance/pm2/logs"] # 启动应用程序 -CMD ["node", "apps/server/dist/main.js"] +CMD ["pm2", "restart", "./pm2/config.json", "--env", "production", "--no-daemon"] diff --git a/docker/build.sh b/docker/build.sh index ce0ecc1..b83009e 100644 --- a/docker/build.sh +++ b/docker/build.sh @@ -1,5 +1,9 @@ #!/bin/sh +# 构建 +pnpm install +pnpm build + cd docker # amd64 diff --git a/docs/docker.md b/docs/docker.md index 535388f..5cd7f42 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -14,17 +14,17 @@ docker network create yice-network ``` shell docker run -p 3306:3306 -d --name yice-mysql --network=yice-network -v /opt/dtstack/yice-performance/yice-mysql/conf:/etc/mysql/conf.d -v /opt/dtstack/yice-performance/yice-mysql/log:/var/log/mysql -v /opt/dtstack/yice-performance/yice-mysql/data:/var/lib/mysql registry.cn-hangzhou.aliyuncs.com/liuxy0551/yice-mysql:latest -docker run -p 4000:4000 -d --name yice-server --network=yice-network -v /opt/dtstack/yice-performance/yice-report:/yice-performance/apps/server/yice-report registry.cn-hangzhou.aliyuncs.com/liuxy0551/yice-server:latest +docker run -p 4000:4000 -d --name yice-server --network=yice-network -v /opt/dtstack/yice-performance/pm2-logs:/yice-performance/pm2/logs -v /opt/dtstack/yice-performance/yice-report:/yice-performance/apps/server/yice-report registry.cn-hangzhou.aliyuncs.com/liuxy0551/yice-server:latest ``` > - `-p` 表示端口映射,`-p 宿主机 port:容器 port`,这里暴漏端口是为了外部可以通过 GUI 工具查看数据 > - `-d` 表示后台运行并返回容器 id > - `--name` 表示给容器指定的名称 > - `-v /opt/dtstack/yice-performance/yice-mysql:/etc/mysql/conf.d` 等挂载路径表示将容器中的配置项、数据、日志都挂载到主机的 `/opt/dtstack/yice-performance/yice-mysql` 下 -> - `-v /opt/dtstack/yice-performance/yice-report:/yice-performance/apps/server/yice-report` 表示将容器中的检测报告挂载到宿主机 +> - `-v /opt/dtstack/yice-performance/pm2-logs:/yice-performance/pm2/logs` 等挂载路径表示将容器中的 pm2 日志和检测报告挂载到宿主机 > - 挂载的目的是为了在删除容器时数据不丢失,且尽量保持容器存储层不发生写操作。 -容器运行后,应当添加一个 `.env.local` 配置文件,内容在当前文档开头,然后通过下方命令重启容器: +容器运行后,应当添加一个 `.env.local` 配置文件,内容在当前文档开头,pm2 会自动重启服务: ``` shell cd /opt/dtstack/yice-performance @@ -32,8 +32,10 @@ cd /opt/dtstack/yice-performance ``` shell docker cp .env.local yice-server:/yice-performance/ -docker start yice-server -docker logs --tail 100 -f yice-server +``` + +``` shell +tail 200 -f /opt/dtstack/yice-performance/pm2-logs/pm2-out.log ```   执行上述命令后可以在浏览器中访问 `http://localhost:4000` 查看效果。 diff --git a/package.json b/package.json index ab89480..e88704f 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,6 @@ "deploy": "zx scripts/deploy.mjs", "deploy-test": "npm run deploy test", "fileSize": "node ./scripts/report-fileSize.js", - "pm2": "pm2 restart ./pm2/config.json --env production", - "pm2:test": "pm2 restart ./pm2/config-test.json --env staging", "prettier": "npx prettier \"**/*.ts\" \"**/*.tsx\" \"**/*.js\" \"**/*.json\" --check", "prettier:fix": "npx prettier \"**/*.ts\" \"**/*.tsx\" \"**/*.js\" \"**/*.json\" --write", "eslint": "npx eslint \"{apps,test}/**/*.ts\" \"{apps,test}/**/*.tsx\"", diff --git a/pm2/config.json b/pm2/config.json index 5699b1b..03f89f8 100644 --- a/pm2/config.json +++ b/pm2/config.json @@ -4,8 +4,8 @@ "cwd": "./", "max_memory_restart": "1G", "log_date_format": "YYYY-MM-DD HH:mm:ss", - "out_file": "apps/server/pm2/logs/pm2-out.log", - "error_file": "apps/server/pm2/logs/pm2-err.log", + "out_file": "./pm2/logs/pm2-out.log", + "error_file": "./pm2/logs/pm2-err.log", "env_production": { "NODE_ENV": "production" } diff --git a/scripts/deploy.mjs b/scripts/deploy.mjs index 2654e8f..0e645ee 100644 --- a/scripts/deploy.mjs +++ b/scripts/deploy.mjs @@ -39,7 +39,7 @@ $.verbose = false; infoLog('4. 开始在远程服务器解压、安装依赖并重启服务...'); $.verbose = true; echo( - await $`ssh root@${yiceServerIP} "cd /opt/dtstack/yice-performance${testStr}/; tar -xzf yice-performance${testStr}.tar.gz; rm -rf yice-performance${testStr}.tar.gz; cp scripts/start${testStr}.sh ./; ls -lahS; ./start${testStr}.sh; du -h --max-depth=1 ./apps/server/yice-report;"` + await $`ssh root@${yiceServerIP} "cd /opt/dtstack/yice-performance${testStr}/; tar -xzf yice-performance${testStr}.tar.gz; rm -rf yice-performance${testStr}.tar.gz; cp scripts/start${testStr}.sh ./; ls -lahS; ./start${testStr}.sh; du -h --max-depth=1 ./;"` ); $.verbose = false; doneLog(); diff --git a/scripts/report-fileSize.js b/scripts/report-fileSize.js index 95fa43d..f222280 100644 --- a/scripts/report-fileSize.js +++ b/scripts/report-fileSize.js @@ -11,11 +11,10 @@ inquirer loop: false, }, { - type: 'list', + type: 'confirm', name: 'isProd', - message: 'Server is prod', - choices: ['yes', 'no'], - default: 'yes', + message: 'Server is production? Default is yes', + default: true, loop: false, }, ]) @@ -26,7 +25,7 @@ function execFunc(res) { const cmd = `ssh root@${yiceServerIP} "cd /opt/dtstack/yice-performance${ isProd ? '' : '-test' - }/; du -h --max-depth=1 ./apps/server/yice-report"`; + }/; du -h --max-depth=1 ./"`; console.info(`Executing: ${cmd} \n`); diff --git a/scripts/start-test.sh b/scripts/start-test.sh index 59c75a4..fe7f5a5 100755 --- a/scripts/start-test.sh +++ b/scripts/start-test.sh @@ -2,4 +2,4 @@ sed -i -- 's/4000/4001/g' .env # pnpm -v pnpm install --production -pnpm pm2:test +pm2 restart ./pm2/config-test.json --env staging diff --git a/scripts/start.sh b/scripts/start.sh index c74a4aa..b49f7eb 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,3 +1,3 @@ # pnpm -v pnpm install --production -pnpm pm2 +pm2 restart ./pm2/config.json --env production From c182fcb9caff61f37570e9c4d423f8ba8a5deb62 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Mon, 15 Jul 2024 15:08:00 +0800 Subject: [PATCH 04/14] feat: log optimize --- apps/server/src/main.ts | 7 ++-- .../email/controllers/email.controller.ts | 8 ++--- .../modules/email/services/email.service.ts | 9 +++-- .../modules/task/services/task.run.service.ts | 21 ++++-------- .../src/modules/task/services/task.service.ts | 7 ++-- apps/server/src/utils/dingtalkRobot.ts | 7 ++-- apps/server/src/utils/taskRun.ts | 34 +++++++------------ 7 files changed, 33 insertions(+), 60 deletions(-) diff --git a/apps/server/src/main.ts b/apps/server/src/main.ts index 9fa2b15..ccd3c38 100644 --- a/apps/server/src/main.ts +++ b/apps/server/src/main.ts @@ -4,7 +4,6 @@ import * as compression from 'compression'; import { HttpExceptionFilter } from './filters/http-exception.filter'; import { AppModule } from './app.module'; -import { formatDate } from './utils'; const packageJson = require('../package.json'); const APP_PORT = process.env.APP_PORT || 4000; @@ -34,11 +33,9 @@ async function bootstrap() { await app.listen(APP_PORT, () => { console.log( - `${formatDate()} app is running in mode ${ - process.env.NODE_ENV - } on http://localhost:${APP_PORT}` + `app is running in mode [${process.env.NODE_ENV}] on http://localhost:${APP_PORT}` ); - console.log(`${formatDate()} api docs: http://localhost:${APP_PORT}/docs`); + console.log(`api docs: http://localhost:${APP_PORT}/docs`); }); } diff --git a/apps/server/src/modules/email/controllers/email.controller.ts b/apps/server/src/modules/email/controllers/email.controller.ts index 9698745..b636199 100644 --- a/apps/server/src/modules/email/controllers/email.controller.ts +++ b/apps/server/src/modules/email/controllers/email.controller.ts @@ -4,7 +4,7 @@ import { ApiOperation } from '@nestjs/swagger'; import { ChartService } from '@/modules/chart/services/chart.service'; import { ProjectService } from '@/modules/project/services/project.service'; -import { formatDate, lastMonthRange, lastWeekRange } from '@/utils'; +import { lastMonthRange, lastWeekRange } from '@/utils'; import { EmailService } from '../services/email.service'; @Controller('email') @@ -36,13 +36,13 @@ export class EmailController { try { await this.sendProject({ projectId, emails }); } catch (error) {} - console.log(formatDate(), ` ${name}, 发送【单个子产品】的数据周报到指定邮箱`); + console.log(`${name}, 发送【单个子产品】的数据周报到指定邮箱`); } }); } async handleSendAll() { if (process.env.DEFAULT_EMAIL) { - console.log(formatDate(), ' 发送【所有子产品】的数据周报到指定邮箱'); + console.log('发送【所有子产品】的数据周报到指定邮箱'); await this.sendAll({ emails: process.env.DEFAULT_EMAIL }); } } @@ -59,7 +59,7 @@ export class EmailController { const result = await this.generatePromise(project); return result; } catch (error) { - console.log(formatDate(), ' 邮件数据处理失败', error); + console.log('邮件数据处理失败', error); throw new HttpException('没有历史检测数据', HttpStatus.OK); } } diff --git a/apps/server/src/modules/email/services/email.service.ts b/apps/server/src/modules/email/services/email.service.ts index b105d3f..f196b48 100644 --- a/apps/server/src/modules/email/services/email.service.ts +++ b/apps/server/src/modules/email/services/email.service.ts @@ -2,7 +2,6 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { MailerService } from '@nestjs-modules/mailer'; import { IFileSizeChartData, IProjectChartData } from 'typing'; -import { formatDate } from '@/utils'; import { renderChart } from '@/utils/echarts'; @Injectable() @@ -26,10 +25,10 @@ export class EmailService { subject: `【${name}】易测数据周报(${startTime}~${endTime})`, // 标题 html, }); - console.log(formatDate(), ' 发送单个子产品的数据周报成功', result); + console.log('发送单个子产品的数据周报成功', result); return result; } catch (error) { - console.log(formatDate(), ' 尝试发送单个子产品的数据周报失败', error); + console.log('尝试发送单个子产品的数据周报失败', error); throw new HttpException('尝试发送单个子产品的数据周报失败', HttpStatus.OK); } } @@ -48,10 +47,10 @@ export class EmailService { html, }); - console.log(formatDate(), ' 发送【所有子产品】的数据周报成功', result); + console.log('发送【所有子产品】的数据周报成功', result); return result; } catch (error) { - console.log(formatDate(), ' 尝试发送【所有子产品】的数据周报失败', error); + console.log('尝试发送【所有子产品】的数据周报失败', error); throw new HttpException('尝试发送【所有子产品】的数据周报失败', HttpStatus.OK); } } diff --git a/apps/server/src/modules/task/services/task.run.service.ts b/apps/server/src/modules/task/services/task.run.service.ts index 510b3b8..9a23f84 100644 --- a/apps/server/src/modules/task/services/task.run.service.ts +++ b/apps/server/src/modules/task/services/task.run.service.ts @@ -174,15 +174,11 @@ export class TaskRunService { .printSql() .execute(); - console.log(formatDate(), ` taskId: ${taskId}, 数据整理完成,已落库`); + console.log(`taskId: ${taskId}, 数据整理完成,已落库`); } catch (error) { status = TASK_STATUS.FAIL; failReason = error; - console.log( - formatDate(), - ` taskId: ${taskId}, 性能数据落库失败`, - error?.toString() - ); + console.log(`taskId: ${taskId}, 性能数据落库失败`, error?.toString()); } await this.taskService.update(taskId, { score, @@ -193,15 +189,12 @@ export class TaskRunService { failReason, }); } else { - console.log( - formatDate(), - ` taskId: ${taskId}, 任务不是运行中的状态,故本次检测结果不做记录` - ); + console.log(`taskId: ${taskId}, 任务不是运行中的状态,故本次检测结果不做记录`); } - console.log(formatDate(), ` taskId: ${taskId}, 检测完成,本次检测耗时: ${duration}ms`); + console.log(`taskId: ${taskId}, 检测完成,本次检测耗时: ${duration}ms`); } catch (error) { - console.log(formatDate(), ' successCallback error', error); + console.log('successCallback error', error); this.failCallback(task, error?.toString(), duration); } } @@ -216,7 +209,7 @@ export class TaskRunService { }); await DingtalkRobot.failure(task); } catch (error) { - console.log(formatDate(), ' failCallback error', error); + console.log('failCallback error', error); } } @@ -337,7 +330,7 @@ export class TaskRunService { failReason, duration, }); - console.log(formatDate(), ` taskId: ${task.taskId}, ${failReason}!`); + console.log(`taskId: ${task.taskId}, ${failReason}!`); this.scheduleControl(); const { projectId } = await this.versionRepository.findOne({ diff --git a/apps/server/src/modules/task/services/task.service.ts b/apps/server/src/modules/task/services/task.service.ts index d7f26a8..aedd5a9 100644 --- a/apps/server/src/modules/task/services/task.service.ts +++ b/apps/server/src/modules/task/services/task.service.ts @@ -10,7 +10,7 @@ import { TASK_STATUS, TASK_TRIGGER_TYPE } from '@/const'; import { Performance } from '@/modules/performance/entities/performance.entity'; import { Project } from '@/modules/project/entities/project.entity'; import { Version } from '@/modules/version/entities/version.entity'; -import { formatDate, getWhere } from '@/utils'; +import { getWhere } from '@/utils'; import { TaskDto } from '../dto/task.dto'; import { TaskReqDto } from '../dto/task.req.dto'; import { Task } from '../entities/task.entity'; @@ -253,10 +253,7 @@ export class TaskService { try { fs.unlinkSync(filePath); } catch (_error) { - console.log( - formatDate(), - ` taskId: ${task.taskId}, 检测报告文件删除失败,${filePath}` - ); + console.log(`taskId: ${task.taskId}, 检测报告文件删除失败,${filePath}`); } }); diff --git a/apps/server/src/utils/dingtalkRobot.ts b/apps/server/src/utils/dingtalkRobot.ts index 7c6bf84..b4ac71f 100644 --- a/apps/server/src/utils/dingtalkRobot.ts +++ b/apps/server/src/utils/dingtalkRobot.ts @@ -1,5 +1,3 @@ -import { formatDate } from './date'; - /** * 钉钉机器人相关方法 * 消息类型:https://open.dingtalk.com/document/orgapp/robot-message-types-and-data-format @@ -41,13 +39,12 @@ class DingtalkRobot { at ); console.log( - formatDate(), - ` ${ + `${ process.env.NODE_ENV === 'staging' ? '【测试服】' : '' }taskId: ${taskId}, ${title}已发送` ); } catch (error) { - console.log(formatDate(), ' 发送失败', text); + console.log('钉钉告警消息发送失败', text); } } } diff --git a/apps/server/src/utils/taskRun.ts b/apps/server/src/utils/taskRun.ts index 48cc31e..ab750a2 100644 --- a/apps/server/src/utils/taskRun.ts +++ b/apps/server/src/utils/taskRun.ts @@ -5,7 +5,6 @@ import { join } from 'path'; import { getLhConfig, getLhOptions } from '@/configs/lighthouse.config'; import { getPuppeteerConfig } from '@/configs/puppeteer.config'; -import { formatDate } from './date'; import { sleep } from './sleep'; const fs = require('fs'); const moment = require('moment'); @@ -101,19 +100,16 @@ const toLogin = async (page, runInfo: ITask) => { if (currentUrl.includes('/login') || currentUrl.includes('/uic/#/')) { throw new Error(`taskId: ${taskId}, 登录失败,仍在登录页面`); } else { - console.log(formatDate(), ` taskId: ${taskId}, 登录完成`); + console.log(`taskId: ${taskId}, 登录完成`); } } catch (error) { const currentUrl = await page.url(); if (currentUrl.includes('/portal/#/')) { // 通过非用户名密码方式登录,已进入 portal 页面,比如默认登录方式设置为单点登录 - console.log( - formatDate(), - ` taskId: ${taskId}, 通过非用户名密码方式登录,已进入 portal 页面` - ); + console.log(`taskId: ${taskId}, 通过非用户名密码方式登录,已进入 portal 页面`); return 'not-uic'; } else { - console.log(formatDate(), ` taskId: ${taskId}, 登录出错`, error?.toString()); + console.log(`taskId: ${taskId}, 登录出错`, error?.toString()); throw error; } } @@ -124,7 +120,7 @@ const changeTenant = async (page, taskId) => { try { // 等待指定的选择器匹配元素出现在页面中 await page.waitForSelector('#change_ten_id', waitForSelectorOptions); - console.log(formatDate(), ` taskId: ${taskId}, 开始搜索并将选择租户`); + console.log(`taskId: ${taskId}, 开始搜索并将选择租户`); const sleepTime = Number(process.env.RESPONSE_SLEEP ?? 5); @@ -139,13 +135,13 @@ const changeTenant = async (page, taskId) => { // 业务中心 antd3.x try { await page.click('li.ant-select-dropdown-menu-item'); - console.log(formatDate(), ` taskId: ${taskId}, 这是数栈 v5.3.x 及之前版本的租户选择框`); + console.log(`taskId: ${taskId}, 这是数栈 v5.3.x 及之前版本的租户选择框`); } catch (_error) {} // 业务中心 antd4.x try { await page.click('.ant-select-item-option-content'); - console.log(formatDate(), ` taskId: ${taskId}, 这是数栈 v6.0.x 及之后版本的租户选择框`); + console.log(`taskId: ${taskId}, 这是数栈 v6.0.x 及之后版本的租户选择框`); } catch (_error) {} // 确定按钮,等待接口选择租户成功 @@ -155,13 +151,9 @@ const changeTenant = async (page, taskId) => { await page.waitForSelector('div.product-box', waitForSelectorOptions); // await sleep(sleepTime); - console.log(formatDate(), ` taskId: ${taskId}, 选择租户成功,开始检测`); + console.log(`taskId: ${taskId}, 选择租户成功,开始检测`); } catch (error) { - console.log( - formatDate(), - ` taskId: ${taskId}, 选择租户出错`, - `选择租户出错,${error?.toString()}` - ); + console.log(`taskId: ${taskId}, 选择租户出错`, `选择租户出错,${error?.toString()}`); throw error; } }; @@ -194,7 +186,7 @@ const handleLighthouseWithPuppeteer = async (runInfo: ITask, needLogin: boolean) getLhConfig({ locale: process.env.LIGHTHOUSE_LOCALE }) ); } catch (error) { - console.log(formatDate(), ` taskId: ${taskId}, 检测失败`, `${error?.toString()}`); + console.log(`taskId: ${taskId}, 检测失败`, `${error?.toString()}`); throw error; } finally { // 检测结束关闭标签页、无头浏览器 @@ -215,16 +207,14 @@ export const taskRun = async (task: ITask, successCallback, failCallback, comple // 依据是否包含 devops 来判断是否需要登录 const needLogin = !!(url.includes('devops') || loginUrl); console.log( - `\n${formatDate()} taskId: ${taskId}, 本次检测${ - needLogin ? '' : '不' - }需要登录,检测地址:`, + `\ntaskId: ${taskId}, 本次检测${needLogin ? '' : '不'}需要登录,检测地址:`, url ); // 检查方法 const runResult = await handleLighthouseWithPuppeteer(task, needLogin); - console.log(formatDate(), ` taskId: ${taskId}, 开始整理数据...`); + console.log(`taskId: ${taskId}, 开始整理数据...`); // 保存检测结果的报告文件,便于预览 const urlStr = url.replace(/http(s?):\/\//g, '').replace(/\/|\#|\?|\&/g, '-'); @@ -255,7 +245,7 @@ export const taskRun = async (task: ITask, successCallback, failCallback, comple const { weight, acronym } = auditRef; const { score, numericValue } = audits[auditRef.id] || {}; if (numericValue === undefined) { - console.log(formatDate(), ` taskId: ${taskId}, 检测结果出现问题,没有单项检测时长`); + console.log(`taskId: ${taskId}, 检测结果出现问题,没有单项检测时长`); throw new Error( `检测结果出现问题,没有单项检测时长,${JSON.stringify(audits[auditRef.id])}` ); From a90e8ecc816cb7fb40f19dbb38477fec4de1f475 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Mon, 15 Jul 2024 17:02:58 +0800 Subject: [PATCH 05/14] chore(release): 2.1.0 --- CHANGELOG.md | 12 ++++++++++++ package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df82784..1db70a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [2.1.0](///compare/v2.0.2...v2.1.0) (2024-07-15) + + +### Features + +* log optimize c182fcb + + +### Bug Fixes + +* sendAll need fileSizeChartData 1eb96df + ### [2.0.2](///compare/v2.0.1...v2.0.2) (2024-07-12) diff --git a/package.json b/package.json index e88704f..e3d7f16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yice-performance", - "version": "2.0.2", + "version": "2.1.0", "description": "", "author": "", "private": true, From 587ca24f512d82204e2643a59797c0066651a566 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Mon, 15 Jul 2024 17:05:41 +0800 Subject: [PATCH 06/14] feat: for github --- apps/server/src/mysql/some.sql | 19 ------------------- apps/web/src/const/index.ts | 2 +- apps/web/src/main.tsx | 2 +- .../home/components/chartModal/index.tsx | 14 ++++++++++++-- 4 files changed, 14 insertions(+), 23 deletions(-) delete mode 100644 apps/server/src/mysql/some.sql diff --git a/apps/server/src/mysql/some.sql b/apps/server/src/mysql/some.sql deleted file mode 100644 index 4299948..0000000 --- a/apps/server/src/mysql/some.sql +++ /dev/null @@ -1,19 +0,0 @@ --- 版本表添加 note 字段用于存储调度配置时的备注 -ALTER TABLE version add COLUMN note varchar(256) NULL COMMENT '备注'; - - - --- 任务表添加 previewImg 字段用于存储检测结果的首屏图片预览 -ALTER TABLE task add COLUMN previewImg LONGTEXT NULL COMMENT '结果的首屏图片预览'; - - - --- 产品表添加 emails 字段用于接收数据周报邮件 -ALTER TABLE project add COLUMN emails varchar(256) NULL COMMENT '子产品相关人员邮箱,用于接收数据周报邮件'; - - - - --- 版本表添加 sort 字段用于版本排序 -ALTER TABLE version add COLUMN sort int NULL DEFAULT 1 COMMENT '排序序号'; - diff --git a/apps/web/src/const/index.ts b/apps/web/src/const/index.ts index ba2ac8d..0cf4862 100644 --- a/apps/web/src/const/index.ts +++ b/apps/web/src/const/index.ts @@ -43,7 +43,7 @@ export const IS_USEFUL_TEXT = [ */ const scoreColor = { orangeMin: 50, - greenMin: 80, + greenMin: 90, }; export const getScoreColor = (score: number) => { diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsx index 30d17d4..6616c40 100644 --- a/apps/web/src/main.tsx +++ b/apps/web/src/main.tsx @@ -10,7 +10,7 @@ import Routers from './routers'; import './main.less'; const yiceRole = localStorage.getItem('yice-role'); -!yiceRole && localStorage.setItem('yice-role', YICE_ROLE.USER); +!yiceRole && localStorage.setItem('yice-role', YICE_ROLE.ADMIN); ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( diff --git a/apps/web/src/views/home/components/chartModal/index.tsx b/apps/web/src/views/home/components/chartModal/index.tsx index 183b746..0f0aefb 100644 --- a/apps/web/src/views/home/components/chartModal/index.tsx +++ b/apps/web/src/views/home/components/chartModal/index.tsx @@ -189,8 +189,18 @@ export default function ChartModal(props: IProps) { const tabItems = [ { label: '性能评分趋势图', key: 'project', children: renderProjectChart() }, - { label: '构建产物大小分析图', key: 'file-size', children: renderFileSizeChart() }, - { label: '版本构建性能图', key: 'version-build', children: renderBuildChart() }, + { + label: '构建产物大小分析图', + key: 'file-size', + disabled: true, + children: renderFileSizeChart(), + }, + { + label: '版本构建性能图', + key: 'version-build', + disabled: true, + children: renderBuildChart(), + }, ]; const tabBarExtraContent = () => { From b5d1edcd4d2a74830647e58fba386eae3d4c3626 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Tue, 16 Jul 2024 11:41:15 +0800 Subject: [PATCH 07/14] feat: console log optimize --- .../modules/email/controllers/email.controller.ts | 8 +++++--- .../src/modules/email/services/email.service.ts | 14 ++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/server/src/modules/email/controllers/email.controller.ts b/apps/server/src/modules/email/controllers/email.controller.ts index b636199..15d0de6 100644 --- a/apps/server/src/modules/email/controllers/email.controller.ts +++ b/apps/server/src/modules/email/controllers/email.controller.ts @@ -36,13 +36,15 @@ export class EmailController { try { await this.sendProject({ projectId, emails }); } catch (error) {} - console.log(`${name}, 发送【单个子产品】的数据周报到指定邮箱`); + console.log( + `\nprojectId: ${projectId}, ${name}, 发送【单个子产品】的数据周报到指定邮箱` + ); } }); } async handleSendAll() { if (process.env.DEFAULT_EMAIL) { - console.log('发送【所有子产品】的数据周报到指定邮箱'); + console.log('\n发送【所有子产品】的数据周报到指定邮箱'); await this.sendAll({ emails: process.env.DEFAULT_EMAIL }); } } @@ -59,7 +61,7 @@ export class EmailController { const result = await this.generatePromise(project); return result; } catch (error) { - console.log('邮件数据处理失败', error); + console.log(`\nprojectId: ${projectId}, ${project?.name}, 邮件数据处理失败`, error); throw new HttpException('没有历史检测数据', HttpStatus.OK); } } diff --git a/apps/server/src/modules/email/services/email.service.ts b/apps/server/src/modules/email/services/email.service.ts index f196b48..8285431 100644 --- a/apps/server/src/modules/email/services/email.service.ts +++ b/apps/server/src/modules/email/services/email.service.ts @@ -25,10 +25,16 @@ export class EmailService { subject: `【${name}】易测数据周报(${startTime}~${endTime})`, // 标题 html, }); - console.log('发送单个子产品的数据周报成功', result); + console.log( + `\nprojectId: ${projectId}, ${name}, 发送【单个子产品】的数据周报成功`, + result + ); return result; } catch (error) { - console.log('尝试发送单个子产品的数据周报失败', error); + console.log( + `\nprojectId: ${projectId}, ${name}, 尝试发送【单个子产品】的数据周报失败`, + error + ); throw new HttpException('尝试发送单个子产品的数据周报失败', HttpStatus.OK); } } @@ -47,10 +53,10 @@ export class EmailService { html, }); - console.log('发送【所有子产品】的数据周报成功', result); + console.log('\n发送【所有子产品】的数据周报成功', result); return result; } catch (error) { - console.log('尝试发送【所有子产品】的数据周报失败', error); + console.log('\n尝试发送【所有子产品】的数据周报失败', error); throw new HttpException('尝试发送【所有子产品】的数据周报失败', HttpStatus.OK); } } From d9e8e177e00651435117543c0676871020beb700 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Tue, 16 Jul 2024 11:41:47 +0800 Subject: [PATCH 08/14] fix: send email when email not saved --- apps/server/src/modules/email/controllers/email.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/modules/email/controllers/email.controller.ts b/apps/server/src/modules/email/controllers/email.controller.ts index 15d0de6..44e4d27 100644 --- a/apps/server/src/modules/email/controllers/email.controller.ts +++ b/apps/server/src/modules/email/controllers/email.controller.ts @@ -58,7 +58,7 @@ export class EmailController { if (emails?.split(',')?.length) { try { - const result = await this.generatePromise(project); + const result = await this.generatePromise({ ...project, emails }); return result; } catch (error) { console.log(`\nprojectId: ${projectId}, ${project?.name}, 邮件数据处理失败`, error); From 373488bdf9d153d2723646d8a6b1a115c5b97a83 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Tue, 16 Jul 2024 11:42:20 +0800 Subject: [PATCH 09/14] feat: week data email optimize --- .../email/controllers/email.controller.ts | 7 +------ .../src/modules/email/services/email.service.ts | 4 ++-- apps/server/src/utils/date.ts | 16 ++++++++-------- apps/server/src/utils/echarts.ts | 11 +++-------- apps/server/src/utils/static/chart.html | 2 +- .../components/chartModal/buildChart/index.tsx | 4 +++- .../chartModal/fileSizeChart/index.tsx | 6 ++++-- 7 files changed, 22 insertions(+), 28 deletions(-) diff --git a/apps/server/src/modules/email/controllers/email.controller.ts b/apps/server/src/modules/email/controllers/email.controller.ts index 44e4d27..c118b47 100644 --- a/apps/server/src/modules/email/controllers/email.controller.ts +++ b/apps/server/src/modules/email/controllers/email.controller.ts @@ -84,7 +84,6 @@ export class EmailController { if (projectChartData?.versionNameList?.length) { const result = await this.emailService.sendMail( project, - lastWeekRange, projectChartData, fileSizeChartData ); @@ -140,11 +139,7 @@ export class EmailController { } if (chartDataList.length) { - const result = await this.emailService.sendMailAllProject( - emails, - chartDataList, - lastWeekRange - ); + const result = await this.emailService.sendMailAllProject(emails, chartDataList); return result; } } catch (error) { diff --git a/apps/server/src/modules/email/services/email.service.ts b/apps/server/src/modules/email/services/email.service.ts index 8285431..08736c9 100644 --- a/apps/server/src/modules/email/services/email.service.ts +++ b/apps/server/src/modules/email/services/email.service.ts @@ -2,6 +2,7 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { MailerService } from '@nestjs-modules/mailer'; import { IFileSizeChartData, IProjectChartData } from 'typing'; +import { lastWeekRange } from '@/utils'; import { renderChart } from '@/utils/echarts'; @Injectable() @@ -10,7 +11,6 @@ export class EmailService { async sendMail( project, - lastWeekRange, projectChartData: IProjectChartData, fileSizeChartData: IFileSizeChartData ) { @@ -41,7 +41,7 @@ export class EmailService { } // 定时发送所有子产品的数据周报到指定邮箱 - async sendMailAllProject(emails, chartDataList = [], lastWeekRange) { + async sendMailAllProject(emails, chartDataList = []) { const [_, __, startTime, endTime] = lastWeekRange; if (emails?.split(',')?.length) { diff --git a/apps/server/src/utils/date.ts b/apps/server/src/utils/date.ts index 90e3456..c3e81e4 100644 --- a/apps/server/src/utils/date.ts +++ b/apps/server/src/utils/date.ts @@ -22,15 +22,15 @@ export const formatTime = (mo, isEnd?: boolean, output = 'YYYY-MM-DD HH:mm:ss') // 近七天 export const lastWeekRange: any = [ - formatTime(todayStart().subtract(7, 'days')), - formatTime(todayStart().subtract(1, 'days'), true), - formatTime(todayStart().subtract(7, 'days'), false, 'MM-DD'), - formatTime(todayStart().subtract(1, 'days'), true, 'MM-DD'), + formatTime(todayStart().subtract(6, 'days')), + formatTime(todayStart().subtract(0, 'days'), true), + formatTime(todayStart().subtract(6, 'days'), false, 'MM-DD'), + formatTime(todayStart().subtract(0, 'days'), true, 'MM-DD'), ]; // 近 30 天 export const lastMonthRange: any = [ - formatTime(todayStart().subtract(30, 'days')), - formatTime(todayStart().subtract(1, 'days'), true), - formatTime(todayStart().subtract(30, 'days'), false, 'MM-DD'), - formatTime(todayStart().subtract(1, 'days'), true, 'MM-DD'), + formatTime(todayStart().subtract(29, 'days')), + formatTime(todayStart().subtract(0, 'days'), true), + formatTime(todayStart().subtract(29, 'days'), false, 'MM-DD'), + formatTime(todayStart().subtract(0, 'days'), true, 'MM-DD'), ]; diff --git a/apps/server/src/utils/echarts.ts b/apps/server/src/utils/echarts.ts index 1d3a8a2..af00ab0 100644 --- a/apps/server/src/utils/echarts.ts +++ b/apps/server/src/utils/echarts.ts @@ -81,16 +81,11 @@ export const getFileSizeChartOptions = (fileSizeChartData: IFileSizeChartData) = bottom: '3%', containLabel: true, }, - toolbox: { - feature: { - saveAsImage: { show: true }, - }, - }, xAxis: { type: 'value', name: '构建产物大小(MB)', nameTextStyle: { - padding: [0, 0, 0, -80], + padding: [0, 0, 0, -100], }, axisLine: { show: true, @@ -125,7 +120,7 @@ export const getFileSizeChartOptions = (fileSizeChartData: IFileSizeChartData) = export const renderChart = (arr: IProjectChartDataList[] = []) => { const config = { width: 475, - height: 200, + height: 240, // width: 950, // height: 400, }; @@ -168,7 +163,7 @@ const renderHtml = (list) => { const renderChartItem = (list = []) => { let html = ''; list.forEach(({ projectId, name, projectChartBase64, fileSizeChartBase64 }) => { - html += ``; + html += ``; }); return html; }; diff --git a/apps/server/src/utils/static/chart.html b/apps/server/src/utils/static/chart.html index 43bca2d..7509312 100644 --- a/apps/server/src/utils/static/chart.html +++ b/apps/server/src/utils/static/chart.html @@ -55,7 +55,7 @@
${name} 近七天
- +
Date: Tue, 16 Jul 2024 14:18:54 +0800 Subject: [PATCH 12/14] build: docker image tag and push --- docker/build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker/build.sh b/docker/build.sh index b83009e..c3b3f7a 100644 --- a/docker/build.sh +++ b/docker/build.sh @@ -9,3 +9,9 @@ cd docker # amd64 docker buildx build --platform linux/amd64 -f Dockerfile.mysql -t liuxy0551/yice-mysql . docker buildx build --platform linux/amd64 -f Dockerfile.server -t liuxy0551/yice-server ../ + +# docker tag liuxy0551/yice-mysql registry.cn-hangzhou.aliyuncs.com/liuxy0551/yice-mysql:latest +# docker push registry.cn-hangzhou.aliyuncs.com/liuxy0551/yice-mysql:latest + +# docker tag liuxy0551/yice-server registry.cn-hangzhou.aliyuncs.com/liuxy0551/yice-server:latest +# docker push registry.cn-hangzhou.aliyuncs.com/liuxy0551/yice-server:latest From 6fbdd17b1f94671e7b2fb53dd662ef4594138e0b Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Tue, 16 Jul 2024 15:03:06 +0800 Subject: [PATCH 13/14] feat: log optimize --- .../modules/build/services/build.service.ts | 32 ++++++++++++------- .../modules/devops/services/devops.service.ts | 3 ++ docs/docker.md | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/apps/server/src/modules/build/services/build.service.ts b/apps/server/src/modules/build/services/build.service.ts index 86425f8..c21ab98 100644 --- a/apps/server/src/modules/build/services/build.service.ts +++ b/apps/server/src/modules/build/services/build.service.ts @@ -43,19 +43,27 @@ export class BuildService { throw new HttpException('repository, branch 不符合规则,此次数据不录入', HttpStatus.OK); } - const version = branch.split('_')?.filter((item) => item.includes('.x'))?.[0]; + try { + const version = branch.split('_')?.filter((item) => item.includes('.x'))?.[0]; - const { projectId } = await this.projectRepository.findOneBy(getWhere({ appName })); + const { projectId } = await this.projectRepository.findOneBy(getWhere({ appName })); - const build = this.buildRepository.create({ - projectId, - repository, - branch, - version, - duration, - fileSize, - }); - const result = await this.buildRepository.save(build); - return result; + const build = this.buildRepository.create({ + projectId, + repository, + branch, + version, + duration, + fileSize, + }); + const result = await this.buildRepository.save(build); + return result; + } catch (error) { + console.log( + `\n构建数据未保存, appName: ${appName}, repository: ${repository}, branch: ${branch}, duration: ${duration}, fileSize: ${fileSize}`, + error + ); + throw new HttpException('构建数据未保存', HttpStatus.OK); + } } } diff --git a/apps/server/src/modules/devops/services/devops.service.ts b/apps/server/src/modules/devops/services/devops.service.ts index 586ea07..8885ea1 100644 --- a/apps/server/src/modules/devops/services/devops.service.ts +++ b/apps/server/src/modules/devops/services/devops.service.ts @@ -15,6 +15,7 @@ export class DevopsService { }); return res?.data?.data; } catch (error) { + console.log(`请求 devops 接口失败, DEVOPS_COOKIE: ${process.env.DEVOPS_COOKIE}`); throw new HttpException('请求 devops 接口失败', HttpStatus.OK); } } @@ -86,6 +87,7 @@ export class DevopsService { const history = await this.getHistory(histories?.[0]?.id); return history; } catch (error) { + console.log(`请求 devops 接口失败, DEVOPS_COOKIE: ${process.env.DEVOPS_COOKIE}`); throw new HttpException('请求 devops 接口失败', HttpStatus.OK); } } @@ -96,6 +98,7 @@ export class DevopsService { const result = await this.axiosGet(`http://devops.dtstack.cn/api/v1/projects`); return result; } catch (error) { + console.log(`请求 devops 接口失败, DEVOPS_COOKIE: ${process.env.DEVOPS_COOKIE}`); throw new HttpException('请求 devops 接口失败', HttpStatus.OK); } } diff --git a/docs/docker.md b/docs/docker.md index 5cd7f42..835721a 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -98,7 +98,7 @@ docker cp /home/app/yice-performance/.env yice-server:/yice-performance/.env ``` ``` shell -docker start yice-server +docker restart yice-server ``` From 4104cc767c654ba9636f11f98d530b90a71b8987 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Tue, 16 Jul 2024 15:03:25 +0800 Subject: [PATCH 14/14] chore(release): 2.1.2 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7fd4bb..348772c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.1.2](///compare/v2.1.1...v2.1.2) (2024-07-16) + + +### Features + +* log optimize 6fbdd17 + ### [2.1.1](///compare/v2.1.0...v2.1.1) (2024-07-16) diff --git a/package.json b/package.json index 1fb58a3..2366bfb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yice-performance", - "version": "2.1.1", + "version": "2.1.2", "description": "", "author": "", "private": true,