package runtimeLogs import ( "strings" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" timeutil "github.com/iwind/TeaGo/utils/time" ) type IndexAction struct { actionutils.ParentAction } func (this *IndexAction) Init() { this.Nav("httpdns", "runtimeLogs", "") } func (this *IndexAction) RunGet(params struct { ClusterId int64 NodeId int64 DayFrom string DayTo string Level string Keyword string }) { httpdnsutils.AddLeftMenu(this.Parent()) if params.ClusterId > 0 { this.Data["clusterId"] = params.ClusterId } else { this.Data["clusterId"] = "" } if params.NodeId > 0 { this.Data["nodeId"] = params.NodeId } else { this.Data["nodeId"] = "" } this.Data["dayFrom"] = params.DayFrom this.Data["dayTo"] = params.DayTo this.Data["level"] = params.Level this.Data["keyword"] = params.Keyword clusterResp, err := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.AdminContext(), &pb.FindAllHTTPDNSClustersRequest{}) if err != nil { this.ErrorPage(err) return } clusters := make([]map[string]interface{}, 0, len(clusterResp.GetClusters())) nodes := make([]map[string]interface{}, 0) for _, cluster := range clusterResp.GetClusters() { clusters = append(clusters, map[string]interface{}{ "id": cluster.GetId(), "name": cluster.GetName(), }) nodeResp, err := this.RPC().HTTPDNSNodeRPC().ListHTTPDNSNodes(this.AdminContext(), &pb.ListHTTPDNSNodesRequest{ ClusterId: cluster.GetId(), }) if err != nil { this.ErrorPage(err) return } for _, node := range nodeResp.GetNodes() { nodes = append(nodes, map[string]interface{}{ "id": node.GetId(), "clusterId": node.GetClusterId(), "name": node.GetName(), }) } } this.Data["clusters"] = clusters this.Data["nodes"] = nodes day := strings.TrimSpace(params.DayFrom) if len(day) == 0 { day = strings.TrimSpace(params.DayTo) } logResp, err := this.RPC().HTTPDNSRuntimeLogRPC().ListHTTPDNSRuntimeLogs(this.AdminContext(), &pb.ListHTTPDNSRuntimeLogsRequest{ Day: day, ClusterId: params.ClusterId, NodeId: params.NodeId, Level: strings.TrimSpace(params.Level), Keyword: strings.TrimSpace(params.Keyword), Offset: 0, Size: 100, }) if err != nil { this.ErrorPage(err) return } runtimeLogs := make([]map[string]interface{}, 0, len(logResp.GetLogs())) for _, item := range logResp.GetLogs() { createdTime := "" if item.GetCreatedAt() > 0 { createdTime = timeutil.FormatTime("Y-m-d H:i:s", item.GetCreatedAt()) } runtimeLogs = append(runtimeLogs, map[string]interface{}{ "createdTime": createdTime, "clusterId": item.GetClusterId(), "clusterName": item.GetClusterName(), "nodeId": item.GetNodeId(), "nodeName": item.GetNodeName(), "level": item.GetLevel(), "tag": item.GetType(), "module": item.GetModule(), "description": item.GetDescription(), "count": item.GetCount(), "requestId": item.GetRequestId(), }) } this.Data["runtimeLogs"] = runtimeLogs this.Show() }