-
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: bcs-monitor rest 泛型优化 #3681
base: master
Are you sure you want to change the base?
Conversation
f881b51
to
e7fee4d
Compare
@@ -28,101 +31,133 @@ const ( | |||
// @Tags Metrics | |||
// @Success 200 {string} string | |||
// @Router /overview [get] | |||
func GetClusterOverview(c *rest.Context) (interface{}, error) { | |||
handler, err := query.HandlerFactory(c.Request.Context(), c.ClusterId) | |||
func GetClusterOverview(c context.Context, req query.GetClusterOverviewReq) (query.ClusterOverviewMetric, error) { |
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.
- 入参,出差应该都是用指针类型
- 默认添加Validate做参数校验
- 下同
|
||
// GetLogRuleReq get log rule request | ||
type GetLogRuleReq struct { | ||
ProjectId string `json:"-" in:"path=projectId;required"` |
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.
json是有意义的, 返回错误以json这个tag返回,下同
if err != nil { | ||
return nil, err | ||
return promclient.ResultData{}, err |
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.
返回也是指针,所以可以返回nil
} | ||
|
||
// ClusterCPURequestUsage 集群 CPU 装箱率 | ||
// @Summary 集群 CPU 装箱率 | ||
// @Tags Metrics | ||
// @Success 200 {string} string | ||
// @Router /cpu_request_usage [get] | ||
func ClusterCPURequestUsage(c *rest.Context) (interface{}, error) { | ||
handler, err := query.HandlerFactory(c.Request.Context(), c.ClusterId) | ||
func ClusterCPURequestUsage(c context.Context, uQuery query.UsageQuery) (promclient.ResultData, error) { |
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.
这里函数签名统一使用req吧(req *query.UsageQuery),下同
|
||
route.Get("/namespaces/{namespace}/pods/{pod}/containers", rest.Handler(pod.GetPodContainers)) | ||
route.Get("/namespaces/{namespace}/pods/{pod}/logs", rest.Handler(pod.GetPodLog)) | ||
route.Get("/namespaces/{namespace}/pods/{pod}/logs/download", rest.StreamHandler(pod.DownloadPodLog)) |
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.
这个命名先和现在项目统一下, 直接使用Handle/Stream 都是动词,主要是简洁点
9b2918a
to
eca9639
Compare
980aad5
to
ca9ec12
Compare
ca9ec12
to
142f7ac
Compare
feat: bcs-monitor rest 泛型优化