2024-05-06 03:28:58 +00:00

183 lines
4.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# CI 监控
监听新 projId自动补全内容获取从 20240101 到当前的所有流水线信息
监听功能未知原因不好用,先不做了,改手动遍历了
拿到 project_id 后,获取数据表中最新的 pipeline 的 Id然后比对接口中的 ID 进行填充
如果没有 pipeline 的 id直接从接口中获取 20240101 到当前的流水线信息
先从数据中获取用户信息填充,随后在根据填充完的用户信息获取全部的 userid 的列表,再写 pipeline 表
# 图表库(不用了)
https://g2plot.antv.antgroup.com/examples
# 数据信息
project 信息
```js
{
id: 'aaa',
project_id: 131366,
description: "场景复现平台-展示设备(移动、音箱、小爱建议、车载、手表等设备)上小爱执行结果及相关处理流程",
name: "ai-scene-review-fe",
path_with_namespace: "miai-fe/fe/ai-scene-review-fe",
web_url: "https://git.n.xiaomi.com/miai-fe/fe/ai-scene-review-fe",
avatar_url: null,
has_new_cicd: false,
}
```
pipeline 信息
```js
{
id: 'bbb',
project_id: 'aaa',
user_id: 'ccc',
pipeline_id: 7646046,
ref: "preview",
status: "success",
web_url: "https://git.n.xiaomi.com/miai-fe/fe/ai-scene-review-fe/-/pipelines/7646046",
started_at: "2024-03-01T16:47:40.192+08:00",
finished_at: "2024-03-01T16:49:30.624+08:00",
duration: 100,
queued_duration: 6,
}
```
user 信息
```js
{
id: 'ccc',
user_id: 10011,
username: "zhaoyingbo",
name: "赵英博",
avatar_url: "https://git.n.xiaomi.com/uploads/-/system/user/avatar/10011/avatar.png",
web_url: "https://git.n.xiaomi.com/zhaoyingbo"
}
```
每周每个项目按分支的运行时长统计 SQL `statisticsPerProj`
```SQL
SELECT
(ROW_NUMBER() OVER()) as id,
strftime('%Y-%W', datetime(pip.started_at)) AS week,
p.name AS name,
ROUND(AVG(pip.duration/60.0), 1) AS duration,
pip.ref
FROM project p
JOIN pipeline pip ON p.id = pip.project_id
GROUP BY name, week, pip.ref;
```
每周流水线运行统计 SQL `statisticsPerWeek`
```SQL
SELECT
(ROW_NUMBER() OVER()) as id,
strftime('%Y-%W', datetime(started_at)) AS week,
COUNT(*) AS total_count,
SUM(CASE WHEN status = 'success' THEN 0 ELSE 1 END) AS failed_count,
SUM(CASE WHEN status = 'success' THEN 1 ELSE 0 END) AS success_count,
ROUND(SUM(CASE WHEN status = 'success' THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 1) AS success_rate,
ROUND(AVG(duration/60.0), 1) AS duration
FROM pipeline
GROUP BY week;
```
# GPT
我有一个 sqlite 数据库,表如下
project 表
```js
{
id: 'aaa',
project_id: 131366,
description: "场景复现平台-展示设备(移动、音箱、小爱建议、车载、手表等设备)上小爱执行结果及相关处理流程",
name: "ai-scene-review-fe",
path_with_namespace: "miai-fe/fe/ai-scene-review-fe",
web_url: "https://git.n.xiaomi.com/miai-fe/fe/ai-scene-review-fe",
avatar_url: null,
has_new_cicd: false,
}
```
pipeline 表
```js
{
id: 'bbb',
project_id: 'aaa',
user_id: 'ccc',
pipeline_id: 7646046,
ref: "preview",
status: "success",
web_url: "https://git.n.xiaomi.com/miai-fe/fe/ai-scene-review-fe/-/pipelines/7646046",
started_at: "2024-03-01T16:47:40.192+08:00",
finished_at: "2024-03-01T16:49:30.624+08:00",
duration: 100,
queued_duration: 6,
}
```
user 表
```js
{
id: 'ccc',
user_id: 10011,
username: "zhaoyingbo",
name: "赵英博",
avatar_url: "https://git.n.xiaomi.com/uploads/-/system/user/avatar/10011/avatar.png",
web_url: "https://git.n.xiaomi.com/zhaoyingbo"
}
```
我想按天展示每个项目的 pipline 按 ref 区分的平均 duration如何创建视图
# 机器人
卡片 IDctp_AAyVLS6Q37cL
JSON 示例
```json
{
"total_count": "29", // OK
"group_table": [
{
"project_name": "ai-ak-fe",
"project_ref": "master",
"project_duration": "1.4",
"project_duration_rate": "<font color='green'>↓12%</font>"
},
{
"project_name": "ai-class-schedule-fe",
"project_ref": "preview",
"project_duration": "3.2",
"project_duration_rate": "<font color='red'>↑5%</font>"
},
{
"project_name": "ai-scene-review-fe",
"project_ref": "staging",
"project_duration": "5.4",
"project_duration_rate": "<font color='green'>↓6%</font>"
}
],
"weekly_count_rate": "<font color='red'>较上周 ↑5%</font>", // OK
"weekly_duration_rate": "<font color='green'>较上周 ↓12%</font>", // OK
"weekly_success_rate": "<font color='red'>较上周 ↑12%</font>", // OK
"duration": "0.9", // OK
"success_rate": "100", // OK
"has_new_cicd_count": "15", // OK
"without_new_cicd_count": "20" // OK
}
```