日常查询由mysql改为clickhouse

This commit is contained in:
robin
2026-02-08 02:00:51 +08:00
parent bc223fd1aa
commit b7388d83b0
43 changed files with 657 additions and 353 deletions

View File

@@ -144,6 +144,9 @@ func (this *HTTPAccessLogService) listHTTPAccessLogsFromClickHouse(ctx context.C
NodeId: req.NodeId,
ClusterId: req.NodeClusterId,
LastRequestId: req.RequestId,
Keyword: req.Keyword,
Ip: req.Ip,
Domain: req.Domain,
}
if req.ServerId > 0 {
f.ServerIds = []int64{req.ServerId}
@@ -216,7 +219,10 @@ func (this *HTTPAccessLogService) listHTTPAccessLogsFromClickHouse(ctx context.C
}
}
hasMore := nextCursor != ""
hasMore := false
if !req.Reverse {
hasMore = nextCursor != ""
}
return &pb.ListHTTPAccessLogsResponse{
HttpAccessLogs: result,
AccessLogs: result,
@@ -233,6 +239,28 @@ func (this *HTTPAccessLogService) FindHTTPAccessLog(ctx context.Context, req *pb
return nil, err
}
// 优先从 ClickHouse 查询
store := clickhouse.NewLogsIngestStore()
if store.Client().IsConfigured() {
row, err := store.FindByTraceId(ctx, req.RequestId)
if err != nil {
return nil, err
}
if row != nil {
// 检查权限
if userId > 0 {
var tx = this.NullTx()
err = models.SharedServerDAO.CheckUserServer(tx, userId, int64(row.ServerId))
if err != nil {
return nil, err
}
}
a := clickhouse.RowToPB(row)
return &pb.FindHTTPAccessLogResponse{HttpAccessLog: a}, nil
}
}
// 如果 ClickHouse 未配置或未找到,则回退到 MySQL
var tx = this.NullTx()
accessLog, err := models.SharedHTTPAccessLogDAO.FindAccessLogWithRequestId(tx, req.RequestId)