mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
Merge branch 'feature/data-mask' into 'main'
fix log bug:Keyword query failed See merge request apipark/APIPark!114
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -142,7 +143,7 @@ func (d *Driver) Logs(clusterId string, conditions map[string]string, start time
|
||||
}
|
||||
cs := make([]string, 0, len(conditions))
|
||||
for k, v := range conditions {
|
||||
if strings.HasPrefix(v, "#") {
|
||||
if strings.HasPrefix(k, "#") {
|
||||
cs = append(cs, v)
|
||||
continue
|
||||
}
|
||||
@@ -151,6 +152,7 @@ func (d *Driver) Logs(clusterId string, conditions map[string]string, start time
|
||||
queries := url.Values{}
|
||||
queries.Set("query", fmt.Sprintf("{cluster=\"%s\"} | json | %s", clusterId, strings.Join(cs, " | ")))
|
||||
queries.Set("limit", strconv.FormatInt(limit, 10))
|
||||
queries.Set("direction", "backward")
|
||||
queries.Set("start", strconv.FormatInt(start.UnixNano(), 10))
|
||||
logs, err := d.recuseLogs(queries, end, offset)
|
||||
if err != nil {
|
||||
@@ -200,6 +202,9 @@ func (d *Driver) recuseLogs(queries url.Values, end time.Time, offset int64) ([]
|
||||
RecordTime: time.UnixMilli(msec),
|
||||
})
|
||||
}
|
||||
sort.Slice(logs, func(i, j int) bool {
|
||||
return logs[i].RecordTime.After(logs[j].RecordTime)
|
||||
})
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,9 @@ func (i *imlStrategyModule) StrategyLogInfo(ctx context.Context, id string) (*st
|
||||
}
|
||||
|
||||
func (i *imlStrategyModule) GetStrategyLogs(ctx context.Context, keyword string, strategyID string, start time.Time, end time.Time, limit int64, offset int64) ([]*strategy_dto.LogItem, int64, error) {
|
||||
if strategyID == "" {
|
||||
return nil, 0, errors.New("strategy id required")
|
||||
}
|
||||
conditions := map[string]string{
|
||||
"strategy": strategyID,
|
||||
}
|
||||
@@ -79,7 +82,7 @@ func (i *imlStrategyModule) GetStrategyLogs(ctx context.Context, keyword string,
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
orCondition := fmt.Sprintf("request_uri =~ \"*%s*\"", keyword)
|
||||
orCondition := fmt.Sprintf("request_uri =~ \".*%s.*\"", keyword)
|
||||
if len(apps) > 0 {
|
||||
appIds := utils.SliceToSlice(apps, func(a *service.Service) string { return a.Id })
|
||||
orCondition = fmt.Sprintf("%s or application =~ \"%s\"", orCondition, strings.Join(appIds, "|"))
|
||||
|
||||
Reference in New Issue
Block a user