Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
967e2587
Commit
967e2587
authored
Jan 14, 2026
by
IanShaw027
Browse files
refactor(ops): 重构ops核心服务层代码
parent
18268381
Changes
6
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/ops_models.go
View file @
967e2587
...
...
@@ -22,14 +22,13 @@ type OpsErrorLog struct {
Platform
string
`json:"platform"`
Model
string
`json:"model"`
LatencyMs
*
int
`json:"latency_ms"`
IsRetryable
bool
`json:"is_retryable"`
RetryCount
int
`json:"retry_count"`
Resolved
bool
`json:"resolved"`
ResolvedAt
*
time
.
Time
`json:"resolved_at"`
ResolvedByUserID
*
int64
`json:"resolved_by_user_id"`
ResolvedByUserName
string
`json:"resolved_by_user_name"`
ResolvedRetryID
*
int64
`json:"resolved_retry_id"`
ResolvedStatusRaw
string
`json:"-"`
...
...
@@ -37,10 +36,13 @@ type OpsErrorLog struct {
RequestID
string
`json:"request_id"`
Message
string
`json:"message"`
UserID
*
int64
`json:"user_id"`
APIKeyID
*
int64
`json:"api_key_id"`
AccountID
*
int64
`json:"account_id"`
GroupID
*
int64
`json:"group_id"`
UserID
*
int64
`json:"user_id"`
UserEmail
string
`json:"user_email"`
APIKeyID
*
int64
`json:"api_key_id"`
AccountID
*
int64
`json:"account_id"`
AccountName
string
`json:"account_name"`
GroupID
*
int64
`json:"group_id"`
GroupName
string
`json:"group_name"`
ClientIP
*
string
`json:"client_ip"`
RequestPath
string
`json:"request_path"`
...
...
@@ -110,6 +112,7 @@ type OpsRetryAttempt struct {
SourceErrorID
int64
`json:"source_error_id"`
Mode
string
`json:"mode"`
PinnedAccountID
*
int64
`json:"pinned_account_id"`
PinnedAccountName
string
`json:"pinned_account_name"`
Status
string
`json:"status"`
StartedAt
*
time
.
Time
`json:"started_at"`
...
...
@@ -121,6 +124,7 @@ type OpsRetryAttempt struct {
HTTPStatusCode
*
int
`json:"http_status_code"`
UpstreamRequestID
*
string
`json:"upstream_request_id"`
UsedAccountID
*
int64
`json:"used_account_id"`
UsedAccountName
string
`json:"used_account_name"`
ResponsePreview
*
string
`json:"response_preview"`
ResponseTruncated
*
bool
`json:"response_truncated"`
...
...
backend/internal/service/ops_port.go
View file @
967e2587
...
...
@@ -98,7 +98,6 @@ type OpsInsertErrorLogInput struct {
// It is set by OpsService.RecordError before persisting.
UpstreamErrorsJSON
*
string
DurationMs
*
int
TimeToFirstTokenMs
*
int64
RequestBodyJSON
*
string
// sanitized json string (not raw bytes)
...
...
backend/internal/service/ops_service.go
View file @
967e2587
...
...
@@ -236,7 +236,68 @@ func (s *OpsService) GetErrorLogs(ctx context.Context, filter *OpsErrorLogFilter
if
s
.
opsRepo
==
nil
{
return
&
OpsErrorLogList
{
Errors
:
[]
*
OpsErrorLog
{},
Total
:
0
,
Page
:
1
,
PageSize
:
20
},
nil
}
return
s
.
opsRepo
.
ListErrorLogs
(
ctx
,
filter
)
result
,
err
:=
s
.
opsRepo
.
ListErrorLogs
(
ctx
,
filter
)
if
err
!=
nil
{
log
.
Printf
(
"[Ops] GetErrorLogs failed: %v"
,
err
)
return
nil
,
err
}
// Apply error filtering based on settings (for historical data)
result
=
s
.
filterErrorLogsBySettings
(
ctx
,
result
)
return
result
,
nil
}
// filterErrorLogsBySettings filters error logs based on advanced settings.
// This ensures that historical errors are also filtered when viewing the dashboard.
func
(
s
*
OpsService
)
filterErrorLogsBySettings
(
ctx
context
.
Context
,
result
*
OpsErrorLogList
)
*
OpsErrorLogList
{
if
result
==
nil
||
len
(
result
.
Errors
)
==
0
{
return
result
}
settings
,
err
:=
s
.
GetOpsAdvancedSettings
(
ctx
)
if
err
!=
nil
||
settings
==
nil
{
// If we can't get settings, return unfiltered (fail open)
return
result
}
filtered
:=
make
([]
*
OpsErrorLog
,
0
,
len
(
result
.
Errors
))
for
_
,
errLog
:=
range
result
.
Errors
{
if
shouldFilterErrorLog
(
settings
,
errLog
)
{
continue
// Skip this error
}
filtered
=
append
(
filtered
,
errLog
)
}
// Update total count to reflect filtered results
result
.
Errors
=
filtered
result
.
Total
=
len
(
filtered
)
return
result
}
// shouldFilterErrorLog determines if an error log should be filtered based on settings.
func
shouldFilterErrorLog
(
settings
*
OpsAdvancedSettings
,
errLog
*
OpsErrorLog
)
bool
{
if
settings
==
nil
||
errLog
==
nil
{
return
false
}
msgLower
:=
strings
.
ToLower
(
errLog
.
Message
)
// Check if count_tokens errors should be ignored
if
settings
.
IgnoreCountTokensErrors
&&
strings
.
Contains
(
errLog
.
RequestPath
,
"/count_tokens"
)
{
return
true
}
// Check if context canceled errors should be ignored
if
settings
.
IgnoreContextCanceled
&&
strings
.
Contains
(
msgLower
,
"context canceled"
)
{
return
true
}
// Check if "no available accounts" errors should be ignored
if
settings
.
IgnoreNoAvailableAccounts
&&
strings
.
Contains
(
msgLower
,
"no available accounts"
)
{
return
true
}
return
false
}
func
(
s
*
OpsService
)
GetErrorLogByID
(
ctx
context
.
Context
,
id
int64
)
(
*
OpsErrorLogDetail
,
error
)
{
...
...
backend/internal/service/ops_settings.go
View file @
967e2587
...
...
@@ -368,9 +368,11 @@ func defaultOpsAdvancedSettings() *OpsAdvancedSettings {
Aggregation
:
OpsAggregationSettings
{
AggregationEnabled
:
false
,
},
IgnoreCountTokensErrors
:
false
,
AutoRefreshEnabled
:
false
,
AutoRefreshIntervalSec
:
30
,
IgnoreCountTokensErrors
:
false
,
IgnoreContextCanceled
:
true
,
// Default to true - client disconnects are not errors
IgnoreNoAvailableAccounts
:
false
,
// Default to false - this is a real routing issue
AutoRefreshEnabled
:
false
,
AutoRefreshIntervalSec
:
30
,
}
}
...
...
backend/internal/service/ops_settings_models.go
View file @
967e2587
...
...
@@ -81,6 +81,8 @@ type OpsAdvancedSettings struct {
DataRetention
OpsDataRetentionSettings
`json:"data_retention"`
Aggregation
OpsAggregationSettings
`json:"aggregation"`
IgnoreCountTokensErrors
bool
`json:"ignore_count_tokens_errors"`
IgnoreContextCanceled
bool
`json:"ignore_context_canceled"`
IgnoreNoAvailableAccounts
bool
`json:"ignore_no_available_accounts"`
AutoRefreshEnabled
bool
`json:"auto_refresh_enabled"`
AutoRefreshIntervalSec
int
`json:"auto_refresh_interval_seconds"`
}
...
...
backend/internal/service/ops_upstream_context.go
View file @
967e2587
...
...
@@ -38,8 +38,9 @@ type OpsUpstreamErrorEvent struct {
AtUnixMs
int64
`json:"at_unix_ms,omitempty"`
// Context
Platform
string
`json:"platform,omitempty"`
AccountID
int64
`json:"account_id,omitempty"`
Platform
string
`json:"platform,omitempty"`
AccountID
int64
`json:"account_id,omitempty"`
AccountName
string
`json:"account_name,omitempty"`
// Outcome
UpstreamStatusCode
int
`json:"upstream_status_code,omitempty"`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment