-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:配置模板的导入 #2711
feat:配置模板的导入 #2711
Conversation
Ambition9186
commented
Oct 26, 2023
- 配置模板支持zip、gz、tar压缩包导入
- 批量新增和修改配置模板
8b0e922
to
1719cdd
Compare
|
||
const ( | ||
// MaxFileSize 最大文件 | ||
MaxFileSize = 5 * 1024 * 1024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是上传的文本类型最大文件大小,改为 MaxUploadTextFileSize 更加见名知意
// MaxFileSize 最大文件 | ||
MaxFileSize = 5 * 1024 * 1024 | ||
// ContentLength 文件大小 | ||
ContentLength = 100 * 1024 * 1024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同理,这里也改成 MaxUploadContentLength
// ContentLength 文件大小 | ||
ContentLength = 100 * 1024 * 1024 | ||
// FileMode 文件模式 | ||
FileMode = "unix" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个常量已经定义过了:
string(table.Unix)
m := dao.genQ.TemplateRevision | ||
// 根据templateIDs获取TemplateRevision中最大ID | ||
// 通过最大ID查询 | ||
var templateId []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以直接 var templateRevisionIDs []uint32 吧,我理解如果最后查询出来只有一列值,是可以 Scan 到一个数组的吧
func (c *configImport) uploadFile(kt *kit.Kit, filePath, rootDir string) (*types.FileInfo, error) { | ||
var ( | ||
content bytes.Buffer | ||
fileType = "text" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"text" 已被定义为常量
string(table.Text)
|
||
message BatchUpsertTemplatesReq { | ||
message Item { | ||
pbtemplate.Template templates = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里 templates 和 template_revisions 都不是 repeated 类型,命名不需要复数形式
@@ -239,6 +241,21 @@ func getLatestTmplRevisions(tmplRevisions []*table.TemplateRevision) map[uint32] | |||
|
|||
func generateRevisionName() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里生成版本名称,到秒级就够了吧。这里索引应该是 templateRevisionName + templateID,一次导入操作,分别是对不同的 template 生成新的版本,基本上是不会重复的
return nil | ||
} | ||
|
||
func (s *Service) validationData(grpcKit *kit.Kit, updateId []uint32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里名称改为 validateBatchUpsertTamplates
}) | ||
} | ||
|
||
err := s.doTemplateRevision(kt, tx, toCreateTr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改名称为: s.doCreateTemplateRevisions
@@ -309,6 +315,12 @@ service Config { | |||
get : "/api/v1/config/biz/{biz_id}/template_spaces/{template_space_id}/templates/list_not_bound" | |||
}; | |||
} | |||
rpc GetTemplateDetailByUniqueKey(GetTemplateDetailByUniqueKeyReq) returns (GetTemplateDetailByUniqueKeyResp) { | |||
option (google.api.http) = { | |||
post : "/api/v1/config/biz/{biz_id}/template_spaces/{template_space_id}/templates/detail" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据蓝鲸最新接口规范,按 restful 风格定义接口,这里用 get 方法
a29a977
to
2d2a8fb
Compare
|
||
message ListTemplateByTupleResp{ | ||
message Item { | ||
pbtemplate.Template templates = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也是哈,不是 repeated 类型不用复数形式命名
message ListTemplateByTupleResp{ | ||
message Item { | ||
pbtemplate.Template templates = 1; | ||
pbtr.TemplateRevision template_revisions = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
@@ -239,6 +240,20 @@ func getLatestTmplRevisions(tmplRevisions []*table.TemplateRevision) map[uint32] | |||
|
|||
func generateRevisionName() string { | |||
// Format the current time as YYYYMMDDHHMMSS | |||
time.Sleep(time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不用 sleep,不然上传一个压缩包有100个配置得 sleep 100 秒
} | ||
|
||
message ListConfigItemByTupleResp { | ||
repeated pbci.ConfigItem config_item = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里命名需要用复数形式
fileType = string(table.Binary) | ||
} else { | ||
// 读取文件内容的前512个字节 | ||
buffer := make([]byte, 512) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里只有5M以下就全部读进内存,只读 512 可能判断不准确,并且可能截断 utf8 的编码导致将文本文件误识别为二进制文件
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之后还需要验证一下如果并发读大文件缓存过快增长会不会导致 OOM,如果会导致OOM,可以考虑限制并发处理文件的数量,以及用 sync.Pool 创建一个可复用的 buffer 池
d36d1b1
to
669c668
Compare
"bscp.io/pkg/types" | ||
) | ||
|
||
var bufferPool sync.Pool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bufferPool 的 Get 方法一般是在全局变量定义的时候就声明了,不确定延迟声明会不会导致不同请求中使用的是不同的 bufferPool 对象,这个改为
var bufferPool = sync.Pool {
New: func() interface{} {
return new(bytes.Buffer)
},
}
669c668
to
e5cf554
Compare
* kv 相关接口 * kv 相关接口 * 配置模板压缩包导入以及批量新增配置模板 (#2711) * kv 相关接口 * golint * golint * kv string 不允许换行 --------- Co-authored-by: ambition <[email protected]>