Skip to content

Commit

Permalink
modify microservice menu (#1635)
Browse files Browse the repository at this point in the history
* modify menu sql and scope role

* modify menu

* delete logmod

* update go.mod

* update go.mod

* update go.mod

* add menu test

* update erda-infra

* insert record into tb_tmc_ini

* delete label of msp

* delete ini_name` = 'MK_JUMP_alarmManagement

* msp jump over permission check
  • Loading branch information
Counterflowwind authored Sep 4, 2021
1 parent 165a3ac commit 1049911
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 77 deletions.
11 changes: 11 additions & 0 deletions .erda/migrations/msp/20210901-menu.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
UPDATE `tb_tmc_ini` SET `ini_value` = 'AlarmManagement' WHERE `ini_name` = 'MK_monitor';
UPDATE `tb_tmc_ini` SET `ini_value` = '[{\"key\":\"EnvironmentalOverview\",\"cnName\":\"环境总览\",\"enName\":\"MicroService\",\"children\":[{\"key\":\"Overview\",\"cnName\":\"全局拓扑\",\"enName\":\"Overview\",\"exists\":true,\"mustExists\":true},{\"key\":\"ServiceList\",\"cnName\":\"服务列表\",\"enName\":\"ServiceList\",\"exists\":true,\"mustExists\":true}],\"exists\":true,\"mustExists\":true},{\"key\":\"ServiceObservation\",\"cnName\":\"服务观测\",\"enName\":\"ServiceObservation\",\"children\":[{\"key\":\"ServiceAnalysis\",\"cnName\":\"服务分析\",\"enName\":\"ServiceAnalysis\",\"exists\":false},{\"key\":\"ErrorInsight\",\"cnName\":\"错误分析\",\"enName\":\"ErrorInsight\",\"exists\":true},{\"key\":\"Transaction\",\"cnName\":\"链路追踪\",\"enName\":\"Transaction\",\"exists\":true}],\"exists\":true,\"mustExists\":true},{\"key\":\"QueryAnalysis\",\"cnName\":\"查询分析\",\"enName\":\"QueryAnalysis\",\"exists\":true,\"children\":[{\"cnName\":\"仪表盘\",\"enName\":\"Dashboard\",\"key\":\"Dashboard\",\"exists\":true},{\"cnName\":\"快速查询\",\"enName\":\"QuickQuery\",\"key\":\"QuickQuery\",\"exists\":true}]},{\"key\":\"LogAnalyze\",\"cnName\":\"日志分析\",\"enName\":\"LogAnalyze\",\"exists\":true,\"children\":[{\"cnName\":\"日志查询\",\"enName\":\"LogQuery\",\"key\":\"LogQuery\",\"exists\":false},{\"cnName\":\"分析规则\",\"enName\":\"AnalyzeRule\",\"key\":\"AnalyzeRule\",\"exists\":false}]},{\"key\":\"APIGateway\",\"cnName\":\"API网关\",\"enName\":\"APIGateway\",\"children\":[{\"key\":\"GatewayIntro\",\"cnName\":\"使用引导\",\"enName\":\"GatewayIntro\",\"href\":\"apiGatewayIntro\",\"exists\":true},{\"key\":\"Endpoints\",\"cnName\":\"流量入口管理\",\"enName\":\"Endpoints\",\"exists\":false,\"onlyK8S\":true},{\"key\":\"APIs\",\"cnName\":\"微服务API管理\",\"enName\":\"APIs\",\"exists\":false},{\"key\":\"ConsumerACL\",\"cnName\":\"调用方管理\",\"enName\":\"ConsumerACL\",\"exists\":false,\"onlyK8S\":true},{\"key\":\"OldPolicies\",\"cnName\":\"API策略\",\"enName\":\"Policies\",\"exists\":false,\"onlyNotK8S\":true},{\"key\":\"OldConsumerACL\",\"cnName\":\"调用者授权\",\"enName\":\"ConsumerACL\",\"exists\":false,\"onlyNotK8S\":true}],\"exists\":true,\"mustExists\":true},{\"key\":\"RegisterCenter\",\"cnName\":\"注册中心\",\"enName\":\"RegisterCenter\",\"children\":[{\"key\":\"RegisterIntro\",\"cnName\":\"使用引导\",\"enName\":\"RegisterIntro\",\"href\":\"registerCenterIntro\",\"exists\":true},{\"key\":\"Services\",\"cnName\":\"服务注册列表\",\"enName\":\"Services\",\"exists\":false}],\"exists\":true,\"mustExists\":true},{\"key\":\"ConfigCenter\",\"cnName\":\"配置中心\",\"enName\":\"ConfigCenter\",\"children\":[{\"key\":\"ConfigIntro\",\"cnName\":\"使用引导\",\"href\":\"configCenterIntro\",\"enName\":\"ConfigIntro\",\"exists\":true},{\"key\":\"Configs\",\"cnName\":\"配置管理\",\"enName\":\"Configs\",\"exists\":false}],\"exists\":true,\"mustExists\":true},{\"key\":\"AlarmManagement\",\"cnName\":\"告警管理\",\"enName\":\"AlarmManagement\",\"children\":[{\"key\":\"AlertStrategy\",\"cnName\":\"告警策略\",\"enName\":\"AlertStrategy\",\"exists\":false},{\"key\":\"AlarmHistory\",\"cnName\":\"告警历史\",\"enName\":\"AlarmHistory\",\"exists\":false},{\"key\":\"RuleManagement\",\"cnName\":\"规则管理\",\"enName\":\"RuleManagement\",\"exists\":false},{\"key\":\"NotifyGroupManagement\",\"cnName\":\"通知组管理\",\"enName\":\"NotifyGroupManagement\",\"exists\":false}],\"exists\":true,\"mustExists\":true},{\"key\":\"EnvironmentSet\",\"cnName\":\"环境设置\",\"enName\":\"EnvironmentSet\",\"children\":[{\"key\":\"AccessConfig\",\"cnName\":\"接入配置\",\"enName\":\"AccessConfig\",\"onlyK8S\":true,\"onlyNotK8S\":true,\"exists\":false},{\"key\":\"MemberManagement\",\"cnName\":\"成员管理\",\"enName\":\"MemberManagement\",\"onlyK8S\":true,\"onlyNotK8S\":true,\"exists\":false},{\"key\":\"ComponentInfo\",\"cnName\":\"组件信息\",\"enName\":\"ComponentInfo\",\"onlyK8S\":true,\"onlyNotK8S\":false,\"exists\":false}],\"exists\":true,\"mustExists\":true}]' WHERE `ini_name` = 'MS_MENU';
UPDATE `tb_tmc_ini` SET `ini_value` = 'AlertStrategy' WHERE `ini_name` = 'MK_JUMP_monitor';
INSERT `tb_tmc_ini` (ini_name,ini_value,ini_desc,is_deleted) VALUES ('MK_environmentalOverview','EnvironmentalOverview','mk_environmentalOverview','N');
INSERT `tb_tmc_ini` (ini_name,ini_value,ini_desc,is_deleted) VALUES ('MK_JUMP_environmentalOverview','Overview','jump_environmentalOverview','N');
INSERT `tb_tmc_ini` (ini_name,ini_value,ini_desc,is_deleted) VALUES ('MK_serviceObservation','ServiceObservation','mk_serviceObservation','N');
INSERT `tb_tmc_ini` (ini_name,ini_value,ini_desc,is_deleted) VALUES ('MK_JUMP_serviceObservation','ErrorInsight','jump_serviceObservation','N');
INSERT `tb_tmc_ini` (ini_name,ini_value,ini_desc,is_deleted) VALUES ('MK_queryAnalysis','QueryAnalysis','mk_queryAnalysis','N');
INSERT `tb_tmc_ini` (ini_name,ini_value,ini_desc,is_deleted) VALUES ('MK_JUMP_QueryAnalysis','Dashboard','jump_QueryAnalysis','N');
INSERT `tb_tmc_ini` (ini_name,ini_value,ini_desc,is_deleted) VALUES ('MK_alarmManagement','AlarmManagement','mk_alarmManagement','N');
INSERT `tb_tmc_ini` (ini_name,ini_value,ini_desc,is_deleted) VALUES ('MK_JUMP_alarmManagement','AlertStrategy','jump_alarmManagement','N');
3 changes: 3 additions & 0 deletions apistructs/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (
// 答疑用户的固定 ID
const SupportID string = "2020"

//MSP
const MSPScope string = "msp"

// Publisher 类型
const (
// 移动应用
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/elastic/cloud-on-k8s v0.0.0-20210205172912-5ce0eca90c60
github.com/elazarl/goproxy v0.0.0-20200421181703-e76ad31c14f6
github.com/erda-project/erda-infra v0.0.0-20210901113044-1130cdf38f06
github.com/erda-project/erda-proto-go v0.0.0-20210902110458-4cc401865f3f
github.com/erda-project/erda-proto-go v0.0.0-20210903092110-0e5c7079f914
github.com/extrame/ole2 v0.0.0-20160812065207-d69429661ad7 // indirect
github.com/extrame/xls v0.0.1
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ github.com/erda-project/erda-proto-go v0.0.0-20210831060342-7be1b9a69982 h1:XPF5
github.com/erda-project/erda-proto-go v0.0.0-20210831060342-7be1b9a69982/go.mod h1:G5C43mj+aCGsYlB/KsjYL/S8UIfU8XHBaJoG83GRP7g=
github.com/erda-project/erda-proto-go v0.0.0-20210902110458-4cc401865f3f h1:MTItVXg0WQ+whnDluy/gXNodwp0vOj2wEXNbwm5mgkI=
github.com/erda-project/erda-proto-go v0.0.0-20210902110458-4cc401865f3f/go.mod h1:G5C43mj+aCGsYlB/KsjYL/S8UIfU8XHBaJoG83GRP7g=
github.com/erda-project/erda-proto-go v0.0.0-20210903092110-0e5c7079f914 h1:iQzarViF1Pd3j/W39o+fRamqVuLUh8CoG4X0OXaix18=
github.com/erda-project/erda-proto-go v0.0.0-20210903092110-0e5c7079f914/go.mod h1:G5C43mj+aCGsYlB/KsjYL/S8UIfU8XHBaJoG83GRP7g=
github.com/erda-project/flink-on-k8s-operator v0.0.0-20210828094530-28e003581cf2 h1:5QKXIq0yTPulGqXzEQx96fLK6HDCb8xC1H6kOjj4hsk=
github.com/erda-project/flink-on-k8s-operator v0.0.0-20210828094530-28e003581cf2/go.mod h1:QbDTwfKi8Nd8VR7cdOqRyWM2Ymul7m0hzSaoC3xSho8=
github.com/erda-project/influxql v1.1.0-ex h1:NgP5+S5Qo234IVSIJ3N/egvzCNYJURfMAett3e8a9LE=
Expand Down
3 changes: 3 additions & 0 deletions modules/core-services/endpoints/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ func (e *Endpoints) FuzzyQueryNotifiesBySource(ctx context.Context, r *http.Requ
}

func (e *Endpoints) checkNotifyPermission(r *http.Request, scopeType, scopeID, action string) error {
if strings.Contains(scopeType, apistructs.MSPScope) {
return nil
}
userID := r.Header.Get("User-ID")
if userID == "" {
return errors.New("failed to get permission(User-ID is empty)")
Expand Down
4 changes: 2 additions & 2 deletions modules/msp/menu/db/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type MenuConfigDB struct {
func (db *MenuConfigDB) GetMicroServiceMenu() (*TmcIni, error) {
var list []*TmcIni
if err := db.Table(TableTmcIni).
Where("ini_name=?", MenuIniName).Limit(1).Find(&list).Error; err != nil {
Where("ini_name=?", MenuIniName).Where("is_deleted = ?", "N").Limit(1).Find(&list).Error; err != nil {
return nil, err
}
if len(list) <= 0 {
Expand All @@ -43,7 +43,7 @@ func (db *MenuConfigDB) GetMicroServiceMenu() (*TmcIni, error) {
func (db *MenuConfigDB) GetMicroServiceEngineKey(engine string) (string, error) {
var list []*TmcIni
if err := db.Table(TableTmcIni).
Where("ini_name=?", EngineMenuKeyPrefix+engine).Limit(1).Find(&list).Error; err != nil {
Where("ini_name=?", EngineMenuKeyPrefix+engine).Where("is_deleted = ?", "N").Limit(1).Find(&list).Error; err != nil {
return "", err
}
if len(list) <= 0 || list[0] == nil {
Expand Down
65 changes: 42 additions & 23 deletions modules/msp/menu/menu.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type menuService struct {

var splitEDAS = strings.ToLower(os.Getenv("SPLIT_EDAS_CLUSTER_TYPE")) == "true"

// GetMenu api
//GetMenu api
func (s *menuService) GetMenu(ctx context.Context, req *pb.GetMenuRequest) (*pb.GetMenuResponse, error) {
// get menu items
items, err := s.getMenuItems()
Expand All @@ -50,19 +50,21 @@ func (s *menuService) GetMenu(ctx context.Context, req *pb.GetMenuRequest) (*pb.
if req.Type == tenantpb.Type_MSP.String() {
var mspItems []*pb.MenuItem
for _, item := range items {
if item.Key == "ServiceGovernance" || item.Key == "AppMonitor" {
params := s.composeMSPMenuParams(req)
item.Params = params
for _, child := range item.Children {
if child.Key == "MonitorIntro" {
child.Exists = false
continue
}
child.Exists = true
child.Params = params
params := s.composeMSPMenuParams(req)
item.Params = params
for _, child := range item.Children {
if child.Key == "MonitorIntro" {
child.Exists = false
continue
}
mspItems = append(mspItems, item)
if child.Key == "ComponentInfo" {
child.Exists = false
continue
}
child.Exists = true
child.Params = params
}
mspItems = append(mspItems, item)
}
items = mspItems
}
Expand All @@ -84,6 +86,23 @@ func (s *menuService) GetMenu(ctx context.Context, req *pb.GetMenuRequest) (*pb.

menuMap := make(map[string]*pb.MenuItem)
for _, item := range items {
isK8s := clusterInfo.IsK8S() || (!splitEDAS && clusterInfo.IsEDAS())
if item.EnName == "EnvironmentSet" {
for _, child := range item.Children {
child.Params = item.Params
// 反转exists字段,隐藏引导页,显示功能子菜单
child.Exists = !child.Exists
if child.OnlyK8S && !isK8s {
child.Exists = false
}
if child.OnlyNotK8S && isK8s {
child.Exists = false
}
if child.MustExists {
child.Exists = true
}
}
}
item.ClusterName = clusterName
item.ClusterType = clusterType
for _, child := range item.Children {
Expand Down Expand Up @@ -274,27 +293,27 @@ func (s *menuService) getEngineConfigs(group, tenantID string) (map[string]map[s
}

func (s *menuService) adjustMenuParams(items []*pb.MenuItem) []*pb.MenuItem {
var overview, monitor, loghub *pb.MenuItem
//var overview, monitor, loghub *pb.MenuItem
var monitor, loghub *pb.MenuItem
setParams := make([]*pb.MenuItem, 0)
for _, item := range items {
switch item.Key {
case "ServiceGovernance":
for _, child := range item.Children {
if child.Key == "Overview" {
overview = child
}
}
case "AppMonitor":
case "EnvironmentalOverview", "ServiceObservation", "QueryAnalysis":
setParams = append(setParams, item)
case "AlarmManagement":
monitor = item
case "LogAnalyze":
loghub = item
}
if monitor != nil && overview != nil && loghub != nil {
if monitor != nil && loghub != nil {
break
}
}
if monitor != nil {
if overview != nil {
overview.Params = monitor.Params
for _, item := range setParams {
for _, child := range item.Children {
child.Params = monitor.Params
}
}
if loghub != nil {
if loghub.Params == nil {
Expand Down
Loading

0 comments on commit 1049911

Please sign in to comment.