feat(home): implement count for home auth dispatch requests and enable usage statistics
- Added `count` attribute to `homeAuthCount` requests to improve home message batching. - Enabled usage statistics for home mode by default and added config-level enforcement. - Adjusted failure logging to include detailed metadata in `UsageReporter`. - Updated multiple executors to pass error details to `PublishFailure` for better debugging. - Enhanced unit tests to validate `count` behavior and usage statistics enforcement across components.
This commit is contained in:
@@ -66,6 +66,7 @@ func (p *usageQueuePlugin) HandleUsage(ctx context.Context, record coreusage.Rec
|
||||
if !failed {
|
||||
failed = !resolveSuccess(ctx)
|
||||
}
|
||||
fail := resolveFail(ctx, record, failed)
|
||||
|
||||
detail := requestDetail{
|
||||
Timestamp: timestamp,
|
||||
@@ -74,6 +75,7 @@ func (p *usageQueuePlugin) HandleUsage(ctx context.Context, record coreusage.Rec
|
||||
AuthIndex: record.AuthIndex,
|
||||
Tokens: tokens,
|
||||
Failed: failed,
|
||||
Fail: fail,
|
||||
}
|
||||
|
||||
payload, err := json.Marshal(queuedUsageDetail{
|
||||
@@ -110,6 +112,7 @@ type requestDetail struct {
|
||||
AuthIndex string `json:"auth_index"`
|
||||
Tokens tokenStats `json:"tokens"`
|
||||
Failed bool `json:"failed"`
|
||||
Fail failDetail `json:"fail"`
|
||||
}
|
||||
|
||||
type tokenStats struct {
|
||||
@@ -120,6 +123,28 @@ type tokenStats struct {
|
||||
TotalTokens int64 `json:"total_tokens"`
|
||||
}
|
||||
|
||||
type failDetail struct {
|
||||
StatusCode int `json:"status_code"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
func resolveFail(ctx context.Context, record coreusage.Record, failed bool) failDetail {
|
||||
fail := failDetail{
|
||||
StatusCode: record.Fail.StatusCode,
|
||||
Body: strings.TrimSpace(record.Fail.Body),
|
||||
}
|
||||
if !failed {
|
||||
return failDetail{StatusCode: 200}
|
||||
}
|
||||
if fail.StatusCode <= 0 {
|
||||
fail.StatusCode = internallogging.GetResponseStatus(ctx)
|
||||
}
|
||||
if fail.StatusCode <= 0 {
|
||||
fail.StatusCode = 500
|
||||
}
|
||||
return fail
|
||||
}
|
||||
|
||||
func resolveSuccess(ctx context.Context) bool {
|
||||
status := internallogging.GetResponseStatus(ctx)
|
||||
if status == 0 {
|
||||
|
||||
Reference in New Issue
Block a user