可以修复单页或者全部服务日志

This commit is contained in:
刘祥超
2022-03-23 17:31:26 +08:00
parent 06ad9cc63b
commit 0ce1df25bc
2 changed files with 44 additions and 7 deletions

View File

@@ -59,7 +59,7 @@ func (this *NodeLogDAO) CreateLog(tx *dbs.Tx, nodeRole nodeconfigs.NodeRole, nod
}
}
hash := stringutil.Md5(nodeRole + "@" + types.String(nodeId) + "@" + types.String(serverId) + "@" + types.String(originId) + "@" + level + "@" + tag + "@" + description + "@" + string(paramsJSON))
var hash = stringutil.Md5(nodeRole + "@" + types.String(nodeId) + "@" + types.String(serverId) + "@" + types.String(originId) + "@" + level + "@" + tag + "@" + description + "@" + string(paramsJSON))
// 检查是否在重复最后一条,避免重复创建
lastLog, err := this.Query(tx).
@@ -80,7 +80,7 @@ func (this *NodeLogDAO) CreateLog(tx *dbs.Tx, nodeRole nodeconfigs.NodeRole, nod
}
}
op := NewNodeLogOperator()
var op = NewNodeLogOperator()
op.Role = nodeRole
op.NodeId = nodeId
op.ServerId = serverId
@@ -139,13 +139,15 @@ func (this *NodeLogDAO) CountNodeLogs(tx *dbs.Tx,
nodeId int64,
serverId int64,
originId int64,
allServers bool,
dayFrom string,
dayTo string,
keyword string,
level string,
fixedState configutils.BoolState,
isUnread bool,
tag string) (int64, error) {
query := this.Query(tx)
var query = this.Query(tx)
if len(role) > 0 {
query.Attr("role", role)
}
@@ -166,6 +168,8 @@ func (this *NodeLogDAO) CountNodeLogs(tx *dbs.Tx,
}
if serverId > 0 {
query.Attr("serverId", serverId)
} else if allServers {
query.Where("serverId>0")
}
if originId > 0 {
query.Attr("originId", originId)
@@ -185,6 +189,13 @@ func (this *NodeLogDAO) CountNodeLogs(tx *dbs.Tx,
if len(level) > 0 {
query.Attr("level", level)
}
if fixedState == configutils.BoolStateYes {
query.Attr("isFixed", 1)
query.Where("level IN ('error', 'success', 'warning')")
} else if fixedState == configutils.BoolStateNo {
query.Attr("isFixed", 0)
query.Where("level IN ('error', 'success', 'warning')")
}
if isUnread {
query.Attr("isRead", 0)
}
@@ -212,7 +223,7 @@ func (this *NodeLogDAO) ListNodeLogs(tx *dbs.Tx,
tag string,
offset int64,
size int64) (result []*NodeLog, err error) {
query := this.Query(tx)
var query = this.Query(tx)
if len(role) > 0 {
query.Attr("role", role)
}
@@ -241,8 +252,10 @@ func (this *NodeLogDAO) ListNodeLogs(tx *dbs.Tx,
}
if fixedState == configutils.BoolStateYes {
query.Attr("isFixed", 1)
query.Where("level IN ('error', 'success', 'warning')")
} else if fixedState == configutils.BoolStateNo {
query.Attr("isFixed", 0)
query.Where("level IN ('error', 'success', 'warning')")
}
if len(dayFrom) > 0 {
dayFrom = strings.ReplaceAll(dayFrom, "-", "")
@@ -310,6 +323,14 @@ func (this *NodeLogDAO) UpdateNodeLogFixed(tx *dbs.Tx, logId int64) error {
return nil
}
// UpdateAllNodeLogsFixed 设置所有节点日志为已修复
func (this *NodeLogDAO) UpdateAllNodeLogsFixed(tx *dbs.Tx) error {
return this.Query(tx).
Attr("isFixed", 0).
Set("isFixed", 1).
UpdateQuickly()
}
// CountAllUnreadNodeLogs 计算未读的日志数量
func (this *NodeLogDAO) CountAllUnreadNodeLogs(tx *dbs.Tx) (int64, error) {
return this.Query(tx).

View File

@@ -41,7 +41,7 @@ func (this *NodeLogService) CountNodeLogs(ctx context.Context, req *pb.CountNode
tx := this.NullTx()
count, err := models.SharedNodeLogDAO.CountNodeLogs(tx, req.Role, req.NodeClusterId, req.NodeId, req.ServerId, req.OriginId, req.DayFrom, req.DayTo, req.Keyword, req.Level, req.IsUnread, req.Tag)
count, err := models.SharedNodeLogDAO.CountNodeLogs(tx, req.Role, req.NodeClusterId, req.NodeId, req.ServerId, req.OriginId, req.AllServers, req.DayFrom, req.DayTo, req.Keyword, req.Level, types.Int8(req.FixedState), req.IsUnread, req.Tag)
if err != nil {
return nil, err
}
@@ -62,9 +62,9 @@ func (this *NodeLogService) ListNodeLogs(ctx context.Context, req *pb.ListNodeLo
return nil, err
}
hashList := []string{}
var hashList = []string{}
result := []*pb.NodeLog{}
var result = []*pb.NodeLog{}
for _, log := range logs {
// 如果是需要修复的日志,我们需要去重
if req.FixedState > 0 {
@@ -109,6 +109,22 @@ func (this *NodeLogService) FixNodeLogs(ctx context.Context, req *pb.FixNodeLogs
return this.Success()
}
// FixAllNodeLogs 设置所有日志为已修复
func (this *NodeLogService) FixAllNodeLogs(ctx context.Context, req *pb.FixAllNodeLogsRequest) (*pb.RPCSuccess, error) {
_, err := this.ValidateAdmin(ctx, 0)
if err != nil {
return nil, err
}
var tx = this.NullTx()
err = models.SharedNodeLogDAO.UpdateAllNodeLogsFixed(tx)
if err != nil {
return nil, err
}
return this.Success()
}
// CountAllUnreadNodeLogs 计算未读的日志数量
func (this *NodeLogService) CountAllUnreadNodeLogs(ctx context.Context, req *pb.CountAllUnreadNodeLogsRequest) (*pb.RPCCountResponse, error) {
_, err := this.ValidateAdmin(ctx, 0)