zhaoyingbo f886c54947
All checks were successful
CI Monitor MIflow / build-image (push) Successful in 55s
chore: 暂时屏蔽Review功能
2024-08-14 06:38:01 +00:00
2024-07-26 09:20:53 +00:00
2024-08-09 08:03:52 +00:00
2024-08-12 12:24:45 +00:00
2024-08-08 11:04:09 +00:00
2024-08-13 01:43:09 +00:00
2024-08-13 02:07:16 +00:00
2024-08-12 12:24:45 +00:00
2024-08-12 12:24:45 +00:00
2024-08-12 12:24:45 +00:00
2024-08-12 12:24:45 +00:00
2024-03-05 09:52:36 +00:00
2024-07-25 01:11:07 +00:00
2024-08-13 01:43:09 +00:00
2024-08-08 11:04:09 +00:00
2024-03-05 09:52:36 +00:00

流水线监控

监听新 projId自动补全内容获取从 20240101 到当前的所有流水线信息

监听功能未知原因不好用,先不做了,改手动遍历了

拿到 project_id 后,获取数据表中最新的 pipeline 的 Id然后比对接口中的 ID 进行填充

如果没有 pipeline 的 id直接从接口中获取 20240101 到当前的流水线信息

先从数据中获取用户信息填充,随后在根据填充完的用户信息获取全部的 userid 的列表,再写 pipeline 表

流水线成功提醒

接收Gitlab 的 WebHooks请求Secret 令牌 实际上为 Egg 的 API_KEY

获取对应的MR信息MR 的发起者也需要发送通知

组织卡片信息,给 Commit的用户以及 可能的 MR发起者发送通知

处理在中间Stage需要提醒的情况

在stage全部成功的情况下按finish_at时间排序找到最后一个stage如果stage的状态是成功且该build的id没有发送过通知则发送通知

流水线通知只是在Pipeline纬度上所以某个stage的变化不会触发通知

在流水线为running如果需要监听Stage且该stage全部的job有非结束状态时即createdpendingrunningmanualscheduled

加入数据库监控列表每10s检查一次如果stage状态全部成功的时候则发送通知并删除监控

在流水线结束,即状态为failedcanceledskippedsuccess,的时候,删除监控,并在状态为success的时候,发送通知

数据库表信息

数据库地址

project 信息

{
  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 信息

{
  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 信息

{
  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

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

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 表

{
  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 表

{
  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 表

{
  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"
}

我想按天展示每个项目的 pipeline 按 ref 区分的平均 duration如何创建视图

机器人

CICD 统计总结

卡片 IDctp_AAyVLS6Q37cL

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
}

流水线成功通知

卡片 IDctp_AA36QafWyob2

JSON 示例

{
  "project": "cloudml-visuals/fe/test",
  "project_link": "https://git.n.xiaomi.com/cloudml-visuals/fe/test",
  "pipeline": "8815519",
  "pipeline_link": "https://git.n.xiaomi.com/cloudml-visuals/fe/cloud-ml-fe/-/pipelines",
  "ref": "preview",
  "ref_link": "https://git.n.xiaomi.com/cloudml-visuals/fe/cloud-ml-fe/-/commits/preview",
  "commit_user": "赵英博",
  "duration": "1m35s",
  "participant": "赵英博、吴婷",
  "commit_message": "chore: Add .gitlab-ci.yml for printing \"Hello, world!\"",
  "mr": "cloudml-visuals/fe/cloud-ml-fe!374",
  "mr_link": "https://git.n.xiaomi.com/cloudml-visuals/fe/cloud-ml-fe/-/merge_requests/374"
}
Description
监控CI运行情况,跟踪每周变化,接收Gitlab Event请求,发送上线通知
Readme 710 KiB
Languages
TypeScript 99.3%
JavaScript 0.6%
Dockerfile 0.1%