Copilot commented on code in PR #1353:
URL: https://github.com/apache/dubbo-admin/pull/1353#discussion_r2504192145


##########
pkg/console/service/application.go:
##########
@@ -267,3 +273,400 @@ func buildApplicationSearchResp(appResource 
*meshresource.ApplicationResource, m
                RegistryClusters: []string{mesh},
        }
 }
+
+func isAppAccessLogConfig(conf *meshproto.OverrideConfig, appName string) bool 
{
+       if conf.Side != consts.SideProvider ||
+               conf.Parameters == nil ||
+               conf.Match == nil ||
+               conf.Match.Application == nil ||
+               conf.Match.Application.Oneof == nil ||
+               len(conf.Match.Application.Oneof) != 1 ||
+               conf.Match.Application.Oneof[0].Exact != appName {
+               return false
+       } else if _, ok := conf.Parameters[`accesslog`]; !ok {
+               return false
+       }
+       return true
+}
+
+func UpInsertAppAccessLog(ctx consolectx.Context, appName string, 
openAccessLog bool, mesh string) error {
+       // check app exists
+       data, err := GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
+       if err != nil {
+               return err
+       }
+       if data == nil {
+               return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s is not exists", appName))
+       }
+       // check app configurator exists
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               return err
+       }
+       // if not exists, create one configurator with access log enable
+       if res == nil {
+               return insertConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+       }
+       // else we update the configurator
+       return updateConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+}
+
+func insertConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       // configurator is nil, accessLog is already closed
+       if !openAccessLog {
+               return nil
+       }
+       res = 
meshresource.NewDynamicConfigResourceWithAttributes(appConfiguratorName, mesh)
+       res.Spec = &meshproto.DynamicConfig{
+               Key:           appName,
+               Scope:         consts.ScopeApplication,
+               ConfigVersion: consts.ConfiguratorVersionV3,
+               Enabled:       true,
+               Configs:       make([]*meshproto.OverrideConfig, 0),
+       }
+       res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       err := CreateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("create configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), 
openAccessLog, err)
+               return err
+       }
+       return nil
+}
+
+func updateConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       var accessLogConfig *meshproto.OverrideConfig
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isAppAccessLogConfig(conf, appName) {
+                       accessLogConfig = conf
+                       return true
+               }
+               return false
+       })
+       // access log config not found
+       if accessLogConfig == nil {
+               // access log is need to be closed and already closed
+               if !openAccessLog {
+                       return nil
+               }
+               // insert a access log enabled config
+               res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       } else {
+               // access log config found and status is the same as needed
+               if accessLogConfig.Enabled == openAccessLog {
+                       return nil
+               }
+               // update the access log enabled status as needed
+               accessLogConfig.Enabled = openAccessLog
+       }
+       err := UpdateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("update configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",

Review Comment:
   Grammar error in log message: "when open accesslog" should be "when opening 
access log" or "while updating access log".
   ```suggestion
                logger.Errorf("update configurator failed when opening access 
log, resourceKey: %s, openAccessLog: %t, err: %s",
   ```



##########
pkg/console/service/application.go:
##########
@@ -267,3 +273,400 @@ func buildApplicationSearchResp(appResource 
*meshresource.ApplicationResource, m
                RegistryClusters: []string{mesh},
        }
 }
+
+func isAppAccessLogConfig(conf *meshproto.OverrideConfig, appName string) bool 
{
+       if conf.Side != consts.SideProvider ||
+               conf.Parameters == nil ||
+               conf.Match == nil ||
+               conf.Match.Application == nil ||
+               conf.Match.Application.Oneof == nil ||
+               len(conf.Match.Application.Oneof) != 1 ||
+               conf.Match.Application.Oneof[0].Exact != appName {
+               return false
+       } else if _, ok := conf.Parameters[`accesslog`]; !ok {
+               return false
+       }
+       return true
+}
+
+func UpInsertAppAccessLog(ctx consolectx.Context, appName string, 
openAccessLog bool, mesh string) error {
+       // check app exists
+       data, err := GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
+       if err != nil {
+               return err
+       }
+       if data == nil {
+               return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s is not exists", appName))
+       }
+       // check app configurator exists
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               return err
+       }
+       // if not exists, create one configurator with access log enable
+       if res == nil {
+               return insertConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+       }
+       // else we update the configurator
+       return updateConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+}
+
+func insertConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       // configurator is nil, accessLog is already closed
+       if !openAccessLog {
+               return nil
+       }
+       res = 
meshresource.NewDynamicConfigResourceWithAttributes(appConfiguratorName, mesh)
+       res.Spec = &meshproto.DynamicConfig{
+               Key:           appName,
+               Scope:         consts.ScopeApplication,
+               ConfigVersion: consts.ConfiguratorVersionV3,
+               Enabled:       true,
+               Configs:       make([]*meshproto.OverrideConfig, 0),
+       }
+       res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       err := CreateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("create configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",

Review Comment:
   Grammar error in log message: "when open accesslog" should be "when opening 
access log" or "while updating access log".



##########
pkg/console/service/application.go:
##########
@@ -267,3 +273,400 @@ func buildApplicationSearchResp(appResource 
*meshresource.ApplicationResource, m
                RegistryClusters: []string{mesh},
        }
 }
+
+func isAppAccessLogConfig(conf *meshproto.OverrideConfig, appName string) bool 
{
+       if conf.Side != consts.SideProvider ||
+               conf.Parameters == nil ||
+               conf.Match == nil ||
+               conf.Match.Application == nil ||
+               conf.Match.Application.Oneof == nil ||
+               len(conf.Match.Application.Oneof) != 1 ||
+               conf.Match.Application.Oneof[0].Exact != appName {
+               return false
+       } else if _, ok := conf.Parameters[`accesslog`]; !ok {
+               return false
+       }
+       return true
+}
+
+func UpInsertAppAccessLog(ctx consolectx.Context, appName string, 
openAccessLog bool, mesh string) error {
+       // check app exists
+       data, err := GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
+       if err != nil {
+               return err
+       }
+       if data == nil {
+               return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s is not exists", appName))
+       }
+       // check app configurator exists
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               return err
+       }
+       // if not exists, create one configurator with access log enable
+       if res == nil {
+               return insertConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+       }
+       // else we update the configurator
+       return updateConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+}
+
+func insertConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       // configurator is nil, accessLog is already closed
+       if !openAccessLog {
+               return nil
+       }
+       res = 
meshresource.NewDynamicConfigResourceWithAttributes(appConfiguratorName, mesh)
+       res.Spec = &meshproto.DynamicConfig{
+               Key:           appName,
+               Scope:         consts.ScopeApplication,
+               ConfigVersion: consts.ConfiguratorVersionV3,
+               Enabled:       true,
+               Configs:       make([]*meshproto.OverrideConfig, 0),
+       }
+       res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       err := CreateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("create configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), 
openAccessLog, err)
+               return err
+       }
+       return nil
+}
+
+func updateConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       var accessLogConfig *meshproto.OverrideConfig
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isAppAccessLogConfig(conf, appName) {
+                       accessLogConfig = conf
+                       return true
+               }
+               return false
+       })
+       // access log config not found
+       if accessLogConfig == nil {
+               // access log is need to be closed and already closed
+               if !openAccessLog {
+                       return nil
+               }
+               // insert a access log enabled config
+               res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       } else {
+               // access log config found and status is the same as needed
+               if accessLogConfig.Enabled == openAccessLog {
+                       return nil
+               }
+               // update the access log enabled status as needed
+               accessLogConfig.Enabled = openAccessLog
+       }
+       err := UpdateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("update configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), 
openAccessLog, err)
+               return err
+       }
+       return nil
+}
+
+func newAccessLogEnabledConfig(appName string) *meshproto.OverrideConfig {
+       return &meshproto.OverrideConfig{
+               Side:       consts.SideProvider,
+               Parameters: map[string]string{`accesslog`: `true`},
+               Enabled:    true,
+               Match: &meshproto.ConditionMatch{
+                       Application: &meshproto.ListStringMatch{
+                               Oneof: []*meshproto.StringMatch{
+                                       {
+                                               Exact: appName,
+                                       },
+                               }}},
+               XGenerateByCp: true,
+       }
+}
+
+func GetAppAccessLog(ctx consolectx.Context, appName string, mesh string) 
(*model.AppAccessLogConfigResp, error) {
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       resp := &model.AppAccessLogConfigResp{
+               AccessLog: false,
+       }
+       if err != nil {
+               logger.Errorf("get configurator failed when get app accesslog, 
resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return nil, err
+       }
+       if res == nil {
+               return resp, nil
+       }
+       var appAccessLogConfig *meshproto.OverrideConfig
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isAppAccessLogConfig(conf, appName) {
+                       appAccessLogConfig = conf
+                       return true
+               }
+               return false
+       })
+       if appAccessLogConfig == nil {
+               return resp, nil
+       }
+       resp.AccessLog = appAccessLogConfig.Enabled
+       return resp, nil
+}
+
+func GetAppFlowWeight(ctx consolectx.Context, appName string, mesh string) 
(*model.AppFlowWeightConfigResp, error) {
+       resp := &model.AppFlowWeightConfigResp{
+               FlowWeightSets: []model.FlowWeightSet{},
+       }
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               logger.Errorf("get configurator failed when get app flow 
weight, resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return nil, err
+       }
+       if res == nil {
+               return resp, nil
+       }
+
+       weight := 0
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isFlowWeightConfig(conf) {
+                       weight, err = strconv.Atoi(conf.Parameters[`weight`])
+                       if err != nil {
+                               logger.Error("parse weight failed", err)
+                               return true

Review Comment:
   Error during weight parsing is logged but not returned to the caller. If 
`strconv.Atoi` fails, the function stops iterating (returns true) but 
`GetAppFlowWeight` still returns `resp, nil`, potentially returning incomplete 
data without indicating an error occurred. Consider returning the error or at 
least ensuring the response indicates the parsing failure.



##########
pkg/console/service/application.go:
##########
@@ -267,3 +273,400 @@ func buildApplicationSearchResp(appResource 
*meshresource.ApplicationResource, m
                RegistryClusters: []string{mesh},
        }
 }
+
+func isAppAccessLogConfig(conf *meshproto.OverrideConfig, appName string) bool 
{
+       if conf.Side != consts.SideProvider ||
+               conf.Parameters == nil ||
+               conf.Match == nil ||
+               conf.Match.Application == nil ||
+               conf.Match.Application.Oneof == nil ||
+               len(conf.Match.Application.Oneof) != 1 ||
+               conf.Match.Application.Oneof[0].Exact != appName {
+               return false
+       } else if _, ok := conf.Parameters[`accesslog`]; !ok {
+               return false
+       }
+       return true
+}
+
+func UpInsertAppAccessLog(ctx consolectx.Context, appName string, 
openAccessLog bool, mesh string) error {
+       // check app exists
+       data, err := GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
+       if err != nil {
+               return err
+       }
+       if data == nil {
+               return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s is not exists", appName))

Review Comment:
   Grammar error in error message: "is not exists" should be "does not exist".
   ```suggestion
                return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s does not exist", appName))
   ```



##########
pkg/console/service/application.go:
##########
@@ -267,3 +273,400 @@ func buildApplicationSearchResp(appResource 
*meshresource.ApplicationResource, m
                RegistryClusters: []string{mesh},
        }
 }
+
+func isAppAccessLogConfig(conf *meshproto.OverrideConfig, appName string) bool 
{
+       if conf.Side != consts.SideProvider ||
+               conf.Parameters == nil ||
+               conf.Match == nil ||
+               conf.Match.Application == nil ||
+               conf.Match.Application.Oneof == nil ||
+               len(conf.Match.Application.Oneof) != 1 ||
+               conf.Match.Application.Oneof[0].Exact != appName {
+               return false
+       } else if _, ok := conf.Parameters[`accesslog`]; !ok {
+               return false
+       }
+       return true
+}
+
+func UpInsertAppAccessLog(ctx consolectx.Context, appName string, 
openAccessLog bool, mesh string) error {
+       // check app exists
+       data, err := GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
+       if err != nil {
+               return err
+       }
+       if data == nil {
+               return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s is not exists", appName))
+       }
+       // check app configurator exists
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               return err
+       }
+       // if not exists, create one configurator with access log enable
+       if res == nil {
+               return insertConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+       }
+       // else we update the configurator
+       return updateConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+}
+
+func insertConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       // configurator is nil, accessLog is already closed
+       if !openAccessLog {
+               return nil
+       }
+       res = 
meshresource.NewDynamicConfigResourceWithAttributes(appConfiguratorName, mesh)
+       res.Spec = &meshproto.DynamicConfig{
+               Key:           appName,
+               Scope:         consts.ScopeApplication,
+               ConfigVersion: consts.ConfiguratorVersionV3,
+               Enabled:       true,
+               Configs:       make([]*meshproto.OverrideConfig, 0),
+       }
+       res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       err := CreateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("create configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), 
openAccessLog, err)
+               return err
+       }
+       return nil
+}
+
+func updateConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       var accessLogConfig *meshproto.OverrideConfig
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isAppAccessLogConfig(conf, appName) {
+                       accessLogConfig = conf
+                       return true
+               }
+               return false
+       })
+       // access log config not found
+       if accessLogConfig == nil {
+               // access log is need to be closed and already closed
+               if !openAccessLog {
+                       return nil
+               }
+               // insert a access log enabled config
+               res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       } else {
+               // access log config found and status is the same as needed
+               if accessLogConfig.Enabled == openAccessLog {
+                       return nil
+               }
+               // update the access log enabled status as needed
+               accessLogConfig.Enabled = openAccessLog
+       }
+       err := UpdateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("update configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), 
openAccessLog, err)
+               return err
+       }
+       return nil
+}
+
+func newAccessLogEnabledConfig(appName string) *meshproto.OverrideConfig {
+       return &meshproto.OverrideConfig{
+               Side:       consts.SideProvider,
+               Parameters: map[string]string{`accesslog`: `true`},
+               Enabled:    true,
+               Match: &meshproto.ConditionMatch{
+                       Application: &meshproto.ListStringMatch{
+                               Oneof: []*meshproto.StringMatch{
+                                       {
+                                               Exact: appName,
+                                       },
+                               }}},
+               XGenerateByCp: true,
+       }
+}
+
+func GetAppAccessLog(ctx consolectx.Context, appName string, mesh string) 
(*model.AppAccessLogConfigResp, error) {
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       resp := &model.AppAccessLogConfigResp{
+               AccessLog: false,
+       }
+       if err != nil {
+               logger.Errorf("get configurator failed when get app accesslog, 
resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return nil, err
+       }
+       if res == nil {
+               return resp, nil
+       }
+       var appAccessLogConfig *meshproto.OverrideConfig
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isAppAccessLogConfig(conf, appName) {
+                       appAccessLogConfig = conf
+                       return true
+               }
+               return false
+       })
+       if appAccessLogConfig == nil {
+               return resp, nil
+       }
+       resp.AccessLog = appAccessLogConfig.Enabled
+       return resp, nil
+}
+
+func GetAppFlowWeight(ctx consolectx.Context, appName string, mesh string) 
(*model.AppFlowWeightConfigResp, error) {
+       resp := &model.AppFlowWeightConfigResp{
+               FlowWeightSets: []model.FlowWeightSet{},
+       }
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               logger.Errorf("get configurator failed when get app flow 
weight, resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return nil, err
+       }
+       if res == nil {
+               return resp, nil
+       }
+
+       weight := 0
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isFlowWeightConfig(conf) {
+                       weight, err = strconv.Atoi(conf.Parameters[`weight`])
+                       if err != nil {
+                               logger.Error("parse weight failed", err)
+                               return true
+                       }
+                       scope := make([]model.ParamMatch, 0, 
len(conf.Match.Param))
+                       for _, param := range conf.Match.Param {
+                               scope = append(scope, model.ParamMatch{
+                                       Key:   &param.Key,
+                                       Value: 
model.StringMatchToModelStringMatch(param.Value),
+                               })
+                       }
+
+                       resp.FlowWeightSets = append(resp.FlowWeightSets, 
model.FlowWeightSet{
+                               Weight: int32(weight),
+                               Scope:  scope,
+                       })
+               }
+               return false
+       })
+       return resp, nil
+}
+
+func isFlowWeightConfig(conf *meshproto.OverrideConfig) bool {
+       if conf.Side != consts.SideProvider ||
+               conf.Parameters == nil ||
+               conf.Match == nil ||
+               conf.Match.Param == nil {
+               return false
+       } else if _, ok := conf.Parameters[`weight`]; !ok {
+               return false
+       }
+       return true
+}
+
+func UpInsertAppFlowWeightConfig(ctx consolectx.Context, appName string, mesh 
string, flowWeightSets []model.FlowWeightSet) error {
+       // check app exists
+       data, err := GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
+       if err != nil {
+               return err
+       }
+       if data == nil {
+               return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s is not exists", appName))
+       }
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               logger.Errorf("get configurator failed when update app flow 
weight, resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return err
+       }
+       // configurator not exists, insert a new one
+       if res == nil {
+               return insertConfiguratorWithFlowWeight(ctx, flowWeightSets, 
appName, appConfiguratorName, mesh)
+       }
+       // configurator exists, update it
+
+       // remove old flow weight config
+       res.Spec.RangeConfigsToRemove(func(conf *meshproto.OverrideConfig) 
(IsRemove bool) {
+               return isFlowWeightConfig(conf)
+       })
+
+       // add new flow weight config
+       flowWeightConfigs := slice.Map(flowWeightSets, func(index int, set 
model.FlowWeightSet) *meshproto.OverrideConfig {
+               return fromFlowWeightSet(set)
+       })
+       res.Spec.Configs = slice.Union(res.Spec.Configs, flowWeightConfigs)
+
+       err = UpdateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("update configurator failed with app flow weight, 
resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return err
+       }
+       return nil
+}
+
+func insertConfiguratorWithFlowWeight(
+       ctx consolectx.Context,
+       flowWeightSets []model.FlowWeightSet,
+       appName, appConfiguratorName, mesh string) error {
+       res := 
meshresource.NewDynamicConfigResourceWithAttributes(appConfiguratorName, mesh)
+       res.Spec = &meshproto.DynamicConfig{
+               Key:           appName,
+               Scope:         consts.ScopeApplication,
+               ConfigVersion: consts.ConfiguratorVersionV3,
+               Enabled:       true,
+       }
+       flowWeightConfigs := slice.Map(flowWeightSets, func(index int, set 
model.FlowWeightSet) *meshproto.OverrideConfig {
+               return fromFlowWeightSet(set)
+       })
+       res.Spec.Configs = flowWeightConfigs
+       err := CreateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("insert configurator failed with app flow weight, 
resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return err
+       }
+       return nil
+}
+
+func fromFlowWeightSet(set model.FlowWeightSet) *meshproto.OverrideConfig {
+       paramMatch := make([]*meshproto.ParamMatch, 0, len(set.Scope))
+       for _, match := range set.Scope {
+               paramMatch = append(paramMatch, &meshproto.ParamMatch{
+                       Key:   *match.Key,
+                       Value: model.ModelStringMatchToStringMatch(match.Value),
+               })
+       }
+       return &meshproto.OverrideConfig{
+               Side:       consts.SideProvider,
+               Parameters: map[string]string{`weight`: 
strconv.Itoa(int(set.Weight))},
+               Match: &meshproto.ConditionMatch{
+                       Param: paramMatch,
+               },
+               XGenerateByCp: true,
+       }
+}
+func GetGrayConfig(ctx consolectx.Context, appName string, mesh string) 
(*model.AppGrayConfigResp, error) {
+       resp := &model.AppGrayConfigResp{}
+       serviceTagRuleName := appName + consts.TagRuleSuffix
+       res, err := GetTagRule(ctx, serviceTagRuleName, mesh)
+       if err != nil {
+               logger.Errorf("get tag rule failed when get gray config, 
resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return nil, err
+       }
+       resp.GraySets = make([]model.GraySet, 0, len(res.Spec.Tags))
+
+       res.Spec.RangeTags(func(tag *meshproto.Tag) (isStop bool) {
+               if isGrayTag(tag) {
+                       scope := make([]model.ParamMatch, 0, len(tag.Match))
+                       for _, paramMatch := range tag.Match {
+                               scope = append(scope, model.ParamMatch{
+                                       Key:   &paramMatch.Key,
+                                       Value: 
model.StringMatchToModelStringMatch(paramMatch.Value),
+                               })
+                       }
+                       resp.GraySets = append(resp.GraySets, model.GraySet{
+                               EnvName: tag.Name,
+                               Scope:   scope,
+                       })
+               }
+               return false
+       })
+       return resp, nil
+}
+
+func isGrayTag(tag *meshproto.Tag) bool {
+       if tag.Name == "" || tag.Addresses != nil || len(tag.Addresses) != 0 {

Review Comment:
   The condition logic is inverted here. The function `isGrayTag` should return 
true for valid gray tags, but this condition returns false when `tag.Addresses` 
is not nil OR when length is not 0. This means if `tag.Addresses` is nil but 
has length 0, it would still check the length. The correct logic should be: `if 
tag.Name == "" || (tag.Addresses != nil && len(tag.Addresses) != 0)` or simply 
`if tag.Name == "" || len(tag.Addresses) != 0`.
   ```suggestion
        if tag.Name == "" || len(tag.Addresses) != 0 {
   ```



##########
pkg/console/handler/auth.go:
##########
@@ -59,6 +61,6 @@ func Logout(_ consolectx.Context) gin.HandlerFunc {
                if err != nil {
                        c.JSON(http.StatusInternalServerError, 
model.NewErrorResp(err.Error()))

Review Comment:
   Inconsistent error handling in the `Logout` function. Line 62 uses the 
deprecated `NewErrorResp` while the rest of the codebase has been refactored to 
use `NewBizErrorResp`. This should be updated to: 
`c.JSON(http.StatusInternalServerError, 
model.NewBizErrorResp(bizerror.NewBizError(bizerror.SessionError, 
err.Error())))`.
   ```suggestion
                        c.JSON(http.StatusInternalServerError, 
model.NewBizErrorResp(bizerror.NewBizError(bizerror.SessionError, err.Error())))
   ```



##########
pkg/console/service/application.go:
##########
@@ -267,3 +273,400 @@ func buildApplicationSearchResp(appResource 
*meshresource.ApplicationResource, m
                RegistryClusters: []string{mesh},
        }
 }
+
+func isAppAccessLogConfig(conf *meshproto.OverrideConfig, appName string) bool 
{
+       if conf.Side != consts.SideProvider ||
+               conf.Parameters == nil ||
+               conf.Match == nil ||
+               conf.Match.Application == nil ||
+               conf.Match.Application.Oneof == nil ||
+               len(conf.Match.Application.Oneof) != 1 ||
+               conf.Match.Application.Oneof[0].Exact != appName {
+               return false
+       } else if _, ok := conf.Parameters[`accesslog`]; !ok {
+               return false
+       }
+       return true
+}
+
+func UpInsertAppAccessLog(ctx consolectx.Context, appName string, 
openAccessLog bool, mesh string) error {
+       // check app exists
+       data, err := GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
+       if err != nil {
+               return err
+       }
+       if data == nil {
+               return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s is not exists", appName))
+       }
+       // check app configurator exists
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               return err
+       }
+       // if not exists, create one configurator with access log enable
+       if res == nil {
+               return insertConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+       }
+       // else we update the configurator
+       return updateConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+}
+
+func insertConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       // configurator is nil, accessLog is already closed
+       if !openAccessLog {
+               return nil
+       }
+       res = 
meshresource.NewDynamicConfigResourceWithAttributes(appConfiguratorName, mesh)
+       res.Spec = &meshproto.DynamicConfig{
+               Key:           appName,
+               Scope:         consts.ScopeApplication,
+               ConfigVersion: consts.ConfiguratorVersionV3,
+               Enabled:       true,
+               Configs:       make([]*meshproto.OverrideConfig, 0),
+       }
+       res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       err := CreateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("create configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), 
openAccessLog, err)
+               return err
+       }
+       return nil
+}
+
+func updateConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       var accessLogConfig *meshproto.OverrideConfig
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isAppAccessLogConfig(conf, appName) {
+                       accessLogConfig = conf
+                       return true
+               }
+               return false
+       })
+       // access log config not found
+       if accessLogConfig == nil {
+               // access log is need to be closed and already closed

Review Comment:
   Grammar error in comment: "is need to be closed" should be "needs to be 
closed".
   ```suggestion
                // access log needs to be closed and already closed
   ```



##########
pkg/console/handler/application.go:
##########
@@ -88,231 +85,90 @@ func ApplicationSearch(ctx consolectx.Context) 
gin.HandlerFunc {
        return func(c *gin.Context) {
                req := model.NewApplicationSearchReq()
                if err := c.ShouldBindQuery(req); err != nil {
-                       c.JSON(http.StatusBadRequest, 
model.NewErrorResp(err.Error()))
+                       util.HandleArgumentError(c, err)
                        return
                }
 
                resp, err := service.SearchApplications(ctx, req)
                if err != nil {
-                       c.JSON(http.StatusBadRequest, 
model.NewErrorResp(err.Error()))
+                       util.HandleServiceError(c, err)
                        return
                }
                c.JSON(http.StatusOK, model.NewSuccessResp(resp))
        }
 }
 
-func isAppOperatorLogOpened(conf *meshproto.OverrideConfig, appName string) 
bool {
-       if conf.Side != consts.SideProvider ||
-               conf.Parameters == nil ||
-               conf.Match == nil ||
-               conf.Match.Application == nil ||
-               conf.Match.Application.Oneof == nil ||
-               len(conf.Match.Application.Oneof) != 1 ||
-               conf.Match.Application.Oneof[0].Exact != appName {
-               return false
-       } else if val, ok := conf.Parameters[`accesslog`]; !ok || val != `true` 
{
-               return false
-       }
-       return true
-}
-
-func ApplicationConfigOperatorLogPut(ctx consolectx.Context) gin.HandlerFunc {
+func ApplicationConfigAccessLogPut(ctx consolectx.Context) gin.HandlerFunc {
        return func(c *gin.Context) {
                var (
                        appName         string
                        operatorLogOpen bool
-                       isNotExist      = false
                        mesh            string
                )
                appName = c.Query("appName")
+               if strutil.IsBlank(appName) {
+                       util.HandleArgumentError(c, errors.New("appName is 
required"))
+                       return
+               }
                mesh = c.Query("mesh")
-               operatorLogOpen, err := 
strconv.ParseBool(c.Query("operatorLog"))
-               if err != nil {
-                       c.JSON(http.StatusBadRequest, 
model.NewErrorResp(err.Error()))
+               if strutil.IsBlank(mesh) {
+                       util.HandleArgumentError(c, errors.New("mesh is 
required"))
                        return
                }
-               appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
-               res, err := service.GetConfigurator(ctx, appConfiguratorName, 
mesh)
+               operatorLogOpen, err := 
strconv.ParseBool(c.Query("operatorLog"))
                if err != nil {
-                       if corestore.IsResourceNotFound(err) {
-                               // check app exists
-                               data, err := service.GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
-                               if err != nil || data == nil {
-                                       c.JSON(http.StatusNotFound, 
model.NewErrorResp(err.Error()))
-                                       return
-                               }
-                               res = 
meshresource.NewDynamicConfigResourceWithAttributes(appConfiguratorName, mesh)
-                               res.Spec = &meshproto.DynamicConfig{
-                                       Key:           appName,
-                                       Scope:         consts.ScopeApplication,
-                                       ConfigVersion: 
consts.ConfiguratorVersionV3,
-                                       Enabled:       true,
-                                       Configs:       
make([]*meshproto.OverrideConfig, 0),
-                               }
-                               isNotExist = true
-                       } else {
-                               c.JSON(http.StatusInternalServerError, 
model.NewErrorResp(err.Error()))
-                               return
-                       }
-               }
-               // append or remove
-               if operatorLogOpen {
-                       // check is already exist
-                       alreadyExist := false
-                       res.Spec.RangeConfig(func(conf 
*meshproto.OverrideConfig) (isStop bool) {
-                               alreadyExist = isAppOperatorLogOpened(conf, 
appName)
-                               return alreadyExist
-                       })
-                       if alreadyExist {
-                               c.JSON(http.StatusOK, model.NewSuccessResp(nil))
-                               return
-                       }
-                       if res.Spec.Configs == nil {
-                               res.Spec.Configs = 
make([]*meshproto.OverrideConfig, 0)
-                       }
-                       res.Spec.Configs = append(res.Spec.Configs, 
&meshproto.OverrideConfig{
-                               Side:       consts.SideProvider,
-                               Parameters: map[string]string{`accesslog`: 
`true`},
-                               Enabled:    true,
-                               Match: &meshproto.ConditionMatch{
-                                       Application: &meshproto.ListStringMatch{
-                                               Oneof: []*meshproto.StringMatch{
-                                                       {
-                                                               Exact: appName,
-                                                       },
-                                               }}},
-                               XGenerateByCp: true,
-                       })
-               } else {
-                       res.Spec.RangeConfigsToRemove(func(conf 
*meshproto.OverrideConfig) (IsRemove bool) {
-                               if conf == nil {
-                                       return true
-                               }
-                               return isAppOperatorLogOpened(conf, appName)
-                       })
+                       util.HandleArgumentError(c, err)
+                       return
                }
-               // restore
-               if isNotExist {
-                       err = service.CreateConfigurator(ctx, appName, res)
-                       if err != nil {
-                               c.JSON(http.StatusInternalServerError, 
model.NewErrorResp(err.Error()))
-                               return
-                       }
-               } else {
-                       err = service.UpdateConfigurator(ctx, appName, res)
-                       if err != nil {
-                               c.JSON(http.StatusInternalServerError, 
model.NewErrorResp(err.Error()))
-                               return
-                       }
+               if err := service.UpInsertAppAccessLog(ctx, appName, 
operatorLogOpen, mesh); err != nil {
+                       util.HandleServiceError(c, err)
+                       return
                }
-               c.JSON(http.StatusOK, model.NewSuccessResp(nil))
+               c.JSON(http.StatusOK, model.NewSuccessResp(true))
        }
 }
 
-func ApplicationConfigOperatorLogGet(ctx consolectx.Context) gin.HandlerFunc {
+func ApplicationConfigAccessLogGet(ctx consolectx.Context) gin.HandlerFunc {
        return func(c *gin.Context) {
                appName := c.Query("appName")
-               if appName == "" {
-                       c.JSON(http.StatusBadRequest, 
model.NewErrorResp("appName is required"))
+               if strutil.IsBlank(appName) {
+                       util.HandleArgumentError(c, errors.New("appName is 
required"))
                        return
                }
                mesh := c.Query("mesh")
                if strutil.IsBlank(mesh) {
-                       c.JSON(http.StatusBadRequest, model.NewErrorResp("mesh 
is required"))
+                       util.HandleArgumentError(c, errors.New("mesh is 
required"))
                        return
                }
-               appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
-               res, err := service.GetConfigurator(ctx, appConfiguratorName, 
mesh)
+               resp, err := service.GetAppAccessLog(ctx, appName, mesh)
                if err != nil {
-                       if corestore.IsResourceNotFound(err) {
-                               c.JSON(http.StatusOK, 
model.NewSuccessResp(map[string]interface{}{"operatorLog": false}))
-                               return
-                       }
-                       c.JSON(http.StatusNotFound, 
model.NewErrorResp(err.Error()))
-                       return
+                       util.HandleServiceError(c, err)

Review Comment:
   Missing return statement after error handling. If `service.GetAppAccessLog` 
returns an error, the function should return early instead of continuing to 
line 147 where it would return a success response with a nil `resp`.
   ```suggestion
                        util.HandleServiceError(c, err)
                        return
   ```



##########
pkg/console/handler/auth.go:
##########
@@ -42,11 +43,12 @@ func Login(ctx consolectx.Context) gin.HandlerFunc {
                        })
                        err := session.Save()
                        if err != nil {
-                               c.JSON(http.StatusInternalServerError, 
model.NewErrorResp(err.Error()))
+                               sessionErr := 
bizerror.NewBizError(bizerror.SessionError, err.Error())
+                               c.JSON(http.StatusInternalServerError, 
model.NewBizErrorResp(sessionErr))

Review Comment:
   Missing return statement after handling session save error. If saving the 
session fails at line 44-47, the function continues to line 49 and sends a 
success response, resulting in duplicate responses being sent to the client.
   ```suggestion
                                c.JSON(http.StatusInternalServerError, 
model.NewBizErrorResp(sessionErr))
                                return
   ```



##########
pkg/console/component.go:
##########
@@ -130,7 +131,8 @@ func (c *consoleWebServer) authMiddleware() gin.HandlerFunc 
{
                session := sessions.Default(c)
                user := session.Get("user")
                if user == nil {
-                       c.JSON(http.StatusUnauthorized, 
model.NewUnauthorizedResp())
+                       err := 
bizerror.NewAssertionError(bizerror.UnknownError, "please login")

Review Comment:
   `NewAssertionError` is being called with two `ErrorCode` values instead of 
the expected and actual types for assertion. The function signature expects 
`(expected, actual interface{})` but receives `(bizerror.UnknownError, "please 
login")`. This should use `NewBizError(bizerror.Unauthorized, "please login")` 
or `NewUnauthorizedError()` instead.
   ```suggestion
                        err := bizerror.NewBizError(bizerror.Unauthorized, 
"please login")
   ```



##########
pkg/console/handler/application.go:
##########
@@ -325,135 +181,42 @@ func ApplicationConfigFlowWeightPUT(ctx 
consolectx.Context) gin.HandlerFunc {
                appName = c.Query("appName")
                mesh = c.Query("mesh")
                if strutil.IsBlank(appName) {
-                       c.JSON(http.StatusBadRequest, 
model.NewErrorResp("application name is required"))
+                       util.HandleArgumentError(c, errors.New("appName is 
required"))

Review Comment:
   Missing return statement after handling the validation error. If `appName` 
is blank, the function will continue executing despite calling 
`HandleArgumentError`, leading to potential issues with the subsequent logic.
   ```suggestion
                        util.HandleArgumentError(c, errors.New("appName is 
required"))
                        return
   ```



##########
pkg/console/handler/auth.go:
##########
@@ -59,6 +61,6 @@ func Logout(_ consolectx.Context) gin.HandlerFunc {
                if err != nil {
                        c.JSON(http.StatusInternalServerError, 
model.NewErrorResp(err.Error()))

Review Comment:
   Missing return statement after error handling. If saving the session fails 
at line 60-62, the function continues to line 64 and sends a success response, 
resulting in duplicate responses being sent to the client.
   ```suggestion
                        c.JSON(http.StatusInternalServerError, 
model.NewErrorResp(err.Error()))
                        return
   ```



##########
pkg/console/service/application.go:
##########
@@ -267,3 +273,400 @@ func buildApplicationSearchResp(appResource 
*meshresource.ApplicationResource, m
                RegistryClusters: []string{mesh},
        }
 }
+
+func isAppAccessLogConfig(conf *meshproto.OverrideConfig, appName string) bool 
{
+       if conf.Side != consts.SideProvider ||
+               conf.Parameters == nil ||
+               conf.Match == nil ||
+               conf.Match.Application == nil ||
+               conf.Match.Application.Oneof == nil ||
+               len(conf.Match.Application.Oneof) != 1 ||
+               conf.Match.Application.Oneof[0].Exact != appName {
+               return false
+       } else if _, ok := conf.Parameters[`accesslog`]; !ok {
+               return false
+       }
+       return true
+}
+
+func UpInsertAppAccessLog(ctx consolectx.Context, appName string, 
openAccessLog bool, mesh string) error {
+       // check app exists
+       data, err := GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
+       if err != nil {
+               return err
+       }
+       if data == nil {
+               return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s is not exists", appName))
+       }
+       // check app configurator exists
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               return err
+       }
+       // if not exists, create one configurator with access log enable
+       if res == nil {
+               return insertConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+       }
+       // else we update the configurator
+       return updateConfiguratorWithAccessLog(ctx, res, openAccessLog, 
appConfiguratorName, appName, mesh)
+}
+
+func insertConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       // configurator is nil, accessLog is already closed
+       if !openAccessLog {
+               return nil
+       }
+       res = 
meshresource.NewDynamicConfigResourceWithAttributes(appConfiguratorName, mesh)
+       res.Spec = &meshproto.DynamicConfig{
+               Key:           appName,
+               Scope:         consts.ScopeApplication,
+               ConfigVersion: consts.ConfiguratorVersionV3,
+               Enabled:       true,
+               Configs:       make([]*meshproto.OverrideConfig, 0),
+       }
+       res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       err := CreateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("create configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), 
openAccessLog, err)
+               return err
+       }
+       return nil
+}
+
+func updateConfiguratorWithAccessLog(ctx consolectx.Context, res 
*meshresource.DynamicConfigResource, openAccessLog bool,
+       appConfiguratorName, appName, mesh string) error {
+       var accessLogConfig *meshproto.OverrideConfig
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isAppAccessLogConfig(conf, appName) {
+                       accessLogConfig = conf
+                       return true
+               }
+               return false
+       })
+       // access log config not found
+       if accessLogConfig == nil {
+               // access log is need to be closed and already closed
+               if !openAccessLog {
+                       return nil
+               }
+               // insert a access log enabled config
+               res.Spec.Configs = append(res.Spec.Configs, 
newAccessLogEnabledConfig(appName))
+       } else {
+               // access log config found and status is the same as needed
+               if accessLogConfig.Enabled == openAccessLog {
+                       return nil
+               }
+               // update the access log enabled status as needed
+               accessLogConfig.Enabled = openAccessLog
+       }
+       err := UpdateConfigurator(ctx, appConfiguratorName, res)
+       if err != nil {
+               logger.Errorf("update configurator failed when open accesslog, 
resourceKey: %s, openAccessLog: %t, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), 
openAccessLog, err)
+               return err
+       }
+       return nil
+}
+
+func newAccessLogEnabledConfig(appName string) *meshproto.OverrideConfig {
+       return &meshproto.OverrideConfig{
+               Side:       consts.SideProvider,
+               Parameters: map[string]string{`accesslog`: `true`},
+               Enabled:    true,
+               Match: &meshproto.ConditionMatch{
+                       Application: &meshproto.ListStringMatch{
+                               Oneof: []*meshproto.StringMatch{
+                                       {
+                                               Exact: appName,
+                                       },
+                               }}},
+               XGenerateByCp: true,
+       }
+}
+
+func GetAppAccessLog(ctx consolectx.Context, appName string, mesh string) 
(*model.AppAccessLogConfigResp, error) {
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       resp := &model.AppAccessLogConfigResp{
+               AccessLog: false,
+       }
+       if err != nil {
+               logger.Errorf("get configurator failed when get app accesslog, 
resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return nil, err
+       }
+       if res == nil {
+               return resp, nil
+       }
+       var appAccessLogConfig *meshproto.OverrideConfig
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isAppAccessLogConfig(conf, appName) {
+                       appAccessLogConfig = conf
+                       return true
+               }
+               return false
+       })
+       if appAccessLogConfig == nil {
+               return resp, nil
+       }
+       resp.AccessLog = appAccessLogConfig.Enabled
+       return resp, nil
+}
+
+func GetAppFlowWeight(ctx consolectx.Context, appName string, mesh string) 
(*model.AppFlowWeightConfigResp, error) {
+       resp := &model.AppFlowWeightConfigResp{
+               FlowWeightSets: []model.FlowWeightSet{},
+       }
+       appConfiguratorName := appName + consts.ConfiguratorRuleSuffix
+       res, err := GetConfigurator(ctx, appConfiguratorName, mesh)
+       if err != nil {
+               logger.Errorf("get configurator failed when get app flow 
weight, resourceKey: %s, err: %s",
+                       coremodel.BuildResourceKey(mesh, appName), err)
+               return nil, err
+       }
+       if res == nil {
+               return resp, nil
+       }
+
+       weight := 0
+       res.Spec.RangeConfig(func(conf *meshproto.OverrideConfig) (isStop bool) 
{
+               if isFlowWeightConfig(conf) {
+                       weight, err = strconv.Atoi(conf.Parameters[`weight`])
+                       if err != nil {
+                               logger.Error("parse weight failed", err)
+                               return true
+                       }
+                       scope := make([]model.ParamMatch, 0, 
len(conf.Match.Param))
+                       for _, param := range conf.Match.Param {
+                               scope = append(scope, model.ParamMatch{
+                                       Key:   &param.Key,
+                                       Value: 
model.StringMatchToModelStringMatch(param.Value),
+                               })
+                       }
+
+                       resp.FlowWeightSets = append(resp.FlowWeightSets, 
model.FlowWeightSet{
+                               Weight: int32(weight),
+                               Scope:  scope,
+                       })
+               }
+               return false
+       })
+       return resp, nil
+}
+
+func isFlowWeightConfig(conf *meshproto.OverrideConfig) bool {
+       if conf.Side != consts.SideProvider ||
+               conf.Parameters == nil ||
+               conf.Match == nil ||
+               conf.Match.Param == nil {
+               return false
+       } else if _, ok := conf.Parameters[`weight`]; !ok {
+               return false
+       }
+       return true
+}
+
+func UpInsertAppFlowWeightConfig(ctx consolectx.Context, appName string, mesh 
string, flowWeightSets []model.FlowWeightSet) error {
+       // check app exists
+       data, err := GetApplicationDetail(ctx, 
&model.ApplicationDetailReq{AppName: appName})
+       if err != nil {
+               return err
+       }
+       if data == nil {
+               return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s is not exists", appName))

Review Comment:
   Grammar error in error message: "is not exists" should be "does not exist".
   ```suggestion
                return bizerror.NewBizError(bizerror.AppNotFound, 
fmt.Sprintf("%s does not exist", appName))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to