Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/traffic/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,20 @@ func (db *DB) GetStats(deploymentName string, since time.Duration) (*TrafficStat
}
}

// Top paths
// Top paths with deployment context
rows, err = db.conn.Query(`
SELECT request_path, COUNT(*) as cnt, AVG(response_time_ms) as avg_time,
SELECT deployment_name, request_path, COUNT(*) as cnt, AVG(response_time_ms) as avg_time,
SUM(CASE WHEN status_code >= 400 THEN 1 ELSE 0 END) as errors
FROM traffic_logs
WHERE created_at >= ?`+deploymentFilter+`
GROUP BY request_path
ORDER BY cnt DESC
GROUP BY deployment_name, request_path
ORDER BY avg_time DESC
LIMIT 10`, args...)
if err == nil {
defer rows.Close()
for rows.Next() {
var p PathStats
if err := rows.Scan(&p.Path, &p.RequestCount, &p.AvgTimeMs, &p.ErrorCount); err == nil {
if err := rows.Scan(&p.Deployment, &p.Path, &p.RequestCount, &p.AvgTimeMs, &p.ErrorCount); err == nil {
stats.TopPaths = append(stats.TopPaths, p)
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/traffic/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type TrafficStats struct {

type PathStats struct {
Path string `json:"path"`
Deployment string `json:"deployment"`
RequestCount int64 `json:"request_count"`
AvgTimeMs float64 `json:"avg_time_ms"`
ErrorCount int64 `json:"error_count"`
Expand Down
Loading