feat(web): console pages for monitors, incidents and notification channels
The dashboard lists monitors with status, latency and 24-hour uptime bars rendered as SVG on the server; monitor pages add 90-day uptime, latency and recent checks; an editor shows the settings of the selected check type. Closes #17 Closes #19 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
9a050ea712
commit
b831478143
18 files changed
+4268
-323
No files matched your search
@@ -12,6 +12,95 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const dailyBuckets = `-- name: DailyBuckets :many
|
||||
SELECT bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count
|
||||
FROM check_results_1d
|
||||
WHERE org_id = $1 AND monitor_id = $2 AND bucket >= $3
|
||||
GROUP BY bucket
|
||||
ORDER BY bucket
|
||||
`
|
||||
|
||||
type DailyBucketsParams struct {
|
||||
OrgID uuid.UUID
|
||||
MonitorID uuid.UUID
|
||||
Bucket interface{}
|
||||
}
|
||||
|
||||
type DailyBucketsRow struct {
|
||||
Bucket time.Time
|
||||
Total int64
|
||||
OkCount int64
|
||||
}
|
||||
|
||||
func (q *Queries) DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error) {
|
||||
rows, err := q.db.Query(ctx, dailyBuckets, arg.OrgID, arg.MonitorID, arg.Bucket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []DailyBucketsRow{}
|
||||
for rows.Next() {
|
||||
var i DailyBucketsRow
|
||||
if err := rows.Scan(&i.Bucket, &i.Total, &i.OkCount); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const hourlyBuckets = `-- name: HourlyBuckets :many
|
||||
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count,
|
||||
(sum(avg_latency_ms * total) / nullif(sum(total), 0))::real AS avg_latency_ms
|
||||
FROM check_results_1h
|
||||
WHERE org_id = $1 AND bucket >= $2
|
||||
GROUP BY monitor_id, bucket
|
||||
ORDER BY monitor_id, bucket
|
||||
`
|
||||
|
||||
type HourlyBucketsParams struct {
|
||||
OrgID uuid.UUID
|
||||
Bucket interface{}
|
||||
}
|
||||
|
||||
type HourlyBucketsRow struct {
|
||||
MonitorID uuid.UUID
|
||||
Bucket time.Time
|
||||
Total int64
|
||||
OkCount int64
|
||||
AvgLatencyMs float32
|
||||
}
|
||||
|
||||
// Per monitor and hour since $2, across all regions.
|
||||
func (q *Queries) HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error) {
|
||||
rows, err := q.db.Query(ctx, hourlyBuckets, arg.OrgID, arg.Bucket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []HourlyBucketsRow{}
|
||||
for rows.Next() {
|
||||
var i HourlyBucketsRow
|
||||
if err := rows.Scan(
|
||||
&i.MonitorID,
|
||||
&i.Bucket,
|
||||
&i.Total,
|
||||
&i.OkCount,
|
||||
&i.AvgLatencyMs,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
type InsertCheckResultsParams struct {
|
||||
Time time.Time
|
||||
OrgID uuid.UUID
|
||||
|
||||
@@ -274,6 +274,37 @@ func (q *Queries) MarkNotificationSent(ctx context.Context, id uuid.UUID) error
|
||||
return err
|
||||
}
|
||||
|
||||
const monitorIncidents = `-- name: MonitorIncidents :many
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents WHERE monitor_id = $1 ORDER BY started_at DESC LIMIT 20
|
||||
`
|
||||
|
||||
func (q *Queries) MonitorIncidents(ctx context.Context, monitorID uuid.UUID) ([]Incident, error) {
|
||||
rows, err := q.db.Query(ctx, monitorIncidents, monitorID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Incident{}
|
||||
for rows.Next() {
|
||||
var i Incident
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.MonitorID,
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const notificationDetails = `-- name: NotificationDetails :many
|
||||
SELECT n.id, n.org_id, n.event, n.attempts,
|
||||
c.type AS channel_type, c.config AS channel_config, c.id AS channel_id,
|
||||
@@ -374,6 +405,37 @@ func (q *Queries) OpenIncident(ctx context.Context, arg OpenIncidentParams) (Inc
|
||||
return i, err
|
||||
}
|
||||
|
||||
const openIncidents = `-- name: OpenIncidents :many
|
||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents WHERE resolved_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
|
||||
rows, err := q.db.Query(ctx, openIncidents)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Incident{}
|
||||
for rows.Next() {
|
||||
var i Incident
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OrgID,
|
||||
&i.MonitorID,
|
||||
&i.StartedAt,
|
||||
&i.ResolvedAt,
|
||||
&i.Cause,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const resolveIncident = `-- name: ResolveIncident :one
|
||||
UPDATE incidents SET resolved_at = $1
|
||||
WHERE monitor_id = $2 AND resolved_at IS NULL
|
||||
|
||||
@@ -35,6 +35,7 @@ type Querier interface {
|
||||
CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error)
|
||||
CreateSSOProvider(ctx context.Context, arg CreateSSOProviderParams) (SsoProvider, error)
|
||||
CreateUser(ctx context.Context, arg CreateUserParams) (User, error)
|
||||
DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error)
|
||||
DeleteAPIToken(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
DeleteAgent(ctx context.Context, arg DeleteAgentParams) (int64, error)
|
||||
DeleteAssignment(ctx context.Context, id uuid.UUID) (int64, error)
|
||||
@@ -71,6 +72,8 @@ type Querier interface {
|
||||
GetSSOProvider(ctx context.Context, id uuid.UUID) (SsoProvider, error)
|
||||
GetUser(ctx context.Context, id uuid.UUID) (User, error)
|
||||
GetUserByEmail(ctx context.Context, email string) (User, error)
|
||||
// Per monitor and hour since $2, across all regions.
|
||||
HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error)
|
||||
// check_results and its aggregates have no row-level security (see
|
||||
// migration 00013). Every query here must filter by org_id.
|
||||
InsertCheckResults(ctx context.Context, arg []InsertCheckResultsParams) (int64, error)
|
||||
@@ -109,6 +112,7 @@ type Querier interface {
|
||||
MarkNotificationSent(ctx context.Context, id uuid.UUID) error
|
||||
// Every role a member holds, with the scope it applies to.
|
||||
MemberGrants(ctx context.Context, arg MemberGrantsParams) ([]MemberGrantsRow, error)
|
||||
MonitorIncidents(ctx context.Context, monitorID uuid.UUID) ([]Incident, error)
|
||||
MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
|
||||
// System scope: monitors to hand to a checker of region, skipping ones that
|
||||
// were disabled, deleted or moved out of the region since dispatch. An
|
||||
@@ -120,6 +124,7 @@ type Querier interface {
|
||||
// System scope.
|
||||
NotificationDetails(ctx context.Context, ids []uuid.UUID) ([]NotificationDetailsRow, error)
|
||||
OpenIncident(ctx context.Context, arg OpenIncidentParams) (Incident, error)
|
||||
OpenIncidents(ctx context.Context) ([]Incident, error)
|
||||
OrgIDBySlug(ctx context.Context, slug string) (uuid.UUID, error)
|
||||
RecentResults(ctx context.Context, arg RecentResultsParams) ([]RecentResultsRow, error)
|
||||
RemoveMembership(ctx context.Context, arg RemoveMembershipParams) (int64, error)
|
||||
|
||||
@@ -32,3 +32,19 @@ SELECT DISTINCT ON (region) region, ok, error
|
||||
FROM check_results
|
||||
WHERE org_id = $1 AND monitor_id = $2 AND time > now() - interval '1 day'
|
||||
ORDER BY region, time DESC;
|
||||
|
||||
-- name: HourlyBuckets :many
|
||||
-- Per monitor and hour since $2, across all regions.
|
||||
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count,
|
||||
(sum(avg_latency_ms * total) / nullif(sum(total), 0))::real AS avg_latency_ms
|
||||
FROM check_results_1h
|
||||
WHERE org_id = $1 AND bucket >= $2
|
||||
GROUP BY monitor_id, bucket
|
||||
ORDER BY monitor_id, bucket;
|
||||
|
||||
-- name: DailyBuckets :many
|
||||
SELECT bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count
|
||||
FROM check_results_1d
|
||||
WHERE org_id = $1 AND monitor_id = $2 AND bucket >= $3
|
||||
GROUP BY bucket
|
||||
ORDER BY bucket;
|
||||
@@ -77,3 +77,9 @@ SELECT * FROM notification_channels ORDER BY name;
|
||||
|
||||
-- name: DeleteChannel :execrows
|
||||
DELETE FROM notification_channels WHERE id = $1;
|
||||
|
||||
-- name: OpenIncidents :many
|
||||
SELECT * FROM incidents WHERE resolved_at IS NULL;
|
||||
|
||||
-- name: MonitorIncidents :many
|
||||
SELECT * FROM incidents WHERE monitor_id = $1 ORDER BY started_at DESC LIMIT 20;
|
||||
Reference in new issue
Block a user