Skip to content

Commit

Permalink
feat: add biz resource limit config
Browse files Browse the repository at this point in the history
  • Loading branch information
AlkaidChan committed Mar 1, 2024
1 parent e7b14ba commit 005a713
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
15 changes: 8 additions & 7 deletions bcs-services/bcs-bscp/cmd/api-server/service/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ func UserInfoHandler(w http.ResponseWriter, r *http.Request) {
render.Render(w, r, rest.OKRender(user))
}

// BizFeatureFlags feature flags for business
type BizFeatureFlags struct {
// BizViewFlag 是否开启业务体验
BizView bool `json:"BIZ_VIEW"`
// FeatureFlags feature flags
type FeatureFlags struct {
// BizView 是否开启业务体验
BizView bool `json:"BIZ_VIEW"`
// ResourceLimit 业务资源限制
ResourceLimit cc.ResourceLimit `json:"RESOURCE_LIMIT"`
}

// FeatureFlagsHandler 特性开关接口
func FeatureFlagsHandler(w http.ResponseWriter, r *http.Request) {
featureFlags := BizFeatureFlags{}
featureFlags := FeatureFlags{}

biz := r.URL.Query().Get("biz")
// set biz_view feature flag
Expand All @@ -90,8 +91,8 @@ func FeatureFlagsHandler(w http.ResponseWriter, r *http.Request) {
featureFlags.ResourceLimit = resourceLimitConf.Default

if resource, ok := resourceLimitConf.Spec[biz]; ok {
if resource.MaxConfigItemSize != 0 {
featureFlags.ResourceLimit.MaxConfigItemSize = resource.MaxConfigItemSize
if resource.MaxFileSize != 0 {
featureFlags.ResourceLimit.MaxFileSize = resource.MaxFileSize
}
// TODO:其他资源限制
}
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/pkg/cc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type FeatureResourceLimit struct {
// ResourceLimit 资源限制配置项
type ResourceLimit struct {
// 配置文件大小上限,单位 Mb
MaxConfigItemSize uint `json:"maxConfigItemSize" yaml:"maxConfigItemSize"`
MaxFileSize uint `json:"maxFileSize" yaml:"maxFileSize"`
}

// Service defines Setting related runtime.
Expand Down
6 changes: 0 additions & 6 deletions bcs-services/bcs-bscp/pkg/rest/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@ func BadRequest(err error) render.Renderer {
return &ErrorResponse{Error: payload, HTTPStatusCode: http.StatusBadRequest}
}

// InternalError rest 通用内部错误
func InternalError(err error) render.Renderer {
payload := &ErrorPayload{Code: "INTERNAL", Message: err.Error()}
return &ErrorResponse{Error: payload, HTTPStatusCode: http.StatusInternalServerError}
}

// GRPCErr GRPC-Gateway 错误
func GRPCErr(err error) *ErrorResponse {
s := status.Convert(err)
Expand Down

0 comments on commit 005a713

Please sign in to comment.