Browse Source

[REV] 异常影响范围,提供服务的中文字段

pujielan 3 months ago
parent
commit
a74e267bea
2 changed files with 19 additions and 1 deletions
  1. 1 0
      app/observe/service/dto/event.go
  2. 18 1
      app/observe/service/event.go

+ 1 - 0
app/observe/service/dto/event.go

@@ -74,4 +74,5 @@ type EventListsResp struct {
 	Total         int64  `json:"total" ch:"StatusMessageCount" gorm:"column:StatusMessageCount"`
 	StatusMessage string `json:"status_message" ch:"StatusMessage" gorm:"column:StatusMessage"`
 	ServiceName   string `json:"service_name" ch:"ServiceName" gorm:"column:ServiceName"`
+	ServiceCnName string `json:"service_cn_name" ch:"ServiceCnName" gorm:"column:ServiceCnName"`
 }

+ 18 - 1
app/observe/service/event.go

@@ -124,6 +124,7 @@ func (e *Event) EventStatistic(c *dto.EventStatisticReq, result *[]dto.EventStat
 }
 
 func (e *Event) EventLists(c *dto.EventStatisticReq, result *[]dto.EventListsResp) error {
+	res := make([]dto.EventListsResp, 0)
 	db := e.ChOrm.Table(models.TableNameTrace)
 	db.Select([]string{
 		"StatusMessage",
@@ -149,8 +150,24 @@ func (e *Event) EventLists(c *dto.EventStatisticReq, result *[]dto.EventListsRes
 	db.Where("StatusCode = 'STATUS_CODE_ERROR' AND StatusMessage != '' AND StatusMessage != 'status code:0'")
 	db.Group("StatusMessage")
 	db.Group("ServiceName")
-	if err := db.Order("StatusMessageCount DESC;").Find(&result).Error; err != nil {
+	if err := db.Order("StatusMessageCount DESC;").Find(&res).Error; err != nil {
 		return errors.Wrap(err, "统计范围时间内的具体异常失败")
 	}
+	svcNodes := []struct {
+		ServiceName string
+		Name        string
+	}{}
+	if err := e.Orm.Model(&models.ServiceNode{}).Where("app_alias", c.AppAlias).Find(&svcNodes).Error; err != nil {
+		return errors.Wrap(err, "获取服务列表失败")
+	}
+	svcMap := map[string]string{}
+	for _, node := range svcNodes {
+		svcMap[node.ServiceName] = node.Name
+	}
+	for _, r := range res {
+		r.ServiceCnName = svcMap[r.ServiceName]
+		fmt.Println("r.serviceName", r.ServiceCnName)
+		*result = append(*result, r)
+	}
 	return nil
 }