错误日志查询问题修复
This commit is contained in:
@@ -126,6 +126,9 @@ func (s *LogsIngestStore) List(ctx context.Context, f ListFilter) (rows []*LogsI
|
||||
if f.HasFirewallPolicy {
|
||||
conditions = append(conditions, "firewall_policy_id > 0")
|
||||
}
|
||||
if f.HasError {
|
||||
conditions = append(conditions, "status >= 400")
|
||||
}
|
||||
if f.FirewallPolicyId > 0 {
|
||||
conditions = append(conditions, "firewall_policy_id = "+strconv.FormatInt(f.FirewallPolicyId, 10))
|
||||
}
|
||||
|
||||
@@ -67,14 +67,33 @@ func (this *HTTPAccessLogService) ListHTTPAccessLogs(ctx context.Context, req *p
|
||||
}
|
||||
|
||||
store := clickhouse.NewLogsIngestStore()
|
||||
if store.Client().IsConfigured() && req.Day != "" {
|
||||
canReadFromClickHouse := this.shouldReadAccessLogsFromClickHouse() && store.Client().IsConfigured() && req.Day != ""
|
||||
canReadFromMySQL := this.shouldReadAccessLogsFromMySQL()
|
||||
if canReadFromClickHouse {
|
||||
resp, listErr := this.listHTTPAccessLogsFromClickHouse(ctx, tx, store, req, userId)
|
||||
if listErr != nil {
|
||||
return nil, listErr
|
||||
}
|
||||
if resp != nil {
|
||||
if listErr == nil && resp != nil {
|
||||
return resp, nil
|
||||
}
|
||||
if !canReadFromMySQL {
|
||||
if listErr != nil {
|
||||
return nil, listErr
|
||||
}
|
||||
return &pb.ListHTTPAccessLogsResponse{
|
||||
HttpAccessLogs: []*pb.HTTPAccessLog{},
|
||||
AccessLogs: []*pb.HTTPAccessLog{},
|
||||
HasMore: false,
|
||||
RequestId: "",
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
if !canReadFromMySQL {
|
||||
return &pb.ListHTTPAccessLogsResponse{
|
||||
HttpAccessLogs: []*pb.HTTPAccessLog{},
|
||||
AccessLogs: []*pb.HTTPAccessLog{},
|
||||
HasMore: false,
|
||||
RequestId: "",
|
||||
}, nil
|
||||
}
|
||||
|
||||
accessLogs, requestId, hasMore, err := models.SharedHTTPAccessLogDAO.ListAccessLogs(tx, req.Partition, req.RequestId, req.Size, req.Day, req.HourFrom, req.HourTo, req.NodeClusterId, req.NodeId, req.ServerId, req.Reverse, req.HasError, req.FirewallPolicyId, req.FirewallRuleGroupId, req.FirewallRuleSetId, req.HasFirewallPolicy, req.UserId, req.Keyword, req.Ip, req.Domain)
|
||||
@@ -241,12 +260,15 @@ func (this *HTTPAccessLogService) FindHTTPAccessLog(ctx context.Context, req *pb
|
||||
|
||||
// 优先从 ClickHouse 查询
|
||||
store := clickhouse.NewLogsIngestStore()
|
||||
if store.Client().IsConfigured() {
|
||||
canReadFromClickHouse := this.shouldReadAccessLogsFromClickHouse() && store.Client().IsConfigured()
|
||||
canReadFromMySQL := this.shouldReadAccessLogsFromMySQL()
|
||||
if canReadFromClickHouse {
|
||||
row, err := store.FindByTraceId(ctx, req.RequestId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if row != nil {
|
||||
if !canReadFromMySQL {
|
||||
return nil, err
|
||||
}
|
||||
} else if row != nil {
|
||||
// 检查权限
|
||||
if userId > 0 {
|
||||
var tx = this.NullTx()
|
||||
@@ -260,6 +282,10 @@ func (this *HTTPAccessLogService) FindHTTPAccessLog(ctx context.Context, req *pb
|
||||
}
|
||||
}
|
||||
|
||||
if !canReadFromMySQL {
|
||||
return &pb.FindHTTPAccessLogResponse{HttpAccessLog: nil}, nil
|
||||
}
|
||||
|
||||
// 如果 ClickHouse 未配置或未找到,则回退到 MySQL
|
||||
var tx = this.NullTx()
|
||||
|
||||
|
||||
@@ -9,6 +9,14 @@ func (this *HTTPAccessLogService) canWriteAccessLogsToDB() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *HTTPAccessLogService) shouldReadAccessLogsFromClickHouse() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *HTTPAccessLogService) shouldReadAccessLogsFromMySQL() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *HTTPAccessLogService) writeAccessLogsToPolicy(pbAccessLogs []*pb.HTTPAccessLog) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,15 @@ import (
|
||||
)
|
||||
|
||||
func (this *HTTPAccessLogService) canWriteAccessLogsToDB() bool {
|
||||
return false
|
||||
return accesslogs.SharedStorageManager.WriteMySQL()
|
||||
}
|
||||
|
||||
func (this *HTTPAccessLogService) shouldReadAccessLogsFromClickHouse() bool {
|
||||
return accesslogs.SharedStorageManager.WriteClickHouse()
|
||||
}
|
||||
|
||||
func (this *HTTPAccessLogService) shouldReadAccessLogsFromMySQL() bool {
|
||||
return accesslogs.SharedStorageManager.WriteMySQL()
|
||||
}
|
||||
|
||||
func (this *HTTPAccessLogService) writeAccessLogsToPolicy(pbAccessLogs []*pb.HTTPAccessLog) error {
|
||||
|
||||
Reference in New Issue
Block a user