fixed some bugs

This commit is contained in:
liuzhihang1
2024-06-29 22:26:47 +08:00
parent 8889c86e75
commit 7e2d6f420b
12 changed files with 203 additions and 17 deletions

View File

@@ -37,7 +37,7 @@ func InitEs() bool {
log.Logger.Error("es启动失败", err)
config.CF.EsEnable = false
} else {
return true
return true
}
} else {
log.Logger.Debug("不使用es")
@@ -121,12 +121,16 @@ func (e *esService) Search(req model.GetLogReq) model.LogResp {
func (e *esService) buildQueryBody(req model.GetLogReq) model.QueryBody {
result := model.QueryBody{}
if req.TimeRange.EndTime != 0 || req.TimeRange.StartTime != 0 {
time := map[string]any{}
if req.TimeRange.StartTime != 0 {
time["gte"] = req.TimeRange.StartTime
}
if req.TimeRange.EndTime != 0 {
time["lte"] = req.TimeRange.EndTime
}
result.Query.Bool.Must = append(result.Query.Bool.Must, map[string]any{
"range": map[string]any{
"time": map[string]any{
"gte": req.TimeRange.StartTime,
"lte": req.TimeRange.EndTime,
},
"time": time,
},
})
}

View File

@@ -7,6 +7,7 @@ import (
"msm/config"
"msm/log"
"msm/model"
"msm/utils"
"os/exec"
"strings"
"time"
@@ -107,7 +108,7 @@ func (p *ProcessStd) pInit() {
func (p *ProcessStd) ReadCache(ws *websocket.Conn) {
for _, line := range p.cacheLine {
ws.WriteMessage(websocket.BinaryMessage, []byte(line))
ws.WriteMessage(websocket.TextMessage, []byte(line))
}
}
@@ -128,7 +129,7 @@ func (p *ProcessStd) readInit() {
output = p.Read()
if p.IsUsing.Load() && output != "" {
p.ws.wsMux.Lock()
p.ws.wsConnect.WriteMessage(websocket.BinaryMessage, []byte(output))
p.ws.wsConnect.WriteMessage(websocket.TextMessage, []byte(output))
p.ws.wsMux.Unlock()
}
}
@@ -137,7 +138,7 @@ func (p *ProcessStd) readInit() {
}
func (p *ProcessStd) Read() string {
if p.stdout.Scan() {
output := p.stdout.Text()
output := utils.RemoveNotValidUtf8InString(p.stdout.Text())
p.logReportHandler(output)
p.cacheLine = p.cacheLine[1:]
p.cacheLine = append(p.cacheLine, output)