Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

LidolLxf
Copy link
Contributor

feat: bcs-monitor rest 泛型优化

@LidolLxf LidolLxf force-pushed the feat_monitor_rest branch 4 times, most recently from f881b51 to e7fee4d Compare February 21, 2025 10:28
@@ -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) {
Copy link
Member

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"`
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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))
Copy link
Member

@ifooth ifooth Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个命名先和现在项目统一下, 直接使用Handle/Stream 都是动词,主要是简洁点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants