edge-channel是一个适用于配置/任务需要下发到边缘机器的轻量级通道系统。
架构概览
统一下发通道-系统架构.png
交互方式
edge-channel主要交互方式: http/grpc
系统会哪几个角色/模块
- 配置中心服务 ----- 配置生成服务
- edge-channel-api ---- 通道api服务,接收配置中心服务传递的任务
- edge-channel-agent ---- 通道边缘服务,用于edge-channel-api交互和下发任务到配置边缘服务
- 配置边缘服务 ---- 配置边缘服务,接收并处理任务/配置的生效
如何接入统一下发通道?使用方的每个模块需要做什么?(下面都通过http示例, grpc可以通过proto转换)
一、配置中心服务
- 注册服务到edge-channel-api
curl --location 'http://edge-channel-api/v1/edgeChannel/server' \
--header 'Content-Type: application/json' \
--data '{
"name": "server name", // 服务名
"threshold": 100, // 服务任务的成功率阈值(即X台机器中需要Y台机器完成则为任务成功,threshold=Y/X * 100)
"strategy_id": 1,// 服务使用的策略, 1:全网下发, 2:自定义策略(生效机器在任务中指定, 后面会将), 其余则需要创建策略后绑定
"server_type": 1, // 服务类型 1:无状态, 2:有状态,有状态任务会根据用户的server_task_id按顺序下发
"remark": "remark", // 备注
"edge_receive_task_url": "http://localhost:7953/config", // 边缘配置服务接收edge-channel任务的接口
"qps": 1 // 服务任务的提交到edge-channel的qps 个/s超过会被限速
}'
注册完服务返回示例
{
"status": {
"code": 1,
"message": "success",
"created_at": "2025-03-24 16:18:22"
},
"data": {
"server_id": 3, // 服务ID
"server_secret": "b18ed8147abc6db33980083707dabf73" // 服务秘钥用于配置服务与edge-channel-api交互使用
}
}
- 任务提交
Authorization生成方法
func generateSignature(secretKey string) (string, error) {
tm10 := strconv.FormatInt(time.Now().Unix(), 10)[:10]
hash := md5.New()
hash.Write([]byte(tm10 + secretKey))
str := hex.EncodeToString(hash.Sum(nil))
sig := tm10 + str[len(str)-8:]
return sig, nil
}
curl --location 'http://edge-channel-api/v1/edgeChannel/task' \
--header 'Content-Type: application/json' \
--header 'Authorization: xxxxxxxx' \
--data '{
"server_id": 2, // 服务id
"server_task_id": 50001, //配置中心服务记录的任务ID, 有状态情况下必传(需要通过该id保证顺序下发), 无状态可不传
"task_info": "happy1", //任务/配置的信息,配置边缘服务接收到的就是该信息
"task_assign_machine_list": [] // 服务绑定的是自定义策略的情况必传
}'
返回示例
{
"status": {
"code": 1,
"message": "success",
"created_at": "2025-03-24 15:47:24"
},
"data": {
"task_id": 1 // 该ID用于后面查询任务的下发情况适用
}
}
- 任务结果查询
curl --location --header 'Authorization: xxxxxxxx' 'http://edge-channel-api/v1/edgeChannel/task/result/1'
返回示例
{
"task_id": 1,
"total": 100,
"success_total": 90,
"fail_total": 10,
"status": 2,
"fail_list": [
{
"machine": "machine-01",
"reason": "Network timeout"
},
{
"machine": "machine-02",
"reason": "Insufficient memory"
}
]
}
二、配置边缘服务
- 提供注册服务时填写的edge_receive_task_url的API接口服务
接收参数:
{
"task_info": "xxxx", // 配置/任务信息
"server_task_id": 1, // 配置中心服务记录的任务ID
"task_id": 1, // edge-channel生成的任务id
"pack_id":1, // 任务包id
"server_id": 2 // 配置中心服务id
}
- 处理完任务反馈任务结果给edge-channel-agent
curl --location 'http://edge-channel-agent/api/edgeChannel/agent/report' \
--header 'Content-Type: application/json' \
--data '{
"task_result_list": [
{
"task_id": 1, //edge-channel生成的任务id
"server_task_id": 1,//配置中心服务记录的任务ID
"server_id": 2, // 配置中心服务id
"pack_id": 1, // 任务包id
"status": 3, // 3成功4失败
"result": "成功了老铁" // 结果信息, 可错误的时候填写错误原因即可
}
]
}'
- (可能用到)获取服务的某个任务
通过edge-channel的id获取任务
3为edge-channel记录的任务id
curl --location 'http://localhost:8081/api/edgeChannel/agent/task/3'
返回示例
{
"status": {
"code": 1,
"message": "success",
"created_at": "2025-03-24 17:02:44"
},
"data": {
"task_id": 3,
"strategy_id": 1,
"pack_id": 2,
"task_info": "mytest3",
"server_task_id": 3,
"server_id": 1
}
}
通过配置中心服务的id获取任务
curl --location 'http://localhost:8081/api/edgeChannel/agent/task_search?server_id=1&server_task_id=1'
返回示例
{
"status": {
"code": 1,
"message": "success",
"created_at": "2025-03-24 17:20:35"
},
"data": {
"task_id": 1,
"strategy_id": 1,
"pack_id": 3,
"task_info": "mytest1",
"server_task_id": 1,
"server_id": 1
}
}