mirror of
https://github.com/labring/sealos.git
synced 2026-09-21 05:44:43 +08:00
feat: global log index (#5430)
This commit is contained in:
@@ -72,6 +72,11 @@ func CreateLogIndexes(db *gorm.DB) error {
|
||||
indexes = []string{
|
||||
// used by global search logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_model_reqat ON logs (model, request_at)",
|
||||
// used by global search logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_channel_reqat ON logs (channel_id, request_at)",
|
||||
// used by global search logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_channel_model_reqat ON logs (channel_id, model, request_at)",
|
||||
|
||||
// global day indexes, used by global dashboard
|
||||
"CREATE INDEX IF NOT EXISTS idx_model_reqat_truncday ON logs (model, request_at, timestamp_trunc_by_day)",
|
||||
// global hour indexes, used by global dashboard
|
||||
@@ -98,20 +103,25 @@ func CreateLogIndexes(db *gorm.DB) error {
|
||||
} else {
|
||||
indexes = []string{
|
||||
// used by global search logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_model_reqat ON logs (model, request_at) INCLUDE (code, used_amount, total_tokens)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_model_reqat ON logs (model, request_at) INCLUDE (code, used_amount, total_tokens, request_id)",
|
||||
// used by global search logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_channel_reqat ON logs (channel_id, request_at) INCLUDE (code, used_amount, total_tokens, request_id)",
|
||||
// used by global search logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_channel_model_reqat ON logs (channel_id, model, request_at) INCLUDE (code, used_amount, total_tokens, request_id)",
|
||||
|
||||
// global day indexes, used by global dashboard
|
||||
"CREATE INDEX IF NOT EXISTS idx_model_reqat_truncday ON logs (model, request_at, timestamp_trunc_by_day) INCLUDE (code, used_amount, total_tokens)",
|
||||
// global hour indexes, used by global dashboard
|
||||
"CREATE INDEX IF NOT EXISTS idx_model_reqat_trunchour ON logs (model, request_at, timestamp_trunc_by_hour) INCLUDE (code, used_amount, total_tokens)",
|
||||
|
||||
// used by search group logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_group_token_reqat ON logs (group_id, token_name, request_at) INCLUDE (code, used_amount, total_tokens)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_group_token_reqat ON logs (group_id, token_name, request_at) INCLUDE (code, used_amount, total_tokens, request_id)",
|
||||
// used by search group logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_group_token_reqat ON logs (group_id, token_name, request_at) INCLUDE (code, used_amount, total_tokens)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_group_token_reqat ON logs (group_id, token_name, request_at) INCLUDE (code, used_amount, total_tokens, request_id)",
|
||||
// used by search group logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_group_model_reqat ON logs (group_id, model, request_at) INCLUDE (code, used_amount, total_tokens)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_group_model_reqat ON logs (group_id, model, request_at) INCLUDE (code, used_amount, total_tokens, request_id)",
|
||||
// used by search group logs
|
||||
"CREATE INDEX IF NOT EXISTS idx_group_token_model_reqat ON logs (group_id, token_name, model, request_at) INCLUDE (code, used_amount, total_tokens)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_group_token_model_reqat ON logs (group_id, token_name, model, request_at) INCLUDE (code, used_amount, total_tokens, request_id)",
|
||||
|
||||
// day indexes, used by dashboard
|
||||
"CREATE INDEX IF NOT EXISTS idx_group_reqat_truncday ON logs (group_id, request_at, timestamp_trunc_by_day) INCLUDE (code, used_amount, total_tokens)",
|
||||
@@ -580,22 +590,13 @@ func buildSearchLogsQuery(
|
||||
if requestID != "" {
|
||||
tx = tx.Where("request_id = ?", requestID)
|
||||
}
|
||||
|
||||
if mode != 0 {
|
||||
tx = tx.Where("mode = ?", mode)
|
||||
}
|
||||
if endpoint != "" {
|
||||
tx = tx.Where("endpoint = ?", endpoint)
|
||||
}
|
||||
if tokenID != 0 {
|
||||
tx = tx.Where("token_id = ?", tokenID)
|
||||
}
|
||||
if channelID != 0 {
|
||||
tx = tx.Where("channel_id = ?", channelID)
|
||||
}
|
||||
if ip != "" {
|
||||
tx = tx.Where("ip = ?", ip)
|
||||
}
|
||||
|
||||
switch codeType {
|
||||
case CodeTypeSuccess:
|
||||
tx = tx.Where("code = 200")
|
||||
@@ -603,6 +604,17 @@ func buildSearchLogsQuery(
|
||||
tx = tx.Where("code != 200")
|
||||
}
|
||||
|
||||
if ip != "" {
|
||||
tx = tx.Where("ip = ?", ip)
|
||||
}
|
||||
|
||||
if mode != 0 {
|
||||
tx = tx.Where("mode = ?", mode)
|
||||
}
|
||||
if endpoint != "" {
|
||||
tx = tx.Where("endpoint = ?", endpoint)
|
||||
}
|
||||
|
||||
// Handle keyword search for zero value fields
|
||||
if keyword != "" {
|
||||
var conditions []string
|
||||
|
||||
Reference in New Issue
Block a user