update log label

This commit is contained in:
Liujian
2024-12-05 15:04:43 +08:00
parent 6bf3737c24
commit c75df95cce
5 changed files with 13 additions and 10 deletions
+2 -2
View File
@@ -50,7 +50,7 @@ type LogInfo struct {
type LogDetail struct {
Api string `json:"api"`
Application string `json:"application"`
BlockName string `json:"block_name"`
Strategy string `json:"strategy"`
ContentType string `json:"content_type"`
Cluster string `json:"cluster"`
Msec string `json:"msec"`
@@ -66,7 +66,7 @@ type LogDetail struct {
ProxyResponseBody string `json:"proxy_response_body"`
Service string `json:"service"`
Provider string `json:"provider"`
Auth string `json:"auth"`
Authorization string `json:"authorization"`
SrcIp string `json:"src_ip"`
Status string `json:"status"`
}
+1 -1
View File
@@ -196,7 +196,7 @@ func (d *Driver) recuseLogs(queries url.Values, end time.Time, offset int64) ([]
Url: detail.RequestUri,
RemoteIP: detail.SrcIp,
Consumer: detail.Application,
Authorization: detail.Auth,
Authorization: detail.Authorization,
RecordTime: time.UnixMilli(msec),
})
}
+4 -4
View File
@@ -10,12 +10,12 @@ func TestLoki(t *testing.T) {
if err != nil {
t.Fatalf("failed to create driver: %v", err)
}
logCountResult, err := d.LogCount("apinto", nil, 720, "block_name")
logCountResult, err := d.LogCount("apinto", nil, 720, "strategy")
if err != nil {
t.Fatalf("failed to get log count: %v", err)
}
t.Log(logCountResult)
logs, count, err := d.Logs("apinto", map[string]string{"block_name": "03899736-5d79-4f26-bd6a-c312a5880780"}, time.Now().Add(-time.Hour*24), time.Now(), 1, 1)
logs, count, err := d.Logs("apinto", map[string]string{"strategy": "03899736-5d79-4f26-bd6a-c312a5880780"}, time.Now().Add(-time.Hour*24), time.Now(), 1, 1)
if err != nil {
t.Fatalf("failed to get logs: %v", err)
}
@@ -57,7 +57,7 @@ func TestLoki(t *testing.T) {
// headers["Content-Type"] = "application/json"
// headers["X-Scope-OrgID"] = "tenant1"
// queries := url.Values{}
// //queries.Set("query", "sum(count_over_time({cluster=\"apinto\"}[24h])) by (block_name)")
// //queries.Set("query", "sum(count_over_time({cluster=\"apinto\"}[24h])) by (strategy)")
// queries.Set("query", "sum(count_over_time({cluster=\"apinto\"}[24h]))")
// result, err := send[LogCount](http.MethodGet, "http://localhost:3100/loki/api/v1/query", headers, queries, "")
// if err != nil {
@@ -75,7 +75,7 @@ func TestLoki(t *testing.T) {
// headers["Content-Type"] = "application/json"
// headers["X-Scope-OrgID"] = "tenant1"
// queries := url.Values{}
// queries.Set("query", "{cluster=\"apinto\"} | json | block_name=\"03899736-5d79-4f26-bd6a-c312a5880780\"")
// queries.Set("query", "{cluster=\"apinto\"} | json | strategy=\"03899736-5d79-4f26-bd6a-c312a5880780\"")
// now := time.Now()
// start := now.Add(-time.Hour * 24 * 30)
// queries.Set("start", strconv.FormatInt(start.UnixNano(), 10))
+3
View File
@@ -153,6 +153,9 @@ func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service)
Expire: a.ExpireTime,
Config: authCfg,
HideCredential: a.HideCredential,
Label: map[string]string{
"authorization": a.UUID,
},
}
}),
}
+3 -3
View File
@@ -69,7 +69,7 @@ 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) {
conditions := map[string]string{
"block_name": strategyID,
"strategy": strategyID,
}
if keyword != "" {
// 查询符合条件的应用ID
@@ -174,9 +174,9 @@ func (i *imlStrategyModule) Search(ctx context.Context, keyword string, driver s
c, err := i.clusterService.Get(ctx, cluster.DefaultClusterID)
if err == nil {
countMap, err = i.logService.LogCount(ctx, "loki", c.Cluster, map[string]string{
"#1": fmt.Sprintf("block_name =~ \"%s\"", strings.Join(strategyIds, "|")),
"#1": fmt.Sprintf("strategy =~ \"%s\"", strings.Join(strategyIds, "|")),
}, 720,
"block_name")
"strategy")
if err != nil {
log.Errorf("get log count error: %v", err)
}