forked from mtusi2026/mtusi2026lab6
feat(lab6): add observability and SLO burn-rate alerts
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *PostgreSQLStore) AttachmentQueueStats(
|
||||
ctx context.Context,
|
||||
now time.Time,
|
||||
) (int64, float64, error) {
|
||||
queryContext, cancel := s.withTimeout(ctx)
|
||||
defer cancel()
|
||||
var depth int64
|
||||
var oldestAge float64
|
||||
err := s.pool.QueryRow(queryContext, `
|
||||
SELECT
|
||||
COUNT(*),
|
||||
COALESCE(EXTRACT(EPOCH FROM ($1::timestamptz - MIN(created_at))), 0)
|
||||
FROM attachment_jobs
|
||||
WHERE status = 'queued'
|
||||
`, now).Scan(&depth, &oldestAge)
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("read attachment queue stats: %w", err)
|
||||
}
|
||||
if oldestAge < 0 {
|
||||
oldestAge = 0
|
||||
}
|
||||
return depth, oldestAge, nil
|
||||
}
|
||||
Reference in New Issue
Block a user