refactor: clean up project structure
- Remove old review reports (keep latest only) - Move docs/ to deploy/docs-backup/ - Move performance-testing/ to deploy/ - Clean up test output files - Organize root directory
This commit is contained in:
@@ -80,6 +80,9 @@ func (f fakeAPIKeyRepo) ClearGroupIDByGroupID(ctx context.Context, groupID int64
|
||||
func (f fakeAPIKeyRepo) CountByGroupID(ctx context.Context, groupID int64) (int64, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
func (f fakeAPIKeyRepo) CountActiveByGroupID(ctx context.Context, groupID int64) (int64, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
func (f fakeAPIKeyRepo) ListKeysByUserID(ctx context.Context, userID int64) ([]string, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
@@ -601,6 +601,9 @@ func (r *stubApiKeyRepo) ResetRateLimitWindows(ctx context.Context, id int64) er
|
||||
func (r *stubApiKeyRepo) GetRateLimitData(ctx context.Context, id int64) (*service.APIKeyRateLimitData, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (r *stubApiKeyRepo) CountActiveByGroupID(ctx context.Context, groupID int64) (int64, error) {
|
||||
return 0, errors.New("not implemented")
|
||||
}
|
||||
|
||||
type stubUserSubscriptionRepo struct {
|
||||
getActive func(ctx context.Context, userID, groupID int64) (*service.UserSubscription, error)
|
||||
|
||||
47
backend/internal/server/middleware/metrics.go
Normal file
47
backend/internal/server/middleware/metrics.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Package middleware provides HTTP middleware for metrics collection.
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/Wei-Shaw/sub2api/internal/pkg/metrics"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// PrometheusMetrics returns a Gin middleware that records Prometheus metrics
|
||||
func PrometheusMetrics() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
path := c.FullPath()
|
||||
if path == "" {
|
||||
path = "unknown"
|
||||
}
|
||||
|
||||
c.Next()
|
||||
|
||||
duration := time.Since(start).Seconds()
|
||||
status := strconv.Itoa(c.Writer.Status())
|
||||
|
||||
// Record HTTP metrics
|
||||
metrics.RecordHTTPRequest(c.Request.Method, path, status, duration)
|
||||
}
|
||||
}
|
||||
|
||||
// GatewayMetrics returns a Gin middleware that records gateway-specific metrics
|
||||
func GatewayMetrics() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
platform := c.GetString("platform")
|
||||
model := c.GetString("model")
|
||||
|
||||
c.Next()
|
||||
|
||||
duration := time.Since(start).Seconds()
|
||||
status := strconv.Itoa(c.Writer.Status())
|
||||
|
||||
if platform != "" {
|
||||
metrics.RecordGatewayRequest(platform, model, status, duration)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user