Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1138d555aa | ||
|
|
2a440b9c5e | ||
|
|
b88ed4bfd2 | ||
|
|
1dcb1531d0 | ||
|
|
87918eff80 | ||
|
|
963c677e1c | ||
|
|
a6bc50b39d | ||
|
|
15aad53d3d | ||
|
|
b0d4bcc002 | ||
|
|
ca852c8299 | ||
|
|
4cde0f7e56 | ||
|
|
feaa1e930d |
No files matched your search
@@ -89,6 +89,7 @@ func run(log *slog.Logger, level *slog.LevelVar, args []string) error {
|
|||||||
health.Register(r)
|
health.Register(r)
|
||||||
r.StaticFS("/static", web.Static())
|
r.StaticFS("/static", web.Static())
|
||||||
srv.Mount(r)
|
srv.Mount(r)
|
||||||
|
srv.EndLongPollsOn(health.Draining())
|
||||||
go srv.RunScheduler(ctx)
|
go srv.RunScheduler(ctx)
|
||||||
go srv.RunNotifier(ctx)
|
go srv.RunNotifier(ctx)
|
||||||
go srv.RunHousekeeping(ctx)
|
go srv.RunHousekeeping(ctx)
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ metadata:
|
|||||||
app.kubernetes.io/component: api
|
app.kubernetes.io/component: api
|
||||||
spec:
|
spec:
|
||||||
replicas: {{ .Values.api.replicas }}
|
replicas: {{ .Values.api.replicas }}
|
||||||
|
# Roll one pod at a time without ever having fewer ready than wanted;
|
||||||
|
# a new pod serves a few seconds before an old one goes, so the ingress
|
||||||
|
# has picked it up.
|
||||||
|
strategy:
|
||||||
|
type: RollingUpdate
|
||||||
|
rollingUpdate:
|
||||||
|
maxUnavailable: 0
|
||||||
|
maxSurge: 1
|
||||||
|
minReadySeconds: 5
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
{{- include "uptimesebi.selector" (list . "api") | nindent 6 }}
|
{{- include "uptimesebi.selector" (list . "api") | nindent 6 }}
|
||||||
|
|||||||
@@ -9,6 +9,15 @@ metadata:
|
|||||||
app.kubernetes.io/component: statuspage
|
app.kubernetes.io/component: statuspage
|
||||||
spec:
|
spec:
|
||||||
replicas: {{ .Values.statuspage.replicas }}
|
replicas: {{ .Values.statuspage.replicas }}
|
||||||
|
# Roll one pod at a time without ever having fewer ready than wanted;
|
||||||
|
# a new pod serves a few seconds before an old one goes, so the ingress
|
||||||
|
# has picked it up.
|
||||||
|
strategy:
|
||||||
|
type: RollingUpdate
|
||||||
|
rollingUpdate:
|
||||||
|
maxUnavailable: 0
|
||||||
|
maxSurge: 1
|
||||||
|
minReadySeconds: 5
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
{{- include "uptimesebi.selector" (list . "statuspage") | nindent 6 }}
|
{{- include "uptimesebi.selector" (list . "statuspage") | nindent 6 }}
|
||||||
|
|||||||
+25
-5
@@ -32,7 +32,9 @@ const (
|
|||||||
ctxAgent = "api.agent"
|
ctxAgent = "api.agent"
|
||||||
ctxInstance = "api.instance"
|
ctxInstance = "api.instance"
|
||||||
maxJobWait = 25 * time.Second
|
maxJobWait = 25 * time.Second
|
||||||
maxJobBatch = 200
|
// drainingPollHold is how long a draining instance still holds a poll.
|
||||||
|
drainingPollHold = time.Second
|
||||||
|
maxJobBatch = 200
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) mountAgentAPI(r gin.IRouter) {
|
func (s *Server) mountAgentAPI(r gin.IRouter) {
|
||||||
@@ -197,8 +199,27 @@ func (s *Server) agentJobs(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
wait := min(time.Duration(req.WaitMS)*time.Millisecond, maxJobWait)
|
wait := min(time.Duration(req.WaitMS)*time.Millisecond, maxJobWait)
|
||||||
entries, err := s.sched.Take(ctx, instance, min(req.Max, maxJobBatch), wait)
|
// A draining instance ends long polls within a second or so, empty, so
|
||||||
if err != nil && ctx.Err() == nil {
|
// the shutdown is not held up and the checker's next poll reaches
|
||||||
|
// another instance. It still holds them that second, so checkers that
|
||||||
|
// poll again at once do not spin against it.
|
||||||
|
pollCtx, stop := context.WithCancel(ctx)
|
||||||
|
defer stop()
|
||||||
|
if s.draining != nil {
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-s.draining:
|
||||||
|
select {
|
||||||
|
case <-time.After(drainingPollHold):
|
||||||
|
case <-pollCtx.Done():
|
||||||
|
}
|
||||||
|
stop()
|
||||||
|
case <-pollCtx.Done():
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
entries, err := s.sched.Take(pollCtx, instance, min(req.Max, maxJobBatch), wait)
|
||||||
|
if err != nil && pollCtx.Err() == nil {
|
||||||
internalError(c, err)
|
internalError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -316,8 +337,7 @@ func (s *Server) agentResults(c *gin.Context) {
|
|||||||
if len(params) == 0 {
|
if len(params) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_, err = q.InsertCheckResults(ctx, params)
|
return insertResults(ctx, q, params)
|
||||||
return err
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Unclaimed, the checker's retry is stored instead.
|
// Unclaimed, the checker's retry is stored instead.
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ var endpoints = []endpoint{
|
|||||||
{method: "POST", path: "/api/v1/org/monitors", tag: "Monitors", summary: "Create a monitor",
|
{method: "POST", path: "/api/v1/org/monitors", tag: "Monitors", summary: "Create a monitor",
|
||||||
description: "`type` is one of http, json, prometheus, tcp, tls, dns, icmp, postgres, mysql, mssql, mongodb, redis, mqtt, kafka, rabbitmq, grpc, smtp, radius, snmp, steam, minecraft, docker, heartbeat or alertmanager (GET /api/v1/org/check-types lists those offered); `config` depends on it (see HTTPConfig, JSONConfig, PrometheusConfig, DNSConfig, TLSConfig, DBConfig, BrokerConfig, GRPCConfig, SMTPConfig, RADIUSConfig, SNMPConfig, GameConfig, DockerConfig, HeartbeatConfig, AlertmanagerConfig). Passwords, RADIUS secrets and SNMP communities are stored encrypted and never returned: `secrets_set` names those set, and an update that leaves one empty keeps it. Heartbeat and alertmanager monitors take neither target nor regions; heartbeats return their `ping_url`. Omit `alert_group_ids` to assign the default alert group; an empty array disables notifications.",
|
description: "`type` is one of http, json, prometheus, tcp, tls, dns, icmp, postgres, mysql, mssql, mongodb, redis, mqtt, kafka, rabbitmq, grpc, smtp, radius, snmp, steam, minecraft, docker, heartbeat or alertmanager (GET /api/v1/org/check-types lists those offered); `config` depends on it (see HTTPConfig, JSONConfig, PrometheusConfig, DNSConfig, TLSConfig, DBConfig, BrokerConfig, GRPCConfig, SMTPConfig, RADIUSConfig, SNMPConfig, GameConfig, DockerConfig, HeartbeatConfig, AlertmanagerConfig). Passwords, RADIUS secrets and SNMP communities are stored encrypted and never returned: `secrets_set` names those set, and an update that leaves one empty keeps it. Heartbeat and alertmanager monitors take neither target nor regions; heartbeats return their `ping_url`. Omit `alert_group_ids` to assign the default alert group; an empty array disables notifications.",
|
||||||
perm: "monitors.write", req: monitorRequest{}, status: http.StatusCreated, resp: monitorView{}},
|
perm: "monitors.write", req: monitorRequest{}, status: http.StatusCreated, resp: monitorView{}},
|
||||||
|
{method: "PUT", path: "/api/v1/org/monitors/order", tag: "Monitors", summary: "Put monitors in the organization's own order", perm: "monitors.write",
|
||||||
|
description: "Positions follow the order of monitor_ids, usually the monitors of one group; the monitor list sorted by its own order shows positioned monitors first, the rest by name. Needs write access to every monitor given.",
|
||||||
|
req: monitorOrderRequest{}},
|
||||||
{method: "PUT", path: "/api/v1/org/monitors/:id", tag: "Monitors", summary: "Change a monitor", perm: "monitors.write",
|
{method: "PUT", path: "/api/v1/org/monitors/:id", tag: "Monitors", summary: "Change a monitor", perm: "monitors.write",
|
||||||
description: "Omitting alert_group_ids preserves existing assignments; an empty array removes all alert groups.",
|
description: "Omitting alert_group_ids preserves existing assignments; an empty array removes all alert groups.",
|
||||||
req: monitorRequest{}, resp: monitorView{}},
|
req: monitorRequest{}, resp: monitorView{}},
|
||||||
@@ -106,7 +109,7 @@ var endpoints = []endpoint{
|
|||||||
description: "Platform checkers serve every organization; other organizations' work appears only as a count. `recent` is paged, newest first; a page may hold fewer results than `limit` when some belong to monitors you cannot read.",
|
description: "Platform checkers serve every organization; other organizations' work appears only as a count. `recent` is paged, newest first; a page may hold fewer results than `limit` when some belong to monitors you cannot read.",
|
||||||
resp: checkerActivity{}},
|
resp: checkerActivity{}},
|
||||||
{method: "GET", path: "/api/v1/org/limits", tag: "Organization", summary: "Limits in effect for the organization and its usage",
|
{method: "GET", path: "/api/v1/org/limits", tag: "Organization", summary: "Limits in effect for the organization and its usage",
|
||||||
description: "0 means unlimited. Creating beyond a limit gives 422 monitor_limit, status_page_limit, region_limit or platform_region_limit.",
|
description: "0 means unlimited. Creating beyond a limit gives 422 monitor_limit, status_page_limit, page_monitor_limit, region_limit or platform_region_limit.",
|
||||||
resp: usageView{}},
|
resp: usageView{}},
|
||||||
{method: "GET", path: "/api/v1/org/check-types", tag: "Monitors", summary: "Monitor types members can create",
|
{method: "GET", path: "/api/v1/org/check-types", tag: "Monitors", summary: "Monitor types members can create",
|
||||||
description: "`own_checkers_only` are the types the platform's checkers do not run: monitors of them use the organization's own regions only, or 422 check_type_own_checkers_only.",
|
description: "`own_checkers_only` are the types the platform's checkers do not run: monitors of them use the organization's own regions only, or 422 check_type_own_checkers_only.",
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ var auditActions = map[string]string{
|
|||||||
"PUT /api/v1/org/policy": "org.policy_update",
|
"PUT /api/v1/org/policy": "org.policy_update",
|
||||||
"POST /api/v1/org/monitors": "monitor.create",
|
"POST /api/v1/org/monitors": "monitor.create",
|
||||||
"PUT /api/v1/org/monitors/:id": "monitor.update",
|
"PUT /api/v1/org/monitors/:id": "monitor.update",
|
||||||
|
"PUT /api/v1/org/monitors/order": "monitor.order",
|
||||||
"DELETE /api/v1/org/monitors/:id": "monitor.delete",
|
"DELETE /api/v1/org/monitors/:id": "monitor.delete",
|
||||||
"POST /api/v1/org/alertmanager/receivers": "alertmanager.receiver_create",
|
"POST /api/v1/org/alertmanager/receivers": "alertmanager.receiver_create",
|
||||||
"DELETE /api/v1/org/alertmanager/receivers/:id": "alertmanager.receiver_delete",
|
"DELETE /api/v1/org/alertmanager/receivers/:id": "alertmanager.receiver_delete",
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ func (s *Server) loadCheckerActivity(ctx context.Context, p *principal, instance
|
|||||||
a.Siblings = append(a.Siblings, sb.ID)
|
a.Siblings = append(a.Siblings, sb.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
monitors, err := q.ListMonitors(ctx)
|
monitors, err := q.ListMonitors(ctx, p.Org.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+273
-68
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -79,16 +80,23 @@ func (s *Server) dashboard(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
v.Root = buildGroupNodes(data.tree, data.rows)
|
v.Root = buildGroupNodes(data.tree, data.rows)
|
||||||
v.Empty = len(data.rows) == 0 && len(v.Root.Children) == 0
|
v.Empty = len(data.rows) == 0 && len(v.Root.Children) == 0
|
||||||
|
v.CanWrite = writableAnywhere(p, data.tree)
|
||||||
if !s.dashboardPage(c, &v, data) {
|
if !s.dashboardPage(c, &v, data) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v.CanWrite = writableAnywhere(p, data.tree)
|
if err := s.dashboardBars(c.Request.Context(), p, &v, &data); err != nil {
|
||||||
|
internalError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
v.Range = data.rng.Key
|
v.Range = data.rng.Key
|
||||||
var earliest time.Time
|
var earliest time.Time
|
||||||
for _, m := range data.byID {
|
if err := s.db.Tx(c.Request.Context(), p.scope(), func(q *store.Queries) error {
|
||||||
if f, ok := data.first[m.ID]; ok && (earliest.IsZero() || f.Before(earliest)) {
|
var err error
|
||||||
earliest = f
|
earliest, err = earliestData(c.Request.Context(), q, p.Org.ID, data.now)
|
||||||
}
|
return err
|
||||||
|
}); err != nil {
|
||||||
|
internalError(c, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
v.Ranges = rangeOptions(c, data.rng, earliest, data.now)
|
v.Ranges = rangeOptions(c, data.rng, earliest, data.now)
|
||||||
for _, m := range data.rows {
|
for _, m := range data.rows {
|
||||||
@@ -97,6 +105,7 @@ func (s *Server) dashboard(c *gin.Context) {
|
|||||||
v.Unchecked++
|
v.Unchecked++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
v.Filters = statusFilters(c, v.Counts, v.Filter)
|
||||||
for id, since := range s.regionsWithoutChecker(c.Request.Context(), data.usedRegions) {
|
for id, since := range s.regionsWithoutChecker(c.Request.Context(), data.usedRegions) {
|
||||||
v.DeadRegions = append(v.DeadRegions, web.DeadRegion{Name: data.regionOf[id].Name, Since: since.Local().Format("2006-01-02 15:04")})
|
v.DeadRegions = append(v.DeadRegions, web.DeadRegion{Name: data.regionOf[id].Name, Since: since.Local().Format("2006-01-02 15:04")})
|
||||||
}
|
}
|
||||||
@@ -105,6 +114,47 @@ func (s *Server) dashboard(c *gin.Context) {
|
|||||||
web.Render(c, http.StatusOK, web.Dashboard(s.pageFor(c, "console.monitors.title"), me, v))
|
web.Render(c, http.StatusOK, web.Dashboard(s.pageFor(c, "console.monitors.title"), me, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dashboardBars loads the bars of the monitors v shows, and only those.
|
||||||
|
func (s *Server) dashboardBars(ctx context.Context, p *principal, v *web.DashboardView, data *monitorData) error {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
walk := func(rows []web.MonitorRow, set bool) {
|
||||||
|
for i := range rows {
|
||||||
|
id, err := uuid.Parse(rows[i].ID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if set {
|
||||||
|
rows[i].Bars = data.bars(id)
|
||||||
|
} else {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var tree func(n *web.GroupNode, set bool)
|
||||||
|
tree = func(n *web.GroupNode, set bool) {
|
||||||
|
walk(n.Monitors, set)
|
||||||
|
for i := range n.Children {
|
||||||
|
tree(&n.Children[i], set)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A search or filter lists Results instead of the tree.
|
||||||
|
listing := v.Search != "" || v.Filter != ""
|
||||||
|
if listing {
|
||||||
|
walk(v.Results, false)
|
||||||
|
} else {
|
||||||
|
tree(&v.Root, false)
|
||||||
|
}
|
||||||
|
if err := s.loadBars(ctx, p, data, ids); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if listing {
|
||||||
|
walk(v.Results, true)
|
||||||
|
} else {
|
||||||
|
tree(&v.Root, true)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// groupMonitorsShown is how many of its own monitors a group shows on the
|
// groupMonitorsShown is how many of its own monitors a group shows on the
|
||||||
// dashboard before linking to all of them.
|
// dashboard before linking to all of them.
|
||||||
const groupMonitorsShown = 50
|
const groupMonitorsShown = 50
|
||||||
@@ -112,14 +162,64 @@ const groupMonitorsShown = 50
|
|||||||
// ungrouped names the pseudo-group of monitors outside any group.
|
// ungrouped names the pseudo-group of monitors outside any group.
|
||||||
const ungrouped = "none"
|
const ungrouped = "none"
|
||||||
|
|
||||||
func monitorKey(m web.MonitorRow) cursor {
|
// monitorSort is an order of the monitor list: the organization's own,
|
||||||
id, _ := uuid.Parse(m.ID)
|
// or by name, status (problems first), uptime (worst first) or latency
|
||||||
return cursor{S: strings.ToLower(m.Name), ID: id}
|
// (slowest first). Monitors without a position or data come last.
|
||||||
|
type monitorSort string
|
||||||
|
|
||||||
|
var monitorSorts = []monitorSort{"custom", "name", "status", "uptime", "latency"}
|
||||||
|
|
||||||
|
const sortCookie = "monitor_sort"
|
||||||
|
|
||||||
|
// sortOf returns the order asked for, remembering it in a cookie, or the
|
||||||
|
// one remembered, or the organization's own.
|
||||||
|
func sortOf(c *gin.Context) monitorSort {
|
||||||
|
if q := monitorSort(c.Query("sort")); slices.Contains(monitorSorts, q) {
|
||||||
|
c.SetSameSite(http.SameSiteLaxMode)
|
||||||
|
c.SetCookie(sortCookie, string(q), 365*24*3600, "/", "", c.Request.TLS != nil, true)
|
||||||
|
return q
|
||||||
|
}
|
||||||
|
if v, err := c.Cookie(sortCookie); err == nil && slices.Contains(monitorSorts, monitorSort(v)) {
|
||||||
|
return monitorSort(v)
|
||||||
|
}
|
||||||
|
return "custom"
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortMonitors(ms []web.MonitorRow) {
|
// key orders m by o as a string, so pages can continue after it.
|
||||||
|
func (o monitorSort) key(m web.MonitorRow) cursor {
|
||||||
|
id, _ := uuid.Parse(m.ID)
|
||||||
|
name := strings.ToLower(m.Name)
|
||||||
|
var k string
|
||||||
|
switch o {
|
||||||
|
case "name":
|
||||||
|
k = name
|
||||||
|
case "status":
|
||||||
|
k = fmt.Sprintf("%d|%s", statusRank[m.Status], name)
|
||||||
|
case "uptime":
|
||||||
|
if m.Ratio < 0 {
|
||||||
|
k = "1|" + name
|
||||||
|
} else {
|
||||||
|
k = fmt.Sprintf("0|%.9f|%s", m.Ratio, name)
|
||||||
|
}
|
||||||
|
case "latency":
|
||||||
|
if m.LatencyMS < 0 {
|
||||||
|
k = "1|" + name
|
||||||
|
} else {
|
||||||
|
k = fmt.Sprintf("0|%010d|%s", math.MaxInt32-m.LatencyMS, name)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if m.Position < 0 {
|
||||||
|
k = "1|" + name
|
||||||
|
} else {
|
||||||
|
k = fmt.Sprintf("0|%010d|%s", m.Position, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cursor{S: k, ID: id}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o monitorSort) sort(ms []web.MonitorRow) {
|
||||||
slices.SortFunc(ms, func(a, b web.MonitorRow) int {
|
slices.SortFunc(ms, func(a, b web.MonitorRow) int {
|
||||||
ka, kb := monitorKey(a), monitorKey(b)
|
ka, kb := o.key(a), o.key(b)
|
||||||
if c := strings.Compare(ka.S, kb.S); c != 0 {
|
if c := strings.Compare(ka.S, kb.S); c != 0 {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
@@ -127,6 +227,46 @@ func sortMonitors(ms []web.MonitorRow) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dashboardStatuses are the statuses the dashboard counts, in order.
|
||||||
|
var dashboardStatuses = []web.Status{web.StatusUp, web.StatusDegraded, web.StatusDown, web.StatusUnknown, web.StatusMaintenance, web.StatusPaused}
|
||||||
|
|
||||||
|
// dashboardURL is the dashboard with key set to value, or removed when
|
||||||
|
// value is empty, keeping the search and range but not the page.
|
||||||
|
func dashboardURL(c *gin.Context, key, value string) string {
|
||||||
|
q := url.Values{}
|
||||||
|
for _, k := range []string{"q", "range", "status", "arrange"} {
|
||||||
|
if v := c.Query(k); v != "" {
|
||||||
|
q.Set(k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value == "" {
|
||||||
|
q.Del(key)
|
||||||
|
} else {
|
||||||
|
q.Set(key, value)
|
||||||
|
}
|
||||||
|
if len(q) == 0 {
|
||||||
|
return "/"
|
||||||
|
}
|
||||||
|
return "/?" + q.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
// statusFilters are the counts of the statuses present, each linking to
|
||||||
|
// its monitors, the active one back to all.
|
||||||
|
func statusFilters(c *gin.Context, counts map[web.Status]int, active web.Status) []web.StatusFilter {
|
||||||
|
var out []web.StatusFilter
|
||||||
|
for _, st := range dashboardStatuses {
|
||||||
|
if counts[st] == 0 && st != active {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
f := web.StatusFilter{Status: st, Count: counts[st], Active: st == active, URL: dashboardURL(c, "status", string(st))}
|
||||||
|
if f.Active {
|
||||||
|
f.URL = dashboardURL(c, "status", "")
|
||||||
|
}
|
||||||
|
out = append(out, f)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// dashboardPage narrows the dashboard to a search or one group, pages it
|
// dashboardPage narrows the dashboard to a search or one group, pages it
|
||||||
// and caps every group's own monitors. It reports false after answering
|
// and caps every group's own monitors. It reports false after answering
|
||||||
// with an error.
|
// with an error.
|
||||||
@@ -135,6 +275,20 @@ func (s *Server) dashboardPage(c *gin.Context, v *web.DashboardView, data monito
|
|||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
order := sortOf(c)
|
||||||
|
v.Sort = string(order)
|
||||||
|
for _, o := range monitorSorts {
|
||||||
|
v.Sorts = append(v.Sorts, web.SortOption{Key: string(o), Active: o == order, URL: dashboardURL(c, "sort", string(o))})
|
||||||
|
}
|
||||||
|
// Arranging by hand shows the whole tree in the organization's order.
|
||||||
|
arranging := order == "custom" && v.CanWrite && c.Query("q") == "" && c.Query("status") == "" && c.Query("group") == ""
|
||||||
|
v.Arrange = arranging && c.Query("arrange") == "1"
|
||||||
|
if arranging {
|
||||||
|
v.ArrangeURL = dashboardURL(c, "arrange", "1")
|
||||||
|
if v.Arrange {
|
||||||
|
v.ArrangeURL = dashboardURL(c, "arrange", "")
|
||||||
|
}
|
||||||
|
}
|
||||||
link := func(group string) string {
|
link := func(group string) string {
|
||||||
q := url.Values{"group": {group}}
|
q := url.Values{"group": {group}}
|
||||||
if r := c.Query("range"); r != "" {
|
if r := c.Query("range"); r != "" {
|
||||||
@@ -144,8 +298,8 @@ func (s *Server) dashboardPage(c *gin.Context, v *web.DashboardView, data monito
|
|||||||
}
|
}
|
||||||
var capNode func(n *web.GroupNode)
|
var capNode func(n *web.GroupNode)
|
||||||
capNode = func(n *web.GroupNode) {
|
capNode = func(n *web.GroupNode) {
|
||||||
sortMonitors(n.Monitors)
|
order.sort(n.Monitors)
|
||||||
if len(n.Monitors) > groupMonitorsShown {
|
if len(n.Monitors) > groupMonitorsShown && !v.Arrange {
|
||||||
n.More = len(n.Monitors) - groupMonitorsShown
|
n.More = len(n.Monitors) - groupMonitorsShown
|
||||||
n.Monitors = n.Monitors[:groupMonitorsShown]
|
n.Monitors = n.Monitors[:groupMonitorsShown]
|
||||||
n.MoreURL = link(cmp.Or(n.ID, ungrouped))
|
n.MoreURL = link(cmp.Or(n.ID, ungrouped))
|
||||||
@@ -155,18 +309,25 @@ func (s *Server) dashboardPage(c *gin.Context, v *web.DashboardView, data monito
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var info pageInfo
|
var info pageInfo
|
||||||
|
if f := web.Status(c.Query("status")); slices.Contains(dashboardStatuses, f) {
|
||||||
|
v.Filter = f
|
||||||
|
v.AllURL = dashboardURL(c, "status", "")
|
||||||
|
}
|
||||||
switch group := c.Query("group"); {
|
switch group := c.Query("group"); {
|
||||||
case strings.TrimSpace(c.Query("q")) != "":
|
case strings.TrimSpace(c.Query("q")) != "" || v.Filter != "":
|
||||||
v.Search = strings.TrimSpace(c.Query("q"))
|
v.Search = strings.TrimSpace(c.Query("q"))
|
||||||
needle := strings.ToLower(v.Search)
|
needle := strings.ToLower(v.Search)
|
||||||
var hits []web.MonitorRow
|
var hits []web.MonitorRow
|
||||||
for _, m := range data.rows {
|
for _, m := range data.rows {
|
||||||
|
if v.Filter != "" && m.Status != v.Filter {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if strings.Contains(strings.ToLower(m.Name), needle) || strings.Contains(strings.ToLower(m.Target), needle) {
|
if strings.Contains(strings.ToLower(m.Name), needle) || strings.Contains(strings.ToLower(m.Target), needle) {
|
||||||
hits = append(hits, m)
|
hits = append(hits, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sortMonitors(hits)
|
order.sort(hits)
|
||||||
v.Results, info = pageSlice(hits, pg, monitorKey)
|
v.Results, info = pageSlice(hits, pg, order.key)
|
||||||
case group != "":
|
case group != "":
|
||||||
var focus web.GroupNode
|
var focus web.GroupNode
|
||||||
found := false
|
found := false
|
||||||
@@ -191,8 +352,8 @@ func (s *Server) dashboardPage(c *gin.Context, v *web.DashboardView, data monito
|
|||||||
c.Redirect(http.StatusSeeOther, "/")
|
c.Redirect(http.StatusSeeOther, "/")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
sortMonitors(focus.Monitors)
|
order.sort(focus.Monitors)
|
||||||
focus.Monitors, info = pageSlice(focus.Monitors, pg, monitorKey)
|
focus.Monitors, info = pageSlice(focus.Monitors, pg, order.key)
|
||||||
for i := range focus.Children {
|
for i := range focus.Children {
|
||||||
capNode(&focus.Children[i])
|
capNode(&focus.Children[i])
|
||||||
}
|
}
|
||||||
@@ -211,80 +372,96 @@ type monitorData struct {
|
|||||||
maint map[uuid.UUID][]store.MaintenanceWindow
|
maint map[uuid.UUID][]store.MaintenanceWindow
|
||||||
rows []web.MonitorRow
|
rows []web.MonitorRow
|
||||||
byID map[uuid.UUID]store.Monitor
|
byID map[uuid.UUID]store.Monitor
|
||||||
// buckets cover the selected range at its resolution.
|
// buckets cover the selected range at its resolution, for the
|
||||||
|
// monitors loadBars was asked for.
|
||||||
buckets map[uuid.UUID][]web.Bucket
|
buckets map[uuid.UUID][]web.Bucket
|
||||||
down map[uuid.UUID][]web.Span
|
down map[uuid.UUID][]web.Span
|
||||||
regionOf map[uuid.UUID]store.Region
|
regionOf map[uuid.UUID]store.Region
|
||||||
rng web.TimeRange
|
rng web.TimeRange
|
||||||
now time.Time
|
now time.Time
|
||||||
// first is when each monitor first reported, from any region;
|
// first is when the monitor of a detail page first reported, from
|
||||||
// firstRegion the same per region.
|
// any region; firstRegion the same per region.
|
||||||
first map[uuid.UUID]time.Time
|
first time.Time
|
||||||
firstRegion map[uuid.UUID]map[string]time.Time
|
firstRegion map[string]time.Time
|
||||||
// statuses are the organization's own incident statuses.
|
// statuses are the organization's own incident statuses.
|
||||||
statuses customStatuses
|
statuses customStatuses
|
||||||
// usedRegions are the regions the enabled monitors are checked from.
|
// usedRegions are the regions the enabled monitors are checked from.
|
||||||
usedRegions []uuid.UUID
|
usedRegions []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadFirstData finds when monitors and their regions first reported. The
|
// loadFirstData finds when monitor and its regions first reported. The
|
||||||
// daily aggregate answers to the day, which is precise enough for anything
|
// daily aggregate answers to the day, which is precise enough for anything
|
||||||
// older than two days; younger data is looked up in the raw results.
|
// older than two days; younger data is looked up exactly.
|
||||||
func loadFirstData(ctx context.Context, q *store.Queries, org uuid.UUID, now time.Time) (map[uuid.UUID]time.Time, map[uuid.UUID]map[string]time.Time, error) {
|
func loadFirstData(ctx context.Context, q *store.Queries, org, monitor uuid.UUID, now time.Time) (time.Time, map[string]time.Time, error) {
|
||||||
first := map[uuid.UUID]time.Time{}
|
var first time.Time
|
||||||
perRegion := map[uuid.UUID]map[string]time.Time{}
|
perRegion := map[string]time.Time{}
|
||||||
note := func(m uuid.UUID, region string, t time.Time) {
|
note := func(region string, t time.Time) {
|
||||||
if perRegion[m] == nil {
|
if cur, ok := perRegion[region]; !ok || t.Before(cur) {
|
||||||
perRegion[m] = map[string]time.Time{}
|
perRegion[region] = t
|
||||||
}
|
}
|
||||||
if cur, ok := perRegion[m][region]; !ok || t.Before(cur) {
|
if first.IsZero() || t.Before(first) {
|
||||||
perRegion[m][region] = t
|
first = t
|
||||||
}
|
|
||||||
if cur, ok := first[m]; !ok || t.Before(cur) {
|
|
||||||
first[m] = t
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recentSince := now.Add(-2 * 24 * time.Hour)
|
recentSince := now.Add(-2 * 24 * time.Hour)
|
||||||
daily, err := q.FirstDataDaily(ctx, org)
|
daily, err := q.FirstDataDaily(ctx, store.FirstDataDailyParams{OrgID: org, MonitorID: monitor})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return first, nil, err
|
||||||
}
|
}
|
||||||
for _, r := range daily {
|
for _, r := range daily {
|
||||||
if r.First.Before(recentSince) {
|
if r.First.Before(recentSince) {
|
||||||
note(r.MonitorID, r.Region, r.First)
|
note(r.Region, r.First)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recent, err := q.FirstDataRecent(ctx, store.FirstDataRecentParams{OrgID: org, Time: recentSince})
|
recent, err := q.FirstDataRecent(ctx, store.FirstDataRecentParams{OrgID: org, MonitorID: monitor, Time: recentSince})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return first, nil, err
|
||||||
}
|
}
|
||||||
for _, r := range recent {
|
for _, r := range recent {
|
||||||
note(r.MonitorID, r.Region, r.First)
|
note(r.Region, r.First)
|
||||||
}
|
}
|
||||||
return first, perRegion, nil
|
return first, perRegion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// rangeBuckets loads the selected range for all monitors, or one if
|
// earliestData finds when any monitor of org first reported, for the
|
||||||
// monitor is set.
|
// ranges the monitor list offers: to the day if that was over two days
|
||||||
func rangeBuckets(ctx context.Context, q *store.Queries, org uuid.UUID, monitor *uuid.UUID, rng web.TimeRange, now time.Time) (map[uuid.UUID][]web.Bucket, error) {
|
// ago, otherwise exactly.
|
||||||
|
func earliestData(ctx context.Context, q *store.Queries, org uuid.UUID, now time.Time) (time.Time, error) {
|
||||||
|
none := func(t time.Time, err error) (time.Time, bool, error) {
|
||||||
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
return time.Time{}, false, nil
|
||||||
|
}
|
||||||
|
return t, err == nil, err
|
||||||
|
}
|
||||||
|
recentSince := now.Add(-2 * 24 * time.Hour)
|
||||||
|
daily, ok, err := none(q.EarliestDataDaily(ctx, org))
|
||||||
|
if err != nil || (ok && daily.Before(recentSince)) {
|
||||||
|
return daily, err
|
||||||
|
}
|
||||||
|
exact, _, err := none(q.EarliestDataRecent(ctx, store.EarliestDataRecentParams{OrgID: org, Time: recentSince}))
|
||||||
|
return exact, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// rangeBuckets loads the selected range for the monitors ids.
|
||||||
|
func rangeBuckets(ctx context.Context, q *store.Queries, org uuid.UUID, ids []uuid.UUID, rng web.TimeRange, now time.Time) (map[uuid.UUID][]web.Bucket, error) {
|
||||||
out := map[uuid.UUID][]web.Bucket{}
|
out := map[uuid.UUID][]web.Bucket{}
|
||||||
since := now.Add(-rng.Window).Truncate(rng.Bucket)
|
since := now.Add(-rng.Window).Truncate(rng.Bucket)
|
||||||
width := fmt.Sprintf("%d seconds", int(rng.Bucket.Seconds()))
|
width := fmt.Sprintf("%d seconds", int(rng.Bucket.Seconds()))
|
||||||
switch rng.Source {
|
switch rng.Source {
|
||||||
case web.SourceHourly:
|
case web.SourceHourly:
|
||||||
rows, err := q.RangeBucketsHourly(ctx, store.RangeBucketsHourlyParams{OrgID: org, Width: width, Since: since, MonitorID: monitor})
|
rows, err := q.RangeBucketsHourly(ctx, store.RangeBucketsHourlyParams{OrgID: org, Width: width, Since: since, Ids: ids})
|
||||||
for _, r := range rows {
|
for _, r := range rows {
|
||||||
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
||||||
}
|
}
|
||||||
return out, err
|
return out, err
|
||||||
case web.SourceDaily:
|
case web.SourceDaily:
|
||||||
rows, err := q.RangeBucketsDaily(ctx, store.RangeBucketsDailyParams{OrgID: org, Width: width, Since: since, MonitorID: monitor})
|
rows, err := q.RangeBucketsDaily(ctx, store.RangeBucketsDailyParams{OrgID: org, Width: width, Since: since, Ids: ids})
|
||||||
for _, r := range rows {
|
for _, r := range rows {
|
||||||
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
||||||
}
|
}
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
rows, err := q.RangeBuckets(ctx, store.RangeBucketsParams{OrgID: org, Width: width, Since: since, MonitorID: monitor})
|
rows, err := q.RangeBuckets(ctx, store.RangeBucketsParams{OrgID: org, Width: width, Since: since, Ids: ids})
|
||||||
for _, r := range rows {
|
for _, r := range rows {
|
||||||
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
||||||
}
|
}
|
||||||
@@ -301,9 +478,10 @@ func (d monitorData) slaFor(m store.Monitor, window time.Duration) float64 {
|
|||||||
return web.SLA(d.down[m.ID], from, d.now)
|
return web.SLA(d.down[m.ID], from, d.now)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadMonitorData assembles everything the monitor list shows.
|
// loadMonitorData assembles the status of every monitor for rng.
|
||||||
// loadMonitorData assembles everything the monitor list shows for rng.
|
// Incidents are loaded far enough back for every SLA window. The bars of
|
||||||
// Incidents are loaded far enough back for every SLA window.
|
// rng are left to loadBars, for the monitors shown: an organization may
|
||||||
|
// have thousands.
|
||||||
func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.TimeRange) (monitorData, error) {
|
func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.TimeRange) (monitorData, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
d := monitorData{
|
d := monitorData{
|
||||||
@@ -325,10 +503,10 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
if groups, err = q.ListGroups(ctx); err != nil {
|
if groups, err = q.ListGroups(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if monitors, err = q.ListMonitors(ctx); err != nil {
|
if monitors, err = q.ListMonitors(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if assigned, err = q.AllMonitorRegions(ctx); err != nil {
|
if assigned, err = q.AllMonitorRegions(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if regions, err = q.ListVisibleRegions(ctx); err != nil {
|
if regions, err = q.ListVisibleRegions(ctx); err != nil {
|
||||||
@@ -337,13 +515,10 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
if latest, err = q.LatestResults(ctx, p.Org.ID); err != nil {
|
if latest, err = q.LatestResults(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if open, err = q.OpenIncidents(ctx); err != nil {
|
if open, err = q.OpenIncidents(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if spans, err = q.IncidentsSince(ctx, ptr(now.Add(-web.SLAWindows[len(web.SLAWindows)-1].Window))); err != nil {
|
if spans, err = q.IncidentsSince(ctx, store.IncidentsSinceParams{OrgID: p.Org.ID, ResolvedAt: ptr(now.Add(-web.SLAWindows[len(web.SLAWindows)-1].Window))}); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
if d.first, d.firstRegion, err = loadFirstData(ctx, q, p.Org.ID, now); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if d.statuses, err = loadCustomStatuses(ctx, q); err != nil {
|
if d.statuses, err = loadCustomStatuses(ctx, q); err != nil {
|
||||||
@@ -353,10 +528,7 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
for i, m := range monitors {
|
for i, m := range monitors {
|
||||||
ids[i] = m.ID
|
ids[i] = m.ID
|
||||||
}
|
}
|
||||||
if d.maint, err = maintenanceFor(ctx, q, ids); err != nil {
|
d.maint, err = maintenanceFor(ctx, q, ids)
|
||||||
return err
|
|
||||||
}
|
|
||||||
d.buckets, err = rangeBuckets(ctx, q, p.Org.ID, nil, rng, now)
|
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -400,7 +572,10 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
d.byID[m.ID] = m
|
d.byID[m.ID] = m
|
||||||
row := web.MonitorRow{ID: m.ID.String(), Name: m.Name, Type: m.Type, Target: m.Target, Latency: "–", Uptime: "–"}
|
row := web.MonitorRow{ID: m.ID.String(), Name: m.Name, Type: m.Type, Target: m.Target, Latency: "–", Uptime: "–", Position: -1, LatencyMS: -1}
|
||||||
|
if m.Position != nil {
|
||||||
|
row.Position = int(*m.Position)
|
||||||
|
}
|
||||||
keys := idStrings(regionsOf[m.ID])
|
keys := idStrings(regionsOf[m.ID])
|
||||||
if check.Passive(check.Type(m.Type)) {
|
if check.Passive(check.Type(m.Type)) {
|
||||||
// The target of a heartbeat is its secret ping token.
|
// The target of a heartbeat is its secret ping token.
|
||||||
@@ -461,9 +636,10 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
sum += l
|
sum += l
|
||||||
}
|
}
|
||||||
row.Latency = fmt.Sprintf("%d ms", sum/int32(len(latencies)))
|
row.Latency = fmt.Sprintf("%d ms", sum/int32(len(latencies)))
|
||||||
|
row.LatencyMS = int(sum / int32(len(latencies)))
|
||||||
}
|
}
|
||||||
row.Uptime = web.SLAText(d.slaFor(m, rng.Window))
|
row.Ratio = d.slaFor(m, rng.Window)
|
||||||
row.Bars = web.UptimeBars(d.buckets[m.ID], now, rng.Bucket, rng.Bars(), rng.Layout)
|
row.Uptime = web.SLAText(row.Ratio)
|
||||||
d.rows = append(d.rows, row)
|
d.rows = append(d.rows, row)
|
||||||
}
|
}
|
||||||
// Problems first, then by name.
|
// Problems first, then by name.
|
||||||
@@ -471,6 +647,23 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loadBars loads the bars of the selected range for the monitors ids.
|
||||||
|
func (s *Server) loadBars(ctx context.Context, p *principal, d *monitorData, ids []uuid.UUID) error {
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||||
|
var err error
|
||||||
|
d.buckets, err = rangeBuckets(ctx, q, p.Org.ID, ids, d.rng, d.now)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// bars are the monitor's bars of the selected range, from loadBars.
|
||||||
|
func (d monitorData) bars(id uuid.UUID) []web.Bar {
|
||||||
|
return web.UptimeBars(d.buckets[id], d.now, d.rng.Bucket, d.rng.Bars(), d.rng.Layout)
|
||||||
|
}
|
||||||
|
|
||||||
func (d monitorData) regionName(id uuid.UUID) string {
|
func (d monitorData) regionName(id uuid.UUID) string {
|
||||||
if r, ok := d.regionOf[id]; ok {
|
if r, ok := d.regionOf[id]; ok {
|
||||||
return r.Name
|
return r.Name
|
||||||
@@ -493,6 +686,16 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
|
|||||||
if !ok {
|
if !ok {
|
||||||
return notFoundPage(c)
|
return notFoundPage(c)
|
||||||
}
|
}
|
||||||
|
if err := s.loadBars(ctx, p, &d, []uuid.UUID{id}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||||
|
var err error
|
||||||
|
d.first, d.firstRegion, err = loadFirstData(ctx, q, p.Org.ID, id, d.now)
|
||||||
|
return err
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
v := web.MonitorDetailView{
|
v := web.MonitorDetailView{
|
||||||
Interval: (time.Duration(m.IntervalSeconds) * time.Second).String(),
|
Interval: (time.Duration(m.IntervalSeconds) * time.Second).String(),
|
||||||
PingURL: s.detailPingURL(p, d, m),
|
PingURL: s.detailPingURL(p, d, m),
|
||||||
@@ -500,7 +703,7 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
|
|||||||
Latency: web.Latency(d.buckets[id], d.now.Add(-d.rng.Window).Truncate(d.rng.Bucket), d.now, 480, 96),
|
Latency: web.Latency(d.buckets[id], d.now.Add(-d.rng.Window).Truncate(d.rng.Bucket), d.now, 480, 96),
|
||||||
Maintenance: maintenanceItems(d.maint[id], d.now),
|
Maintenance: maintenanceItems(d.maint[id], d.now),
|
||||||
Range: d.rng.Key,
|
Range: d.rng.Key,
|
||||||
Ranges: rangeOptions(c, d.rng, d.first[id], d.now),
|
Ranges: rangeOptions(c, d.rng, d.first, d.now),
|
||||||
Uptime90: "–",
|
Uptime90: "–",
|
||||||
}
|
}
|
||||||
for _, r := range d.rows {
|
for _, r := range d.rows {
|
||||||
@@ -508,6 +711,7 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
|
|||||||
v.Row = r
|
v.Row = r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
v.Row.Bars = d.bars(id)
|
||||||
var (
|
var (
|
||||||
daily []store.DailyBucketsRow
|
daily []store.DailyBucketsRow
|
||||||
recent []store.ListResultsRow
|
recent []store.ListResultsRow
|
||||||
@@ -536,7 +740,7 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
|
|||||||
for _, w := range web.SLAWindows {
|
for _, w := range web.SLAWindows {
|
||||||
v.SLAs = append(v.SLAs, web.SLAEntry{
|
v.SLAs = append(v.SLAs, web.SLAEntry{
|
||||||
Label: w.Key, Value: web.SLAText(d.slaFor(m, w.Window)),
|
Label: w.Key, Value: web.SLAText(d.slaFor(m, w.Window)),
|
||||||
Partial: !web.HasEnoughData(d.first[id], d.now, w.Window),
|
Partial: !web.HasEnoughData(d.first, d.now, w.Window),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
regions, err := s.regionHistory(ctx, p, d, m)
|
regions, err := s.regionHistory(ctx, p, d, m)
|
||||||
@@ -1130,7 +1334,7 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m
|
|||||||
if orgGroups, err = q.ListGroups(ctx); err != nil {
|
if orgGroups, err = q.ListGroups(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if monitors, err = q.ListMonitors(ctx); err != nil {
|
if monitors, err = q.ListMonitors(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
own, err = q.OrgServesOwnPages(ctx, &p.Org.ID)
|
own, err = q.OrgServesOwnPages(ctx, &p.Org.ID)
|
||||||
@@ -1155,6 +1359,7 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m
|
|||||||
e.RecordName, e.RecordValue = v.DomainRecord.Name, v.DomainRecord.Value
|
e.RecordName, e.RecordValue = v.DomainRecord.Name, v.DomainRecord.Value
|
||||||
}
|
}
|
||||||
e.DomainChangesPerDay = domainChangesPerDay
|
e.DomainChangesPerDay = domainChangesPerDay
|
||||||
|
e.MonitorLimit = s.orgLimits(c.Request.Context(), p.Org).MonitorsPerPage
|
||||||
if v.CNAMERecord != nil {
|
if v.CNAMERecord != nil {
|
||||||
e.CNAMEValue = v.CNAMERecord.Value
|
e.CNAMEValue = v.CNAMERecord.Value
|
||||||
}
|
}
|
||||||
@@ -1360,7 +1565,7 @@ func (s *Server) regionHistory(ctx context.Context, p *principal, d monitorData,
|
|||||||
Name: d.regionNameString(r),
|
Name: d.regionNameString(r),
|
||||||
Bars: web.UptimeBars(byRegion[r], d.now, rng.Bucket, rng.Bars(), rng.Layout),
|
Bars: web.UptimeBars(byRegion[r], d.now, rng.Bucket, rng.Bars(), rng.Layout),
|
||||||
Uptime: "–",
|
Uptime: "–",
|
||||||
Enough: web.HasEnoughData(d.firstRegion[m.ID][r], d.now, rng.Window),
|
Enough: web.HasEnoughData(d.firstRegion[r], d.now, rng.Window),
|
||||||
}
|
}
|
||||||
if u := web.Uptime(byRegion[r]); u >= 0 {
|
if u := web.Uptime(byRegion[r]); u >= 0 {
|
||||||
h.Uptime = web.PercentPrecise(u)
|
h.Uptime = web.PercentPrecise(u)
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package api_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDashboardFiltersByStatus(t *testing.T) {
|
||||||
|
e := newEnv(t)
|
||||||
|
_, region := e.platformChecker(t, uniq("eu-"))
|
||||||
|
owner := e.browser(t)
|
||||||
|
owner.signup("o@"+uniq("flt")+".test", uniq("flt-"))
|
||||||
|
create := func(name string) string {
|
||||||
|
t.Helper()
|
||||||
|
st, m := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": name, "type": "http", "target": "https://" + strings.ToLower(name) + ".test", "interval_seconds": 60, "regions": []string{region}})
|
||||||
|
if st != http.StatusCreated {
|
||||||
|
t.Fatalf("create %s = %d %v", name, st, m)
|
||||||
|
}
|
||||||
|
return m["id"].(string)
|
||||||
|
}
|
||||||
|
create("Alpha")
|
||||||
|
create("Beta")
|
||||||
|
gamma := create("Gamma")
|
||||||
|
owner.do("PUT", "/api/v1/org/monitors/"+gamma, map[string]any{"name": "Gamma", "type": "http", "target": "https://gamma.test", "interval_seconds": 60, "regions": []string{region}, "enabled": false})
|
||||||
|
|
||||||
|
_, _, all := owner.page("/")
|
||||||
|
for _, want := range []string{`href="/?status=unknown"`, `href="/?status=paused"`, "Show only the 2 monitors that are no data", "Show only the 1 monitor that is paused"} {
|
||||||
|
if !strings.Contains(all, want) {
|
||||||
|
t.Errorf("the dashboard lacks %q", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, paused := owner.page("/?status=paused")
|
||||||
|
if !strings.Contains(paused, "Gamma") || strings.Contains(paused, "Alpha") || strings.Contains(paused, "Beta") {
|
||||||
|
t.Error("?status=paused does not show only the paused monitor")
|
||||||
|
}
|
||||||
|
// The active filter links back to all, and the search keeps it.
|
||||||
|
if !strings.Contains(paused, `aria-current="true"`) || !strings.Contains(paused, `title="Show all statuses"`) {
|
||||||
|
t.Error("the active filter is not marked")
|
||||||
|
}
|
||||||
|
if !strings.Contains(paused, `name="status" value="paused"`) {
|
||||||
|
t.Error("the search form drops the status filter")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, both := owner.page("/?status=unknown&q=alp")
|
||||||
|
if !strings.Contains(both, "Alpha") || strings.Contains(both, "Beta") || strings.Contains(both, "Gamma") {
|
||||||
|
t.Error("status filter and search do not combine")
|
||||||
|
}
|
||||||
|
if _, _, none := owner.page("/?status=down"); !strings.Contains(none, "No monitor has this status right now.") {
|
||||||
|
t.Error("an empty filter does not say so")
|
||||||
|
}
|
||||||
|
// An unknown status shows everything.
|
||||||
|
if _, _, bogus := owner.page("/?status=bogus"); !strings.Contains(bogus, "Alpha") || !strings.Contains(bogus, "Gamma") {
|
||||||
|
t.Error("an unknown status filter hides monitors")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSignupSendsSignedInUsersToTheMonitors(t *testing.T) {
|
||||||
|
e := newEnv(t)
|
||||||
|
visitor := e.browser(t)
|
||||||
|
if st, path, _ := visitor.page("/signup"); st != http.StatusOK || path != "/signup" {
|
||||||
|
t.Fatalf("signup for a visitor = %d at %s", st, path)
|
||||||
|
}
|
||||||
|
owner := e.browser(t)
|
||||||
|
owner.signup("o@"+uniq("su")+".test", uniq("su-"))
|
||||||
|
if st, path, html := owner.page("/signup"); st != http.StatusOK || path != "/" || !strings.Contains(html, "Monitors") {
|
||||||
|
t.Errorf("signup when signed in ended at %s (%d), want the monitor list", path, st)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPageEditorOffersAddAndRemoveAll(t *testing.T) {
|
||||||
|
e := newEnv(t)
|
||||||
|
_, region := e.platformChecker(t, uniq("eu-"))
|
||||||
|
owner := e.browser(t)
|
||||||
|
owner.signup("o@"+uniq("pa")+".test", uniq("pa-"))
|
||||||
|
_, mon := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": "Shop", "type": "http", "target": "https://shop.test", "interval_seconds": 60, "regions": []string{region}})
|
||||||
|
shop := mon["id"].(string)
|
||||||
|
_, p := owner.do("POST", "/api/v1/org/statuspages", map[string]any{"slug": uniq("pa-"), "title": "Status"})
|
||||||
|
_, _, html := owner.page("/statuspages/" + p["id"].(string))
|
||||||
|
for _, want := range []string{`data-check-all="on"`, `data-check-all="off"`, "Add all", "Remove all"} {
|
||||||
|
if !strings.Contains(html, want) {
|
||||||
|
t.Errorf("the page editor lacks %q", want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Monitors not on the page get their fields from the template only
|
||||||
|
// when ticked, so thousands of them stay light.
|
||||||
|
if n := strings.Count(html, `data-field="label"`); n != 1 || !strings.Contains(html, "<template data-row-fields>") {
|
||||||
|
t.Errorf("the page editor renders %d label fields, want only the template's", n)
|
||||||
|
}
|
||||||
|
owner.do("PUT", "/api/v1/org/statuspages/"+p["id"].(string)+"/monitors", map[string]any{"monitors": []map[string]any{{"monitor_id": shop, "label": "Webshop"}}})
|
||||||
|
if _, _, html := owner.page("/statuspages/" + p["id"].(string)); strings.Count(html, `data-field="label"`) != 2 || !strings.Contains(html, `value="Webshop"`) {
|
||||||
|
t.Error("a monitor on the page lacks its fields")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMonitorOrder(t *testing.T) {
|
||||||
|
e := newEnv(t)
|
||||||
|
_, region := e.platformChecker(t, uniq("eu-"))
|
||||||
|
owner := e.browser(t)
|
||||||
|
owner.signup("o@"+uniq("ord")+".test", uniq("ord-"))
|
||||||
|
ids := map[string]string{}
|
||||||
|
for _, n := range []string{"Alpha", "Bravo", "Charlie"} {
|
||||||
|
_, m := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": n, "type": "http", "target": "https://" + strings.ToLower(n) + ".test", "interval_seconds": 60, "regions": []string{region}})
|
||||||
|
ids[n] = m["id"].(string)
|
||||||
|
}
|
||||||
|
order := func(html string, names ...string) bool {
|
||||||
|
last := -1
|
||||||
|
for _, n := range names {
|
||||||
|
i := strings.Index(html, ">"+n+"<")
|
||||||
|
if i < last || i < 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
last = i
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Without an order of its own, by name.
|
||||||
|
if _, _, html := owner.page("/"); !order(html, "Alpha", "Bravo", "Charlie") {
|
||||||
|
t.Error("monitors without positions are not by name")
|
||||||
|
}
|
||||||
|
st, body := owner.do("PUT", "/api/v1/org/monitors/order", map[string]any{"monitor_ids": []string{ids["Charlie"], ids["Alpha"]}})
|
||||||
|
if st != http.StatusNoContent {
|
||||||
|
t.Fatalf("order = %d %v", st, body)
|
||||||
|
}
|
||||||
|
// Positioned ones first, in their order; the rest after, by name.
|
||||||
|
_, _, html := owner.page("/")
|
||||||
|
if !order(html, "Charlie", "Alpha", "Bravo") {
|
||||||
|
t.Error("the list does not follow the organization's order")
|
||||||
|
}
|
||||||
|
if !strings.Contains(html, "?arrange=1") || !strings.Contains(html, "?sort=name") {
|
||||||
|
t.Error("the dashboard offers neither arranging nor sorting")
|
||||||
|
}
|
||||||
|
if _, _, arr := owner.page("/?arrange=1"); !strings.Contains(arr, `data-sortable="/org/monitors/order"`) || !strings.Contains(arr, `data-sort-id="`+ids["Charlie"]+`"`) {
|
||||||
|
t.Error("arranging does not show the sortable list")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sorting by name is remembered until changed.
|
||||||
|
if _, _, byName := owner.page("/?sort=name"); !order(byName, "Alpha", "Bravo", "Charlie") {
|
||||||
|
t.Error("?sort=name does not sort by name")
|
||||||
|
}
|
||||||
|
if _, _, again := owner.page("/"); !order(again, "Alpha", "Bravo", "Charlie") || strings.Contains(again, "?arrange=1") {
|
||||||
|
t.Error("the sort order is not remembered, or arranging is offered outside the own order")
|
||||||
|
}
|
||||||
|
owner.page("/?sort=custom")
|
||||||
|
|
||||||
|
// Unknown and duplicate monitors are refused, and nothing changes.
|
||||||
|
st, body = owner.do("PUT", "/api/v1/org/monitors/order", map[string]any{"monitor_ids": []string{ids["Bravo"], "00000000-0000-0000-0000-000000000001"}})
|
||||||
|
expect(t, "unknown monitor", st, body, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||||
|
st, body = owner.do("PUT", "/api/v1/org/monitors/order", map[string]any{"monitor_ids": []string{ids["Bravo"], ids["Bravo"]}})
|
||||||
|
expect(t, "duplicate monitor", st, body, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||||
|
if _, _, html := owner.page("/"); !order(html, "Charlie", "Alpha", "Bravo") {
|
||||||
|
t.Error("a refused order changed the list")
|
||||||
|
}
|
||||||
|
// Another organization cannot touch them.
|
||||||
|
other := e.browser(t)
|
||||||
|
other.signup("x@"+uniq("ord")+".test", uniq("ord-"))
|
||||||
|
st, body = other.do("PUT", "/api/v1/org/monitors/order", map[string]any{"monitor_ids": []string{ids["Alpha"]}})
|
||||||
|
expect(t, "another organization's monitor", st, body, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package api_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLongPollsEndWhenDraining(t *testing.T) {
|
||||||
|
e := newEnv(t)
|
||||||
|
tok, _ := e.platformChecker(t, uniq("eu-"))
|
||||||
|
drain := make(chan struct{})
|
||||||
|
e.api.EndLongPollsOn(drain)
|
||||||
|
client := agentapi.NewClient(e.srv.URL, tok, uuid.New(), "test").WithHTTPClient(e.srv.Client())
|
||||||
|
|
||||||
|
go func() { time.Sleep(300 * time.Millisecond); close(drain) }()
|
||||||
|
start := time.Now()
|
||||||
|
jobs, err := client.Jobs(context.Background(), 10, 20*time.Second)
|
||||||
|
if err != nil || len(jobs) != 0 {
|
||||||
|
t.Fatalf("Jobs() while draining = %v, %v; want no jobs and no error", jobs, err)
|
||||||
|
}
|
||||||
|
if took := time.Since(start); took > 3*time.Second {
|
||||||
|
t.Errorf("a long poll ran %v after draining began, want it to end within about a second", took)
|
||||||
|
}
|
||||||
|
// Once draining, polls answer at once.
|
||||||
|
start = time.Now()
|
||||||
|
if _, err := client.Jobs(context.Background(), 10, 20*time.Second); err != nil || time.Since(start) > 2*time.Second {
|
||||||
|
t.Errorf("a poll on a draining instance took %v (%v)", time.Since(start), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -472,7 +472,7 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
|
|||||||
for _, a := range alertAssignments {
|
for _, a := range alertAssignments {
|
||||||
alertGroupsByMonitor[a.MonitorID] = append(alertGroupsByMonitor[a.MonitorID], a.GroupID)
|
alertGroupsByMonitor[a.MonitorID] = append(alertGroupsByMonitor[a.MonitorID], a.GroupID)
|
||||||
}
|
}
|
||||||
regionRows, err := q.AllMonitorRegions(ctx)
|
regionRows, err := q.AllMonitorRegions(ctx, p.Org.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -480,7 +480,7 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
|
|||||||
for _, r := range regionRows {
|
for _, r := range regionRows {
|
||||||
regions[r.MonitorID] = append(regions[r.MonitorID], r.RegionID)
|
regions[r.MonitorID] = append(regions[r.MonitorID], r.RegionID)
|
||||||
}
|
}
|
||||||
monitors, err := q.ListMonitors(ctx)
|
monitors, err := q.ListMonitors(ctx, p.Org.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,8 +93,7 @@ func (s *Server) recordPassive(ctx context.Context, region string, id, org uuid.
|
|||||||
row.Error = ptr(truncateValid(msg, 500))
|
row.Error = ptr(truncateValid(msg, 500))
|
||||||
}
|
}
|
||||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||||
_, err := q.InsertCheckResults(ctx, []store.InsertCheckResultsParams{row})
|
return insertResults(ctx, q, []store.InsertCheckResultsParams{row})
|
||||||
return err
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package api_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestLatestResultsKeepTheNewest checks that a result arriving late does
|
||||||
|
// not replace a newer one, and that a batch keeps its newest per region.
|
||||||
|
func TestLatestResultsKeepTheNewest(t *testing.T) {
|
||||||
|
e := newEnv(t)
|
||||||
|
_, region := e.platformChecker(t, uniq("eu-"))
|
||||||
|
owner := e.browser(t)
|
||||||
|
owner.signup("o@"+uniq("lr")+".test", uniq("lr-"))
|
||||||
|
_, m := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": "Shop", "type": "http", "target": "https://shop.test", "interval_seconds": 60, "regions": []string{region}})
|
||||||
|
id, org := uuid.MustParse(m["id"].(string)), uuid.MustParse(owner.orgID())
|
||||||
|
now := time.Now().Truncate(time.Millisecond)
|
||||||
|
upsert := func(rows ...map[string]any) {
|
||||||
|
t.Helper()
|
||||||
|
for _, r := range rows {
|
||||||
|
r["monitor_id"], r["org_id"], r["region"] = id, org, region
|
||||||
|
}
|
||||||
|
b, _ := json.Marshal(rows)
|
||||||
|
if err := e.asSystem(t, func(tx pgx.Tx) error { return store.New(tx).UpsertLatestResults(context.Background(), b) }); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
latest := func() (time.Time, bool) {
|
||||||
|
t.Helper()
|
||||||
|
var (
|
||||||
|
at time.Time
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
if err := e.asSystem(t, func(tx pgx.Tx) error {
|
||||||
|
return tx.QueryRow(context.Background(), `SELECT time, ok FROM latest_results WHERE monitor_id = $1`, id).Scan(&at, &ok)
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return at, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
upsert(map[string]any{"time": now.Add(-time.Minute), "ok": true}, map[string]any{"time": now, "ok": false, "error": "down"})
|
||||||
|
if at, ok := latest(); !at.Equal(now) || ok {
|
||||||
|
t.Errorf("after a batch latest = %v ok=%t, want the newest (%v, failed)", at, ok, now)
|
||||||
|
}
|
||||||
|
upsert(map[string]any{"time": now.Add(-30 * time.Second), "ok": true})
|
||||||
|
if at, _ := latest(); !at.Equal(now) {
|
||||||
|
t.Errorf("a late result replaced the newest: %v", at)
|
||||||
|
}
|
||||||
|
upsert(map[string]any{"time": now.Add(time.Minute), "ok": true, "latency_ms": 12})
|
||||||
|
if at, ok := latest(); !at.Equal(now.Add(time.Minute)) || !ok {
|
||||||
|
t.Errorf("a newer result was not kept: %v ok=%t", at, ok)
|
||||||
|
}
|
||||||
|
_, body := owner.do("GET", "/api/v1/org/monitors", nil)
|
||||||
|
if got := body["monitors"].([]any)[0].(map[string]any)["latest"].([]any); len(got) != 1 {
|
||||||
|
t.Errorf("the API lists %d latest results, want 1", len(got))
|
||||||
|
}
|
||||||
|
if _, _, html := owner.page("/monitors/" + id.String()); !strings.Contains(html, "12 ms") {
|
||||||
|
t.Error("the monitor page does not show the latest result")
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-3
@@ -36,6 +36,8 @@ type Limits struct {
|
|||||||
OwnRegionsCount bool `json:"own_regions_count"`
|
OwnRegionsCount bool `json:"own_regions_count"`
|
||||||
// OrgsPerAccount limits the organizations an account owns.
|
// OrgsPerAccount limits the organizations an account owns.
|
||||||
OrgsPerAccount int `json:"orgs_per_account"`
|
OrgsPerAccount int `json:"orgs_per_account"`
|
||||||
|
// MonitorsPerPage limits the monitors one status page shows.
|
||||||
|
MonitorsPerPage int `json:"monitors_per_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) defaultLimits() Limits {
|
func (s *Server) defaultLimits() Limits {
|
||||||
@@ -79,6 +81,7 @@ func (s *Server) orgLimits(ctx context.Context, org store.Org) Limits {
|
|||||||
override(&l.Monitors, org.LimitMonitors)
|
override(&l.Monitors, org.LimitMonitors)
|
||||||
override(&l.StatusPages, org.LimitStatusPages)
|
override(&l.StatusPages, org.LimitStatusPages)
|
||||||
override(&l.RegionsPerMonitor, org.LimitRegionsPerMonitor)
|
override(&l.RegionsPerMonitor, org.LimitRegionsPerMonitor)
|
||||||
|
override(&l.MonitorsPerPage, org.LimitMonitorsPerPage)
|
||||||
if org.LimitOwnRegionsCount != nil {
|
if org.LimitOwnRegionsCount != nil {
|
||||||
l.OwnRegionsCount = *org.LimitOwnRegionsCount
|
l.OwnRegionsCount = *org.LimitOwnRegionsCount
|
||||||
}
|
}
|
||||||
@@ -189,6 +192,7 @@ type limitsRequest struct {
|
|||||||
RegionsPerMonitor int `json:"regions_per_monitor" binding:"min=0,max=1000"`
|
RegionsPerMonitor int `json:"regions_per_monitor" binding:"min=0,max=1000"`
|
||||||
OwnRegionsCount bool `json:"own_regions_count"`
|
OwnRegionsCount bool `json:"own_regions_count"`
|
||||||
OrgsPerAccount int `json:"orgs_per_account" binding:"min=0,max=100000"`
|
OrgsPerAccount int `json:"orgs_per_account" binding:"min=0,max=100000"`
|
||||||
|
MonitorsPerPage int `json:"monitors_per_page" binding:"min=0,max=200"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) adminSetLimits(c *gin.Context) {
|
func (s *Server) adminSetLimits(c *gin.Context) {
|
||||||
@@ -243,6 +247,7 @@ type orgLimitsRequest struct {
|
|||||||
StatusPages *int32 `json:"status_pages" binding:"omitempty,min=0,max=1000000"`
|
StatusPages *int32 `json:"status_pages" binding:"omitempty,min=0,max=1000000"`
|
||||||
RegionsPerMonitor *int32 `json:"regions_per_monitor" binding:"omitempty,min=0,max=1000"`
|
RegionsPerMonitor *int32 `json:"regions_per_monitor" binding:"omitempty,min=0,max=1000"`
|
||||||
OwnRegionsCount optBool `json:"own_regions_count"`
|
OwnRegionsCount optBool `json:"own_regions_count"`
|
||||||
|
MonitorsPerPage *int32 `json:"monitors_per_page" binding:"omitempty,min=0,max=200"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) adminSetOrgLimits(c *gin.Context) {
|
func (s *Server) adminSetOrgLimits(c *gin.Context) {
|
||||||
@@ -261,6 +266,7 @@ func (s *Server) adminSetOrgLimits(c *gin.Context) {
|
|||||||
row, err := q.SetOrgLimits(ctx, store.SetOrgLimitsParams{
|
row, err := q.SetOrgLimits(ctx, store.SetOrgLimitsParams{
|
||||||
ID: id, Monitors: req.Monitors, StatusPages: req.StatusPages,
|
ID: id, Monitors: req.Monitors, StatusPages: req.StatusPages,
|
||||||
RegionsPerMonitor: req.RegionsPerMonitor, OwnRegionsCount: req.OwnRegionsCount.v,
|
RegionsPerMonitor: req.RegionsPerMonitor, OwnRegionsCount: req.OwnRegionsCount.v,
|
||||||
|
MonitorsPerPage: req.MonitorsPerPage,
|
||||||
})
|
})
|
||||||
auditDetail(c, "slug", row.Slug)
|
auditDetail(c, "slug", row.Slug)
|
||||||
return err
|
return err
|
||||||
@@ -316,6 +322,7 @@ type orgLimitsView struct {
|
|||||||
StatusPages *int32 `json:"status_pages"`
|
StatusPages *int32 `json:"status_pages"`
|
||||||
RegionsPerMonitor *int32 `json:"regions_per_monitor"`
|
RegionsPerMonitor *int32 `json:"regions_per_monitor"`
|
||||||
OwnRegionsCount *bool `json:"own_regions_count"`
|
OwnRegionsCount *bool `json:"own_regions_count"`
|
||||||
|
MonitorsPerPage *int32 `json:"monitors_per_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type adminOwner struct {
|
type adminOwner struct {
|
||||||
@@ -342,9 +349,10 @@ func (s *Server) adminOrgs(ctx context.Context, search string, pg pageReq) ([]ad
|
|||||||
o := &out[i]
|
o := &out[i]
|
||||||
o.moderatedOrg = moderatedOrg{r.ID, r.Slug, r.Name, r.SuspendedAt, r.SuspendedReason}
|
o.moderatedOrg = moderatedOrg{r.ID, r.Slug, r.Name, r.SuspendedAt, r.SuspendedReason}
|
||||||
o.Created = r.CreatedAt.Format("2006-01-02")
|
o.Created = r.CreatedAt.Format("2006-01-02")
|
||||||
o.Overrides = orgLimitsView{r.LimitMonitors, r.LimitStatusPages, r.LimitRegionsPerMonitor, r.LimitOwnRegionsCount}
|
o.Overrides = orgLimitsView{r.LimitMonitors, r.LimitStatusPages, r.LimitRegionsPerMonitor, r.LimitOwnRegionsCount, r.LimitMonitorsPerPage}
|
||||||
o.Limits = s.orgLimits(ctx, store.Org{LimitMonitors: r.LimitMonitors, LimitStatusPages: r.LimitStatusPages,
|
o.Limits = s.orgLimits(ctx, store.Org{LimitMonitors: r.LimitMonitors, LimitStatusPages: r.LimitStatusPages,
|
||||||
LimitRegionsPerMonitor: r.LimitRegionsPerMonitor, LimitOwnRegionsCount: r.LimitOwnRegionsCount})
|
LimitRegionsPerMonitor: r.LimitRegionsPerMonitor, LimitOwnRegionsCount: r.LimitOwnRegionsCount,
|
||||||
|
LimitMonitorsPerPage: r.LimitMonitorsPerPage})
|
||||||
o.Limits.OrgsPerAccount = defaults.OrgsPerAccount
|
o.Limits.OrgsPerAccount = defaults.OrgsPerAccount
|
||||||
o.Usage.Monitors, o.Usage.StatusPages = int(r.Monitors), int(r.StatusPages)
|
o.Usage.Monitors, o.Usage.StatusPages = int(r.Monitors), int(r.StatusPages)
|
||||||
if r.OwnerID != uuid.Nil {
|
if r.OwnerID != uuid.Nil {
|
||||||
@@ -403,7 +411,7 @@ func (s *Server) orgsView(c *gin.Context, pg pageReq) (web.OrgsView, error) {
|
|||||||
ID: o.ID.String(), Name: o.Name, Slug: o.Slug, Created: o.Created, Suspended: state(o.SuspendedAt, o.Reason),
|
ID: o.ID.String(), Name: o.Name, Slug: o.Slug, Created: o.Created, Suspended: state(o.SuspendedAt, o.Reason),
|
||||||
Monitors: o.Usage.Monitors, StatusPages: o.Usage.StatusPages, Limits: webLimits(o.Limits),
|
Monitors: o.Usage.Monitors, StatusPages: o.Usage.StatusPages, Limits: webLimits(o.Limits),
|
||||||
MonitorsOverride: optInt(o.Overrides.Monitors), StatusPagesOverride: optInt(o.Overrides.StatusPages),
|
MonitorsOverride: optInt(o.Overrides.Monitors), StatusPagesOverride: optInt(o.Overrides.StatusPages),
|
||||||
RegionsOverride: optInt(o.Overrides.RegionsPerMonitor),
|
RegionsOverride: optInt(o.Overrides.RegionsPerMonitor), PerPageOverride: optInt(o.Overrides.MonitorsPerPage),
|
||||||
}
|
}
|
||||||
if o.Overrides.OwnRegionsCount != nil {
|
if o.Overrides.OwnRegionsCount != nil {
|
||||||
row.OwnRegionsOverride = strconv.FormatBool(*o.Overrides.OwnRegionsCount)
|
row.OwnRegionsOverride = strconv.FormatBool(*o.Overrides.OwnRegionsCount)
|
||||||
|
|||||||
@@ -155,3 +155,68 @@ func TestLimits(t *testing.T) {
|
|||||||
t.Error("the organization settings lack the usage")
|
t.Error("the organization settings lack the usage")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMonitorsPerStatusPageLimit(t *testing.T) {
|
||||||
|
e := newEnv(t)
|
||||||
|
ctx := context.Background()
|
||||||
|
reset := func() {
|
||||||
|
_ = e.asSystem(t, func(tx pgx.Tx) error {
|
||||||
|
_, err := tx.Exec(ctx, `DELETE FROM platform_settings WHERE key = 'limits'`)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
reset()
|
||||||
|
t.Cleanup(reset)
|
||||||
|
admin := e.browser(t)
|
||||||
|
admin.signup("admin@"+uniq("mpp")+".test", uniq("mpp-admin-"))
|
||||||
|
if err := tenant.New(e.dbPool).Tx(ctx, tenant.Global(), func(q *store.Queries) error {
|
||||||
|
return q.MakeAdmin(ctx, admin.userIDSelf())
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if st, body := admin.do("PUT", "/api/v1/admin/limits", map[string]any{"monitors_per_page": 2}); st != http.StatusNoContent {
|
||||||
|
t.Fatalf("set defaults = %d %v", st, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
owner := e.browser(t)
|
||||||
|
owner.signup("o@"+uniq("mpp")+".test", uniq("mpp-"))
|
||||||
|
var ids []map[string]any
|
||||||
|
for range 3 {
|
||||||
|
_, m := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": "hb", "type": "heartbeat", "interval_seconds": 3600})
|
||||||
|
ids = append(ids, map[string]any{"monitor_id": m["id"]})
|
||||||
|
}
|
||||||
|
_, page := owner.do("POST", "/api/v1/org/statuspages", map[string]any{"slug": uniq("mpp-"), "title": "Status"})
|
||||||
|
set := func(n int) (int, map[string]any) {
|
||||||
|
return owner.do("PUT", "/api/v1/org/statuspages/"+page["id"].(string)+"/monitors", map[string]any{"monitors": ids[:n]})
|
||||||
|
}
|
||||||
|
if st, body := set(2); st != http.StatusNoContent {
|
||||||
|
t.Fatalf("two monitors = %d %v", st, body)
|
||||||
|
}
|
||||||
|
st, body := set(3)
|
||||||
|
expect(t, "three monitors", st, body, http.StatusUnprocessableEntity, "page_monitor_limit")
|
||||||
|
if _, _, html := owner.page("/statuspages/" + page["id"].(string)); !strings.Contains(html, "at most 2 monitors") {
|
||||||
|
t.Error("the editor does not name the limit")
|
||||||
|
}
|
||||||
|
|
||||||
|
// An override for the organization raises it; lowered again, the page
|
||||||
|
// keeps its monitors but cannot grow.
|
||||||
|
org := owner.orgID()
|
||||||
|
if st, body := admin.do("PUT", "/api/v1/admin/orgs/"+org+"/limits", map[string]any{"monitors_per_page": 3}); st != http.StatusNoContent {
|
||||||
|
t.Fatalf("override = %d %v", st, body)
|
||||||
|
}
|
||||||
|
if st, body := set(3); st != http.StatusNoContent {
|
||||||
|
t.Fatalf("three monitors with the override = %d %v", st, body)
|
||||||
|
}
|
||||||
|
admin.do("PUT", "/api/v1/admin/orgs/"+org+"/limits", map[string]any{"monitors_per_page": 1})
|
||||||
|
if st, body := set(3); st != http.StatusNoContent {
|
||||||
|
t.Errorf("saving a page beyond a lowered limit = %d %v", st, body)
|
||||||
|
}
|
||||||
|
if st, body := set(2); st != http.StatusNoContent {
|
||||||
|
t.Errorf("shrinking a page beyond a lowered limit = %d %v", st, body)
|
||||||
|
}
|
||||||
|
st, body = set(3)
|
||||||
|
expect(t, "growing again beyond the lowered limit", st, body, http.StatusUnprocessableEntity, "page_monitor_limit")
|
||||||
|
if _, _, html := admin.page("/admin"); !strings.Contains(html, "Monitors per status page") {
|
||||||
|
t.Error("the admin page does not offer the limit")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -234,7 +234,7 @@ func (s *Server) loadMaintenanceScope(ctx context.Context, p *principal) (mainte
|
|||||||
return ms, err
|
return ms, err
|
||||||
}
|
}
|
||||||
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||||
rows, err := q.ListMonitors(ctx)
|
rows, err := q.ListMonitors(ctx, p.Org.ID)
|
||||||
for _, m := range rows {
|
for _, m := range rows {
|
||||||
ms.monitors[m.ID] = m
|
ms.monitors[m.ID] = m
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
type monitorOrderRequest struct {
|
||||||
|
// MonitorIDs in the order wanted; usually the monitors of one group.
|
||||||
|
MonitorIDs []uuid.UUID `json:"monitor_ids" binding:"required,min=1,max=1000"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// orderMonitors stores the organization's own order of the monitors given,
|
||||||
|
// which the monitor list follows when sorted by its own order. It needs
|
||||||
|
// write access to every one of them.
|
||||||
|
func (s *Server) orderMonitors(c *gin.Context) {
|
||||||
|
var req monitorOrderRequest
|
||||||
|
if !bind(c, &req) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p := current(c)
|
||||||
|
ctx := c.Request.Context()
|
||||||
|
t, err := s.loadGroupTree(ctx, p.scope())
|
||||||
|
if err != nil {
|
||||||
|
internalError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
errDenied := errors.New("denied")
|
||||||
|
seen := map[uuid.UUID]bool{}
|
||||||
|
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||||
|
for i, id := range req.MonitorIDs {
|
||||||
|
if seen[id] {
|
||||||
|
return pgx.ErrNoRows
|
||||||
|
}
|
||||||
|
seen[id] = true
|
||||||
|
m, err := q.GetMonitor(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !canInGroup(p, authz.MonitorsWrite, t, m.GroupID) {
|
||||||
|
return errDenied
|
||||||
|
}
|
||||||
|
if _, err := q.SetMonitorPosition(ctx, store.SetMonitorPositionParams{ID: id, Position: new(int32(i))}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, errDenied):
|
||||||
|
fail(c, http.StatusForbidden, "forbidden")
|
||||||
|
case errors.Is(err, pgx.ErrNoRows):
|
||||||
|
fail(c, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||||
|
case err != nil:
|
||||||
|
internalError(c, err)
|
||||||
|
default:
|
||||||
|
c.Status(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -220,7 +220,7 @@ func (s *Server) listMonitors(c *gin.Context) {
|
|||||||
for _, a := range assignments {
|
for _, a := range assignments {
|
||||||
alertGroups[a.MonitorID] = append(alertGroups[a.MonitorID], a.GroupID)
|
alertGroups[a.MonitorID] = append(alertGroups[a.MonitorID], a.GroupID)
|
||||||
}
|
}
|
||||||
regions, err := q.AllMonitorRegions(ctx)
|
regions, err := q.AllMonitorRegions(ctx, p.Org.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,11 @@ func (s *Server) signupOptions(ctx context.Context) (bool, []web.IDPButton, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) signupPage(c *gin.Context) {
|
func (s *Server) signupPage(c *gin.Context) {
|
||||||
|
// Signed in already: straight to the monitors.
|
||||||
|
if auth.Current(c) != nil {
|
||||||
|
c.Redirect(http.StatusSeeOther, "/")
|
||||||
|
return
|
||||||
|
}
|
||||||
email, providers, err := s.signupOptions(c.Request.Context())
|
email, providers, err := s.signupOptions(c.Request.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
internalError(c, err)
|
internalError(c, err)
|
||||||
|
|||||||
@@ -55,8 +55,13 @@ func TestUncheckedMonitorsAndRegionsWithoutChecker(t *testing.T) {
|
|||||||
if _, err := tx.Exec(ctx, `UPDATE monitors SET created_at = now() - interval '1 hour' WHERE id = $1`, id); err != nil {
|
if _, err := tx.Exec(ctx, `UPDATE monitors SET created_at = now() - interval '1 hour' WHERE id = $1`, id); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err := tx.Exec(ctx, `INSERT INTO check_results (time, org_id, monitor_id, region, checker_id, ok, latency_ms) VALUES (now() - interval '10 minutes', $1, $2, $3, $4, true, 10)`,
|
if _, err := tx.Exec(ctx, `INSERT INTO check_results (time, org_id, monitor_id, region, checker_id, ok, latency_ms) VALUES (now() - interval '10 minutes', $1, $2, $3, $4, true, 10)`,
|
||||||
org, id, region, uuid.New())
|
org, id, region, uuid.New()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// As the API keeps it when the result arrives.
|
||||||
|
_, err := tx.Exec(ctx, `INSERT INTO latest_results (time, org_id, monitor_id, region, ok, latency_ms) VALUES (now() - interval '10 minutes', $1, $2, $3, true, 10)`,
|
||||||
|
org, id, region)
|
||||||
return err
|
return err
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
// latestRow is a result as UpsertLatestResults reads it.
|
||||||
|
type latestRow struct {
|
||||||
|
MonitorID uuid.UUID `json:"monitor_id"`
|
||||||
|
Region string `json:"region"`
|
||||||
|
OrgID uuid.UUID `json:"org_id"`
|
||||||
|
Time time.Time `json:"time"`
|
||||||
|
OK bool `json:"ok"`
|
||||||
|
LatencyMS *int32 `json:"latency_ms"`
|
||||||
|
StatusCode *int32 `json:"status_code"`
|
||||||
|
Error *string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// insertResults stores results and keeps the newest per monitor and
|
||||||
|
// region in latest_results, which the console reads instead of a day of
|
||||||
|
// results.
|
||||||
|
func insertResults(ctx context.Context, q *store.Queries, rows []store.InsertCheckResultsParams) error {
|
||||||
|
if _, err := q.InsertCheckResults(ctx, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
latest := make([]latestRow, len(rows))
|
||||||
|
for i, r := range rows {
|
||||||
|
latest[i] = latestRow{
|
||||||
|
MonitorID: r.MonitorID, Region: r.Region, OrgID: r.OrgID, Time: r.Time, OK: r.Ok,
|
||||||
|
LatencyMS: r.LatencyMs, StatusCode: r.StatusCode, Error: r.Error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b, err := json.Marshal(latest)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return q.UpsertLatestResults(ctx, b)
|
||||||
|
}
|
||||||
@@ -55,6 +55,8 @@ type Server struct {
|
|||||||
limits *versioned[Limits]
|
limits *versioned[Limits]
|
||||||
// support caches how the platform runs support tickets.
|
// support caches how the platform runs support tickets.
|
||||||
support *versioned[supportSettings]
|
support *versioned[supportSettings]
|
||||||
|
// draining, once closed, ends the long polls of checkers.
|
||||||
|
draining <-chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deps are the external resources a Server needs.
|
// Deps are the external resources a Server needs.
|
||||||
@@ -94,6 +96,10 @@ func New(cfg config.API, d Deps) *Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EndLongPollsOn makes the checkers' long polls return as soon as ch is
|
||||||
|
// closed, as when the instance starts draining for a shutdown.
|
||||||
|
func (s *Server) EndLongPollsOn(ch <-chan struct{}) { s.draining = ch }
|
||||||
|
|
||||||
// Mount installs session loading, locale resolution and CSRF protection and
|
// Mount installs session loading, locale resolution and CSRF protection and
|
||||||
// registers the JSON API and the console pages below them.
|
// registers the JSON API and the console pages below them.
|
||||||
func (s *Server) Mount(r gin.IRouter) {
|
func (s *Server) Mount(r gin.IRouter) {
|
||||||
@@ -156,6 +162,7 @@ func (s *Server) Mount(r gin.IRouter) {
|
|||||||
// scoped to a group grant access below that group only.
|
// scoped to a group grant access below that group only.
|
||||||
org.GET("/monitors", s.listMonitors)
|
org.GET("/monitors", s.listMonitors)
|
||||||
org.POST("/monitors", s.createMonitor)
|
org.POST("/monitors", s.createMonitor)
|
||||||
|
org.PUT("/monitors/order", s.orderMonitors)
|
||||||
org.PUT("/monitors/:id", s.updateMonitor)
|
org.PUT("/monitors/:id", s.updateMonitor)
|
||||||
org.DELETE("/monitors/:id", s.deleteMonitor)
|
org.DELETE("/monitors/:id", s.deleteMonitor)
|
||||||
org.GET("/monitors/:id/evidence", s.listEvidence)
|
org.GET("/monitors/:id/evidence", s.listEvidence)
|
||||||
|
|||||||
@@ -84,10 +84,15 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
|||||||
for i, m := range listed {
|
for i, m := range listed {
|
||||||
ids[i] = m.MonitorID
|
ids[i] = m.MonitorID
|
||||||
}
|
}
|
||||||
if latest, err = q.LatestResults(ctx, page.OrgID); err != nil {
|
rows, err := q.LatestResultsForMonitors(ctx, store.LatestResultsForMonitorsParams{OrgID: page.OrgID, Ids: ids})
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if open, err = q.OpenIncidents(ctx); err != nil {
|
latest = make([]store.LatestResultsRow, len(rows))
|
||||||
|
for i, r := range rows {
|
||||||
|
latest[i] = store.LatestResultsRow(r)
|
||||||
|
}
|
||||||
|
if open, err = q.OpenIncidents(ctx, page.OrgID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if daily, err = q.DailyBucketsForMonitors(ctx, store.DailyBucketsForMonitorsParams{
|
if daily, err = q.DailyBucketsForMonitors(ctx, store.DailyBucketsForMonitorsParams{
|
||||||
@@ -97,7 +102,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
|||||||
}
|
}
|
||||||
if page.ShowComponentDetails {
|
if page.ShowComponentDetails {
|
||||||
if hourly, err = q.HourlyBuckets(ctx, store.HourlyBucketsParams{
|
if hourly, err = q.HourlyBuckets(ctx, store.HourlyBucketsParams{
|
||||||
OrgID: page.OrgID, Bucket: now.UTC().Add(-24 * time.Hour),
|
OrgID: page.OrgID, Bucket: now.UTC().Add(-24 * time.Hour), Ids: ids,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -698,6 +703,16 @@ func (s *Server) setPageMonitors(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// A page beyond a lowered limit may keep its monitors but not add any.
|
||||||
|
if max := s.orgLimits(ctx, p.Org).MonitorsPerPage; max > 0 && len(req.Monitors) > max {
|
||||||
|
had, err := q.CountStatusPageMonitors(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if int64(len(req.Monitors)) > had {
|
||||||
|
return limitError{"page_monitor_limit", max}
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := q.ClearStatusPageMonitors(ctx, id); err != nil {
|
if err := q.ClearStatusPageMonitors(ctx, id); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -725,6 +740,7 @@ func (s *Server) setPageMonitors(c *gin.Context) {
|
|||||||
case isForeignKeyViolation(err), isUniqueViolation(err, "status_page_monitors_pkey"):
|
case isForeignKeyViolation(err), isUniqueViolation(err, "status_page_monitors_pkey"):
|
||||||
// Unknown monitors, monitors of other orgs and duplicates.
|
// Unknown monitors, monitors of other orgs and duplicates.
|
||||||
fail(c, http.StatusUnprocessableEntity, "invalid_monitor")
|
fail(c, http.StatusUnprocessableEntity, "invalid_monitor")
|
||||||
|
case failLimit(c, err):
|
||||||
case err != nil:
|
case err != nil:
|
||||||
internalError(c, err)
|
internalError(c, err)
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ type API interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
pollWait = 20 * time.Second
|
pollWait = 20 * time.Second
|
||||||
|
// quickPoll is a long poll answered empty faster than any wait would.
|
||||||
|
quickPoll = 200 * time.Millisecond
|
||||||
flushInterval = 2 * time.Second
|
flushInterval = 2 * time.Second
|
||||||
// maxPending bounds results kept while the API is unreachable.
|
// maxPending bounds results kept while the API is unreachable.
|
||||||
maxPending = 50_000
|
maxPending = 50_000
|
||||||
@@ -127,6 +129,12 @@ func (r *Runner) Run(ctx context.Context, drain time.Duration) error {
|
|||||||
|
|
||||||
func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
||||||
backoff := time.Second
|
backoff := time.Second
|
||||||
|
// failing and failures track an outage, so its end is logged too: a log
|
||||||
|
// whose last line is an error otherwise reads as a checker stuck.
|
||||||
|
var (
|
||||||
|
failing time.Time
|
||||||
|
failures int
|
||||||
|
)
|
||||||
for ctx.Err() == nil {
|
for ctx.Err() == nil {
|
||||||
free := cap(r.slots) - len(r.slots)
|
free := cap(r.slots) - len(r.slots)
|
||||||
wait := pollWait
|
wait := pollWait
|
||||||
@@ -134,6 +142,7 @@ func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
|||||||
// Still poll as a heartbeat, but do not take work.
|
// Still poll as a heartbeat, but do not take work.
|
||||||
wait = 0
|
wait = 0
|
||||||
}
|
}
|
||||||
|
asked := time.Now()
|
||||||
jobs, err := r.api.Jobs(ctx, free, wait)
|
jobs, err := r.api.Jobs(ctx, free, wait)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, agentapi.ErrUnauthorized):
|
case errors.Is(err, agentapi.ErrUnauthorized):
|
||||||
@@ -143,11 +152,19 @@ func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
r.log.Warn("polling for jobs failed", "error", err, "retry_in", backoff)
|
r.log.Warn("polling for jobs failed", "error", err, "retry_in", backoff)
|
||||||
|
if failing.IsZero() {
|
||||||
|
failing = time.Now()
|
||||||
|
}
|
||||||
|
failures++
|
||||||
sleep(ctx, backoff)
|
sleep(ctx, backoff)
|
||||||
backoff = min(backoff*2, 30*time.Second)
|
backoff = min(backoff*2, 30*time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
backoff = time.Second
|
backoff = time.Second
|
||||||
|
if !failing.IsZero() {
|
||||||
|
r.log.Info("polling for jobs works again", "failed_for", time.Since(failing).Round(time.Second).String(), "failures", failures)
|
||||||
|
failing, failures = time.Time{}, 0
|
||||||
|
}
|
||||||
r.lastPoll.Store(time.Now().UnixMilli())
|
r.lastPoll.Store(time.Now().UnixMilli())
|
||||||
for _, j := range jobs {
|
for _, j := range jobs {
|
||||||
r.slots <- struct{}{}
|
r.slots <- struct{}{}
|
||||||
@@ -157,7 +174,9 @@ func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
|||||||
r.results <- r.execute(ctx, j)
|
r.results <- r.execute(ctx, j)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if free == 0 {
|
// A long poll answered empty at once, as by an instance shutting
|
||||||
|
// down, is not repeated at once either.
|
||||||
|
if free == 0 || (len(jobs) == 0 && wait > 0 && time.Since(asked) < quickPoll) {
|
||||||
sleep(ctx, time.Second)
|
sleep(ctx, time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,15 +207,27 @@ func (r *Runner) execute(ctx context.Context, j agentapi.Job) agentapi.Result {
|
|||||||
func (r *Runner) report(ctx context.Context) {
|
func (r *Runner) report(ctx context.Context) {
|
||||||
tick := time.NewTicker(flushInterval)
|
tick := time.NewTicker(flushInterval)
|
||||||
defer tick.Stop()
|
defer tick.Stop()
|
||||||
var pending []agentapi.Result
|
var (
|
||||||
|
pending []agentapi.Result
|
||||||
|
// failing is when reporting started to fail, zero while it works.
|
||||||
|
failing time.Time
|
||||||
|
)
|
||||||
flush := func(ctx context.Context) {
|
flush := func(ctx context.Context) {
|
||||||
|
sent := 0
|
||||||
for len(pending) > 0 {
|
for len(pending) > 0 {
|
||||||
n := min(len(pending), agentapi.MaxResults)
|
n := min(len(pending), agentapi.MaxResults)
|
||||||
if err := r.api.Report(ctx, pending[:n]); err != nil {
|
if err := r.api.Report(ctx, pending[:n]); err != nil {
|
||||||
r.log.Warn("reporting results failed", "error", err, "pending", len(pending))
|
r.log.Warn("reporting results failed", "error", err, "pending", len(pending))
|
||||||
|
if failing.IsZero() {
|
||||||
|
failing = time.Now()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pending = pending[n:]
|
pending, sent = pending[n:], sent+n
|
||||||
|
}
|
||||||
|
if !failing.IsZero() {
|
||||||
|
r.log.Info("reporting results works again", "failed_for", time.Since(failing).Round(time.Second).String(), "sent", sent)
|
||||||
|
failing = time.Time{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package checker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"log/slog"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/check"
|
||||||
|
)
|
||||||
|
|
||||||
|
// flakyAPI fails its first calls, like an API being rolled out.
|
||||||
|
type flakyAPI struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
jobFails int
|
||||||
|
reportFails int
|
||||||
|
gave bool
|
||||||
|
reported int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *flakyAPI) Jobs(ctx context.Context, _ int, wait time.Duration) ([]agentapi.Job, error) {
|
||||||
|
f.mu.Lock()
|
||||||
|
if f.jobFails > 0 {
|
||||||
|
f.jobFails--
|
||||||
|
f.mu.Unlock()
|
||||||
|
return nil, errors.New("504 Gateway Timeout")
|
||||||
|
}
|
||||||
|
if !f.gave {
|
||||||
|
f.gave = true
|
||||||
|
f.mu.Unlock()
|
||||||
|
return []agentapi.Job{{MonitorID: uuid.New(), Type: "tcp", Target: "x:1"}}, nil
|
||||||
|
}
|
||||||
|
f.mu.Unlock()
|
||||||
|
select {
|
||||||
|
case <-time.After(min(wait, 50*time.Millisecond)):
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *flakyAPI) Report(_ context.Context, rs []agentapi.Result) error {
|
||||||
|
f.mu.Lock()
|
||||||
|
defer f.mu.Unlock()
|
||||||
|
if f.reportFails > 0 {
|
||||||
|
f.reportFails--
|
||||||
|
return errors.New("context deadline exceeded")
|
||||||
|
}
|
||||||
|
f.reported += len(rs)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *flakyAPI) Release(context.Context) error { return nil }
|
||||||
|
|
||||||
|
type syncBuffer struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
b bytes.Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *syncBuffer) Write(p []byte) (int, error) {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
return s.b.Write(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *syncBuffer) String() string {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
return s.b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRecoveryIsLogged(t *testing.T) {
|
||||||
|
api := &flakyAPI{jobFails: 1, reportFails: 1}
|
||||||
|
var logs syncBuffer
|
||||||
|
r := New(api, 2, slog.New(slog.NewJSONHandler(&logs, nil)))
|
||||||
|
r.run = func(context.Context, check.Spec) check.Outcome { return check.Outcome{OK: true} }
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
done := make(chan error, 1)
|
||||||
|
go func() { done <- r.Run(ctx, time.Second) }()
|
||||||
|
|
||||||
|
deadline := time.Now().Add(10 * time.Second)
|
||||||
|
for time.Now().Before(deadline) {
|
||||||
|
out := logs.String()
|
||||||
|
if strings.Contains(out, "polling for jobs works again") && strings.Contains(out, "reporting results works again") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
}
|
||||||
|
cancel()
|
||||||
|
if err := <-done; err != nil {
|
||||||
|
t.Errorf("Run() = %v", err)
|
||||||
|
}
|
||||||
|
out := logs.String()
|
||||||
|
for _, want := range []string{`"msg":"polling for jobs works again"`, `"failures":1`, `"msg":"reporting results works again"`, `"sent":1`} {
|
||||||
|
if !strings.Contains(out, want) {
|
||||||
|
t.Errorf("log lacks %s:\n%s", want, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if n := strings.Count(out, "works again"); n != 2 {
|
||||||
|
t.Errorf("recovery logged %d times, want once each", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -107,6 +107,7 @@
|
|||||||
"audit.action.member.role_unassign": "Rolle entzogen",
|
"audit.action.member.role_unassign": "Rolle entzogen",
|
||||||
"audit.action.monitor.create": "Monitor erstellt",
|
"audit.action.monitor.create": "Monitor erstellt",
|
||||||
"audit.action.monitor.delete": "Monitor gelöscht",
|
"audit.action.monitor.delete": "Monitor gelöscht",
|
||||||
|
"audit.action.monitor.order": "Monitore angeordnet",
|
||||||
"audit.action.monitor.update": "Monitor geändert",
|
"audit.action.monitor.update": "Monitor geändert",
|
||||||
"audit.action.org.check_types_update": "Check-Typen geändert",
|
"audit.action.org.check_types_update": "Check-Typen geändert",
|
||||||
"audit.action.org.create": "Organisation angelegt",
|
"audit.action.org.create": "Organisation angelegt",
|
||||||
@@ -619,6 +620,7 @@
|
|||||||
"error.owner_cannot_be_removed": "Owner können nicht entfernt werden. Entziehe zuerst die Owner-Rechte.",
|
"error.owner_cannot_be_removed": "Owner können nicht entfernt werden. Entziehe zuerst die Owner-Rechte.",
|
||||||
"error.owner_has_all_permissions": "Der Owner hat bereits alle Berechtigungen.",
|
"error.owner_has_all_permissions": "Der Owner hat bereits alle Berechtigungen.",
|
||||||
"error.owner_only": "Nur Owner können ändern, wem die Organisation gehört.",
|
"error.owner_only": "Nur Owner können ändern, wem die Organisation gehört.",
|
||||||
|
"error.page_monitor_limit": "Eine Statusseite darf höchstens {{.Max}} Monitore zeigen.",
|
||||||
"error.password_too_short": "Das Passwort braucht mindestens {{.Min}} Zeichen.",
|
"error.password_too_short": "Das Passwort braucht mindestens {{.Min}} Zeichen.",
|
||||||
"error.permission_escalation": "Du kannst keine Berechtigungen vergeben, die du selbst nicht hast.",
|
"error.permission_escalation": "Du kannst keine Berechtigungen vergeben, die du selbst nicht hast.",
|
||||||
"error.platform_region_limit": "Ein Monitor darf aus höchstens {{.Max}} Plattform-Regionen geprüft werden; eigene Checker-Regionen zählen nicht.",
|
"error.platform_region_limit": "Ein Monitor darf aus höchstens {{.Max}} Plattform-Regionen geprüft werden; eigene Checker-Regionen zählen nicht.",
|
||||||
@@ -902,6 +904,7 @@
|
|||||||
"limits.default": "Standard: {{.Value}}",
|
"limits.default": "Standard: {{.Value}}",
|
||||||
"limits.intro": "Gelten für jede Organisation und jeden Account ohne eigenen Wert, auch wenn du sie später änderst. 0 heißt unbegrenzt. Ein gesenktes Limit lässt alles Bestehende stehen; nur neue Monitore, Statusseiten, Regionen oder Organisationen werden abgelehnt.",
|
"limits.intro": "Gelten für jede Organisation und jeden Account ohne eigenen Wert, auch wenn du sie später änderst. 0 heißt unbegrenzt. Ein gesenktes Limit lässt alles Bestehende stehen; nur neue Monitore, Statusseiten, Regionen oder Organisationen werden abgelehnt.",
|
||||||
"limits.monitors": "Monitore",
|
"limits.monitors": "Monitore",
|
||||||
|
"limits.monitors_per_page": "Monitore pro Statusseite",
|
||||||
"limits.org_title": "Kontingent",
|
"limits.org_title": "Kontingent",
|
||||||
"limits.orgs_per_account": "Organisationen pro Account",
|
"limits.orgs_per_account": "Organisationen pro Account",
|
||||||
"limits.own_false": "zählen nicht",
|
"limits.own_false": "zählen nicht",
|
||||||
@@ -1019,6 +1022,9 @@
|
|||||||
"monitors.alertmanager_hint": "Ausgefallen, solange ein Alert feuert, der alle Matcher erfüllt. Alerts kommen über einen Empfänger:",
|
"monitors.alertmanager_hint": "Ausgefallen, solange ein Alert feuert, der alle Matcher erfüllt. Alerts kommen über einen Empfänger:",
|
||||||
"monitors.all": "Alle Monitore",
|
"monitors.all": "Alle Monitore",
|
||||||
"monitors.all_results": "Alle Ergebnisse",
|
"monitors.all_results": "Alle Ergebnisse",
|
||||||
|
"monitors.arrange": "Monitore anordnen",
|
||||||
|
"monitors.arrange_done": "Anordnen beenden",
|
||||||
|
"monitors.arrange_hint": "Zieh die Monitore oder verschieb sie mit ↑ und ↓ in die gewünschte Reihenfolge innerhalb ihrer Gruppe. Jede Änderung wird sofort gespeichert und gilt für alle in der Organisation.",
|
||||||
"monitors.assertion_op": "Operator",
|
"monitors.assertion_op": "Operator",
|
||||||
"monitors.assertion_path": "Pfad",
|
"monitors.assertion_path": "Pfad",
|
||||||
"monitors.assertion_value": "Wert",
|
"monitors.assertion_value": "Wert",
|
||||||
@@ -1064,6 +1070,13 @@
|
|||||||
"monitors.docker_host": "Docker-Host (unix://-Socket oder tcp://host:2375)",
|
"monitors.docker_host": "Docker-Host (unix://-Socket oder tcp://host:2375)",
|
||||||
"monitors.edit": "Monitor bearbeiten",
|
"monitors.edit": "Monitor bearbeiten",
|
||||||
"monitors.expect_status": "Erwarteter Status (z. B. 2xx, 301)",
|
"monitors.expect_status": "Erwarteter Status (z. B. 2xx, 301)",
|
||||||
|
"monitors.filter_clear": "Alle Status anzeigen",
|
||||||
|
"monitors.filter_label": "Monitore nach Status anzeigen",
|
||||||
|
"monitors.filter_only": "Nur",
|
||||||
|
"monitors.filter_show": {
|
||||||
|
"one": "Nur den {{.Count}} Monitor mit Status „{{.Status}}“ anzeigen",
|
||||||
|
"other": "Nur die {{.Count}} Monitore mit Status „{{.Status}}“ anzeigen"
|
||||||
|
},
|
||||||
"monitors.follow_redirects": "Weiterleitungen folgen",
|
"monitors.follow_redirects": "Weiterleitungen folgen",
|
||||||
"monitors.game_min_free_slots": "Mindestens freie Plätze",
|
"monitors.game_min_free_slots": "Mindestens freie Plätze",
|
||||||
"monitors.game_min_free_slots_hint": "0 prüft nur, ob der Server antwortet.",
|
"monitors.game_min_free_slots_hint": "0 prüft nur, ob der Server antwortet.",
|
||||||
@@ -1090,10 +1103,13 @@
|
|||||||
"monitors.minecraft_edition": "Edition",
|
"monitors.minecraft_edition": "Edition",
|
||||||
"monitors.minecraft_hint": "Ziel ist host:port (Java meist 25565, Bedrock 19132). Pingt den Server wie die Serverliste im Spiel.",
|
"monitors.minecraft_hint": "Ziel ist host:port (Java meist 25565, Bedrock 19132). Pingt den Server wie die Serverliste im Spiel.",
|
||||||
"monitors.minecraft_java": "Java Edition",
|
"monitors.minecraft_java": "Java Edition",
|
||||||
|
"monitors.move_down": "{{.Name}} nach unten",
|
||||||
|
"monitors.move_up": "{{.Name}} nach oben",
|
||||||
"monitors.new": "Neuer Monitor",
|
"monitors.new": "Neuer Monitor",
|
||||||
"monitors.no_data_since": "keine Daten seit {{.Time}}",
|
"monitors.no_data_since": "keine Daten seit {{.Time}}",
|
||||||
"monitors.no_match": "Kein Monitor gefunden.",
|
"monitors.no_match": "Kein Monitor gefunden.",
|
||||||
"monitors.no_results": "Noch keine Ergebnisse.",
|
"monitors.no_results": "Noch keine Ergebnisse.",
|
||||||
|
"monitors.no_status_match": "Gerade hat kein Monitor diesen Status.",
|
||||||
"monitors.op_absent": "fehlt",
|
"monitors.op_absent": "fehlt",
|
||||||
"monitors.op_contains": "enthält",
|
"monitors.op_contains": "enthält",
|
||||||
"monitors.op_eq": "gleich",
|
"monitors.op_eq": "gleich",
|
||||||
@@ -1144,6 +1160,12 @@
|
|||||||
"monitors.snmp_oid": "OID",
|
"monitors.snmp_oid": "OID",
|
||||||
"monitors.snmp_value": "Wert",
|
"monitors.snmp_value": "Wert",
|
||||||
"monitors.snmp_version": "Version",
|
"monitors.snmp_version": "Version",
|
||||||
|
"monitors.sort": "Sortierung",
|
||||||
|
"monitors.sort_custom": "eigene Reihenfolge",
|
||||||
|
"monitors.sort_latency": "Latenz",
|
||||||
|
"monitors.sort_name": "Name",
|
||||||
|
"monitors.sort_status": "Status",
|
||||||
|
"monitors.sort_uptime": "Uptime",
|
||||||
"monitors.stale_hours": "Verfällt nach (Stunden)",
|
"monitors.stale_hours": "Verfällt nach (Stunden)",
|
||||||
"monitors.stale_hours_hint": "Ein feuernder Alert, den Alertmanager nicht mehr wiederholt, gilt nach dieser Zeit als beendet. Halte sie über repeat_interval.",
|
"monitors.stale_hours_hint": "Ein feuernder Alert, den Alertmanager nicht mehr wiederholt, gilt nach dieser Zeit als beendet. Halte sie über repeat_interval.",
|
||||||
"monitors.steam_hint": "Ziel ist host:port des Query-Ports (meist der Spielport, z. B. 27015). Fragt den Server wie der Steam-Serverbrowser nach seinen Infos (A2S); funktioniert für Source- und die meisten Steam-Spiele.",
|
"monitors.steam_hint": "Ziel ist host:port des Query-Ports (meist der Spielport, z. B. 27015). Fragt den Server wie der Steam-Serverbrowser nach seinen Infos (A2S); funktioniert für Source- und die meisten Steam-Spiele.",
|
||||||
@@ -1282,6 +1304,10 @@
|
|||||||
"pages.intro": "Öffentliche Seiten mit dem Zustand ausgewählter Monitore. Jede Seite kann eine eigene Domain nutzen oder als einzelne HTML-Datei exportiert werden.",
|
"pages.intro": "Öffentliche Seiten mit dem Zustand ausgewählter Monitore. Jede Seite kann eine eigene Domain nutzen oder als einzelne HTML-Datei exportiert werden.",
|
||||||
"pages.label": "Öffentlicher Name",
|
"pages.label": "Öffentlicher Name",
|
||||||
"pages.logo": "Logo-URL (https)",
|
"pages.logo": "Logo-URL (https)",
|
||||||
|
"pages.monitor_limit": "Diese Seite darf höchstens {{.Max}} Monitore zeigen.",
|
||||||
|
"pages.monitors_filter": "Monitore filtern",
|
||||||
|
"pages.monitors_all": "Alle hinzufügen",
|
||||||
|
"pages.monitors_none": "Alle entfernen",
|
||||||
"pages.no_group": "Ohne Gruppe",
|
"pages.no_group": "Ohne Gruppe",
|
||||||
"pages.open": "Öffnen",
|
"pages.open": "Öffnen",
|
||||||
"pages.own_servers": "Die Statusseiten dieser Organisation liefern nur ihre eigenen Statusseiten-Server aus, nicht die der Plattform. Ruf sie über die Adresse deiner Server auf oder verbinde eine eigene Domain, die auf sie zeigt.",
|
"pages.own_servers": "Die Statusseiten dieser Organisation liefern nur ihre eigenen Statusseiten-Server aus, nicht die der Plattform. Ruf sie über die Adresse deiner Server auf oder verbinde eine eigene Domain, die auf sie zeigt.",
|
||||||
|
|||||||
@@ -107,6 +107,7 @@
|
|||||||
"audit.action.member.role_unassign": "Role removed",
|
"audit.action.member.role_unassign": "Role removed",
|
||||||
"audit.action.monitor.create": "Monitor created",
|
"audit.action.monitor.create": "Monitor created",
|
||||||
"audit.action.monitor.delete": "Monitor deleted",
|
"audit.action.monitor.delete": "Monitor deleted",
|
||||||
|
"audit.action.monitor.order": "Monitors put in order",
|
||||||
"audit.action.monitor.update": "Monitor changed",
|
"audit.action.monitor.update": "Monitor changed",
|
||||||
"audit.action.org.check_types_update": "Check types changed",
|
"audit.action.org.check_types_update": "Check types changed",
|
||||||
"audit.action.org.create": "Organization created",
|
"audit.action.org.create": "Organization created",
|
||||||
@@ -619,6 +620,7 @@
|
|||||||
"error.owner_cannot_be_removed": "Owners cannot be removed. Take their ownership away first.",
|
"error.owner_cannot_be_removed": "Owners cannot be removed. Take their ownership away first.",
|
||||||
"error.owner_has_all_permissions": "The owner already has every permission.",
|
"error.owner_has_all_permissions": "The owner already has every permission.",
|
||||||
"error.owner_only": "Only owners can change who owns the organization.",
|
"error.owner_only": "Only owners can change who owns the organization.",
|
||||||
|
"error.page_monitor_limit": "A status page may show at most {{.Max}} monitors.",
|
||||||
"error.password_too_short": "The password needs at least {{.Min}} characters.",
|
"error.password_too_short": "The password needs at least {{.Min}} characters.",
|
||||||
"error.permission_escalation": "You cannot grant permissions you do not hold yourself.",
|
"error.permission_escalation": "You cannot grant permissions you do not hold yourself.",
|
||||||
"error.platform_region_limit": "A monitor may be checked from at most {{.Max}} platform regions; your own checker regions do not count.",
|
"error.platform_region_limit": "A monitor may be checked from at most {{.Max}} platform regions; your own checker regions do not count.",
|
||||||
@@ -902,6 +904,7 @@
|
|||||||
"limits.default": "default: {{.Value}}",
|
"limits.default": "default: {{.Value}}",
|
||||||
"limits.intro": "Apply to every organization and account without an override of its own, also when you change them later. 0 means unlimited. Lowering a limit keeps everything that exists; only new monitors, status pages, regions or organizations are refused.",
|
"limits.intro": "Apply to every organization and account without an override of its own, also when you change them later. 0 means unlimited. Lowering a limit keeps everything that exists; only new monitors, status pages, regions or organizations are refused.",
|
||||||
"limits.monitors": "Monitors",
|
"limits.monitors": "Monitors",
|
||||||
|
"limits.monitors_per_page": "Monitors per status page",
|
||||||
"limits.org_title": "Usage",
|
"limits.org_title": "Usage",
|
||||||
"limits.orgs_per_account": "Organizations per account",
|
"limits.orgs_per_account": "Organizations per account",
|
||||||
"limits.own_false": "do not count",
|
"limits.own_false": "do not count",
|
||||||
@@ -1019,6 +1022,9 @@
|
|||||||
"monitors.alertmanager_hint": "Down while an alert matching all matchers fires. Alerts arrive through a receiver:",
|
"monitors.alertmanager_hint": "Down while an alert matching all matchers fires. Alerts arrive through a receiver:",
|
||||||
"monitors.all": "All monitors",
|
"monitors.all": "All monitors",
|
||||||
"monitors.all_results": "All results",
|
"monitors.all_results": "All results",
|
||||||
|
"monitors.arrange": "Arrange monitors",
|
||||||
|
"monitors.arrange_done": "Done arranging",
|
||||||
|
"monitors.arrange_hint": "Drag the monitors, or move them with ↑ and ↓, into the order you want within each group. Every change is saved at once and is the same for everybody in the organization.",
|
||||||
"monitors.assertion_op": "Operator",
|
"monitors.assertion_op": "Operator",
|
||||||
"monitors.assertion_path": "Path",
|
"monitors.assertion_path": "Path",
|
||||||
"monitors.assertion_value": "Value",
|
"monitors.assertion_value": "Value",
|
||||||
@@ -1064,6 +1070,13 @@
|
|||||||
"monitors.docker_host": "Docker host (unix:// socket or tcp://host:2375)",
|
"monitors.docker_host": "Docker host (unix:// socket or tcp://host:2375)",
|
||||||
"monitors.edit": "Edit monitor",
|
"monitors.edit": "Edit monitor",
|
||||||
"monitors.expect_status": "Expected status (e.g. 2xx, 301)",
|
"monitors.expect_status": "Expected status (e.g. 2xx, 301)",
|
||||||
|
"monitors.filter_clear": "Show all statuses",
|
||||||
|
"monitors.filter_label": "Show monitors by status",
|
||||||
|
"monitors.filter_only": "Only",
|
||||||
|
"monitors.filter_show": {
|
||||||
|
"one": "Show only the {{.Count}} monitor that is {{.Status}}",
|
||||||
|
"other": "Show only the {{.Count}} monitors that are {{.Status}}"
|
||||||
|
},
|
||||||
"monitors.follow_redirects": "Follow redirects",
|
"monitors.follow_redirects": "Follow redirects",
|
||||||
"monitors.game_min_free_slots": "Minimum free slots",
|
"monitors.game_min_free_slots": "Minimum free slots",
|
||||||
"monitors.game_min_free_slots_hint": "0 only checks that the server answers.",
|
"monitors.game_min_free_slots_hint": "0 only checks that the server answers.",
|
||||||
@@ -1090,10 +1103,13 @@
|
|||||||
"monitors.minecraft_edition": "Edition",
|
"monitors.minecraft_edition": "Edition",
|
||||||
"monitors.minecraft_hint": "Target is host:port (Java usually 25565, Bedrock 19132). Pings the server like the in-game server list.",
|
"monitors.minecraft_hint": "Target is host:port (Java usually 25565, Bedrock 19132). Pings the server like the in-game server list.",
|
||||||
"monitors.minecraft_java": "Java Edition",
|
"monitors.minecraft_java": "Java Edition",
|
||||||
|
"monitors.move_down": "Move {{.Name}} down",
|
||||||
|
"monitors.move_up": "Move {{.Name}} up",
|
||||||
"monitors.new": "New monitor",
|
"monitors.new": "New monitor",
|
||||||
"monitors.no_data_since": "no data since {{.Time}}",
|
"monitors.no_data_since": "no data since {{.Time}}",
|
||||||
"monitors.no_match": "No monitor matches.",
|
"monitors.no_match": "No monitor matches.",
|
||||||
"monitors.no_results": "No results yet.",
|
"monitors.no_results": "No results yet.",
|
||||||
|
"monitors.no_status_match": "No monitor has this status right now.",
|
||||||
"monitors.op_absent": "is absent",
|
"monitors.op_absent": "is absent",
|
||||||
"monitors.op_contains": "contains",
|
"monitors.op_contains": "contains",
|
||||||
"monitors.op_eq": "equals",
|
"monitors.op_eq": "equals",
|
||||||
@@ -1144,6 +1160,12 @@
|
|||||||
"monitors.snmp_oid": "OID",
|
"monitors.snmp_oid": "OID",
|
||||||
"monitors.snmp_value": "Value",
|
"monitors.snmp_value": "Value",
|
||||||
"monitors.snmp_version": "Version",
|
"monitors.snmp_version": "Version",
|
||||||
|
"monitors.sort": "Sort order",
|
||||||
|
"monitors.sort_custom": "own order",
|
||||||
|
"monitors.sort_latency": "latency",
|
||||||
|
"monitors.sort_name": "name",
|
||||||
|
"monitors.sort_status": "status",
|
||||||
|
"monitors.sort_uptime": "uptime",
|
||||||
"monitors.stale_hours": "Stale after (hours)",
|
"monitors.stale_hours": "Stale after (hours)",
|
||||||
"monitors.stale_hours_hint": "A firing alert Alertmanager stops repeating counts as over after this time. Keep it above repeat_interval.",
|
"monitors.stale_hours_hint": "A firing alert Alertmanager stops repeating counts as over after this time. Keep it above repeat_interval.",
|
||||||
"monitors.steam_hint": "Target is host:port of the query port (usually the game port, e.g. 27015). Asks the server for its info like the Steam server browser (A2S); works for Source and most Steam games.",
|
"monitors.steam_hint": "Target is host:port of the query port (usually the game port, e.g. 27015). Asks the server for its info like the Steam server browser (A2S); works for Source and most Steam games.",
|
||||||
@@ -1282,6 +1304,10 @@
|
|||||||
"pages.intro": "Public pages showing the state of selected monitors. Each page can use its own domain or be exported as a single HTML file.",
|
"pages.intro": "Public pages showing the state of selected monitors. Each page can use its own domain or be exported as a single HTML file.",
|
||||||
"pages.label": "Public name",
|
"pages.label": "Public name",
|
||||||
"pages.logo": "Logo URL (https)",
|
"pages.logo": "Logo URL (https)",
|
||||||
|
"pages.monitor_limit": "This page may show at most {{.Max}} monitors.",
|
||||||
|
"pages.monitors_filter": "Filter monitors",
|
||||||
|
"pages.monitors_all": "Add all",
|
||||||
|
"pages.monitors_none": "Remove all",
|
||||||
"pages.no_group": "No group",
|
"pages.no_group": "No group",
|
||||||
"pages.open": "Open",
|
"pages.open": "Open",
|
||||||
"pages.own_servers": "Your organization's own status page servers serve its pages; the platform's do not. Open them at the address of your servers or connect a custom domain pointing at them.",
|
"pages.own_servers": "Your organization's own status page servers serve its pages; the platform's do not. Open them at the address of your servers or connect a custom domain pointing at them.",
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- How many monitors one status page of the organization may show; NULL
|
||||||
|
-- follows the platform default, 0 means unlimited.
|
||||||
|
ALTER TABLE orgs ADD COLUMN limit_monitors_per_page integer CHECK (limit_monitors_per_page >= 0);
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER TABLE orgs DROP COLUMN limit_monitors_per_page;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- The organization's own order of its monitors on the monitor list, within
|
||||||
|
-- each group; NULL sorts after positioned monitors, by name.
|
||||||
|
ALTER TABLE monitors ADD COLUMN position integer;
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER TABLE monitors DROP COLUMN position;
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
-- +goose Up
|
||||||
|
-- The newest result per monitor and region, kept up to date as results
|
||||||
|
-- arrive. Finding it in check_results means reading a day of results of
|
||||||
|
-- every monitor, which made every console page slow for organizations
|
||||||
|
-- with many monitors.
|
||||||
|
CREATE TABLE latest_results (
|
||||||
|
monitor_id uuid NOT NULL,
|
||||||
|
region text NOT NULL,
|
||||||
|
org_id uuid NOT NULL,
|
||||||
|
time timestamptz NOT NULL,
|
||||||
|
ok boolean NOT NULL,
|
||||||
|
latency_ms integer,
|
||||||
|
status_code integer,
|
||||||
|
error text,
|
||||||
|
PRIMARY KEY (monitor_id, region),
|
||||||
|
FOREIGN KEY (monitor_id, org_id) REFERENCES monitors (id, org_id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX latest_results_org_idx ON latest_results (org_id);
|
||||||
|
|
||||||
|
INSERT INTO latest_results (monitor_id, region, org_id, time, ok, latency_ms, status_code, error)
|
||||||
|
SELECT DISTINCT ON (r.monitor_id, r.region) r.monitor_id, r.region, r.org_id, r.time, r.ok, r.latency_ms, r.status_code, r.error
|
||||||
|
FROM check_results r
|
||||||
|
JOIN monitors m ON m.id = r.monitor_id AND m.org_id = r.org_id
|
||||||
|
WHERE r.time > now() - INTERVAL '1 day'
|
||||||
|
ORDER BY r.monitor_id, r.region, r.time DESC;
|
||||||
|
|
||||||
|
ALTER TABLE latest_results ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE latest_results FORCE ROW LEVEL SECURITY;
|
||||||
|
CREATE POLICY latest_results_tenant ON latest_results FOR ALL
|
||||||
|
USING (app_scope_system() OR org_id = app_org_id())
|
||||||
|
WITH CHECK (app_scope_system() OR org_id = app_org_id());
|
||||||
|
|
||||||
|
-- Console queries name the organization so that these can be used; row
|
||||||
|
-- security alone does not let the planner use an index.
|
||||||
|
CREATE INDEX monitor_regions_org_idx ON monitor_regions (org_id);
|
||||||
|
CREATE INDEX incidents_open_org_idx ON incidents (org_id) WHERE resolved_at IS NULL;
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
DROP INDEX incidents_open_org_idx;
|
||||||
|
DROP INDEX monitor_regions_org_idx;
|
||||||
|
DROP TABLE latest_results;
|
||||||
@@ -3,6 +3,7 @@ package platform
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -17,15 +18,24 @@ type Probe func(context.Context) error
|
|||||||
type Health struct {
|
type Health struct {
|
||||||
probes map[string]Probe
|
probes map[string]Probe
|
||||||
draining atomic.Bool
|
draining atomic.Bool
|
||||||
|
drained chan struct{}
|
||||||
|
once sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHealth returns a Health that is ready while all probes pass.
|
// NewHealth returns a Health that is ready while all probes pass.
|
||||||
func NewHealth(probes map[string]Probe) *Health {
|
func NewHealth(probes map[string]Probe) *Health {
|
||||||
return &Health{probes: probes}
|
return &Health{probes: probes, drained: make(chan struct{})}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drain makes /readyz fail permanently. Call it before shutdown.
|
// Drain makes /readyz fail permanently. Call it before shutdown.
|
||||||
func (h *Health) Drain() { h.draining.Store(true) }
|
func (h *Health) Drain() {
|
||||||
|
h.draining.Store(true)
|
||||||
|
h.once.Do(func() { close(h.drained) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draining is closed once Drain is called, so long-running requests can
|
||||||
|
// end early instead of holding up the shutdown.
|
||||||
|
func (h *Health) Draining() <-chan struct{} { return h.drained }
|
||||||
|
|
||||||
// Register mounts /healthz (liveness) and /readyz (readiness).
|
// Register mounts /healthz (liveness) and /readyz (readiness).
|
||||||
func (h *Health) Register(r gin.IRoutes) {
|
func (h *Health) Register(r gin.IRoutes) {
|
||||||
|
|||||||
@@ -124,22 +124,65 @@ func (q *Queries) DailyBucketsForMonitors(ctx context.Context, arg DailyBucketsF
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const earliestDataDaily = `-- name: EarliestDataDaily :one
|
||||||
|
SELECT bucket::timestamptz AS first FROM check_results_1d WHERE org_id = $1 ORDER BY bucket LIMIT 1
|
||||||
|
`
|
||||||
|
|
||||||
|
// The day the organization's monitors first reported, if any did.
|
||||||
|
func (q *Queries) EarliestDataDaily(ctx context.Context, orgID uuid.UUID) (time.Time, error) {
|
||||||
|
row := q.db.QueryRow(ctx, earliestDataDaily, orgID)
|
||||||
|
var first time.Time
|
||||||
|
err := row.Scan(&first)
|
||||||
|
return first, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const earliestDataRecent = `-- name: EarliestDataRecent :one
|
||||||
|
SELECT f.time FROM monitors m
|
||||||
|
CROSS JOIN LATERAL (
|
||||||
|
SELECT c.time FROM check_results c
|
||||||
|
WHERE c.org_id = $1 AND c.monitor_id = m.id AND c.time >= $2
|
||||||
|
ORDER BY c.time LIMIT 1
|
||||||
|
) f
|
||||||
|
WHERE m.org_id = $1
|
||||||
|
ORDER BY f.time LIMIT 1
|
||||||
|
`
|
||||||
|
|
||||||
|
type EarliestDataRecentParams struct {
|
||||||
|
OrgID uuid.UUID
|
||||||
|
Time time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// When the organization's monitors first reported since $2, exactly: the
|
||||||
|
// first result of each monitor is found through its index, so the cost
|
||||||
|
// does not grow with the days of results.
|
||||||
|
func (q *Queries) EarliestDataRecent(ctx context.Context, arg EarliestDataRecentParams) (time.Time, error) {
|
||||||
|
row := q.db.QueryRow(ctx, earliestDataRecent, arg.OrgID, arg.Time)
|
||||||
|
var time time.Time
|
||||||
|
err := row.Scan(&time)
|
||||||
|
return time, err
|
||||||
|
}
|
||||||
|
|
||||||
const firstDataDaily = `-- name: FirstDataDaily :many
|
const firstDataDaily = `-- name: FirstDataDaily :many
|
||||||
SELECT monitor_id, region, min(bucket)::timestamptz AS first
|
SELECT monitor_id, region, min(bucket)::timestamptz AS first
|
||||||
FROM check_results_1d
|
FROM check_results_1d
|
||||||
WHERE org_id = $1
|
WHERE org_id = $1 AND monitor_id = $2
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
|
type FirstDataDailyParams struct {
|
||||||
|
OrgID uuid.UUID
|
||||||
|
MonitorID uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
type FirstDataDailyRow struct {
|
type FirstDataDailyRow struct {
|
||||||
MonitorID uuid.UUID
|
MonitorID uuid.UUID
|
||||||
Region string
|
Region string
|
||||||
First time.Time
|
First time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// When each monitor and region first reported, to the day.
|
// When each region of a monitor first reported, to the day.
|
||||||
func (q *Queries) FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstDataDailyRow, error) {
|
func (q *Queries) FirstDataDaily(ctx context.Context, arg FirstDataDailyParams) ([]FirstDataDailyRow, error) {
|
||||||
rows, err := q.db.Query(ctx, firstDataDaily, orgID)
|
rows, err := q.db.Query(ctx, firstDataDaily, arg.OrgID, arg.MonitorID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -161,13 +204,14 @@ func (q *Queries) FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstD
|
|||||||
const firstDataRecent = `-- name: FirstDataRecent :many
|
const firstDataRecent = `-- name: FirstDataRecent :many
|
||||||
SELECT monitor_id, region, min(time)::timestamptz AS first
|
SELECT monitor_id, region, min(time)::timestamptz AS first
|
||||||
FROM check_results
|
FROM check_results
|
||||||
WHERE org_id = $1 AND time >= $2
|
WHERE org_id = $1 AND monitor_id = $2 AND time >= $3
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
type FirstDataRecentParams struct {
|
type FirstDataRecentParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Time time.Time
|
MonitorID uuid.UUID
|
||||||
|
Time time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type FirstDataRecentRow struct {
|
type FirstDataRecentRow struct {
|
||||||
@@ -176,10 +220,10 @@ type FirstDataRecentRow struct {
|
|||||||
First time.Time
|
First time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// When each monitor and region first reported since $2, exactly. Used for
|
// When each region of a monitor first reported since $3, exactly. Used for
|
||||||
// data younger than the daily aggregate's resolution.
|
// data younger than the daily aggregate's resolution.
|
||||||
func (q *Queries) FirstDataRecent(ctx context.Context, arg FirstDataRecentParams) ([]FirstDataRecentRow, error) {
|
func (q *Queries) FirstDataRecent(ctx context.Context, arg FirstDataRecentParams) ([]FirstDataRecentRow, error) {
|
||||||
rows, err := q.db.Query(ctx, firstDataRecent, arg.OrgID, arg.Time)
|
rows, err := q.db.Query(ctx, firstDataRecent, arg.OrgID, arg.MonitorID, arg.Time)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -203,6 +247,7 @@ SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, s
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1h
|
FROM check_results_1h
|
||||||
WHERE org_id = $1 AND bucket >= $2
|
WHERE org_id = $1 AND bucket >= $2
|
||||||
|
AND ($3::uuid[] IS NULL OR monitor_id = ANY ($3::uuid[]))
|
||||||
GROUP BY monitor_id, bucket
|
GROUP BY monitor_id, bucket
|
||||||
ORDER BY monitor_id, bucket
|
ORDER BY monitor_id, bucket
|
||||||
`
|
`
|
||||||
@@ -210,6 +255,7 @@ ORDER BY monitor_id, bucket
|
|||||||
type HourlyBucketsParams struct {
|
type HourlyBucketsParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Bucket interface{}
|
Bucket interface{}
|
||||||
|
Ids []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type HourlyBucketsRow struct {
|
type HourlyBucketsRow struct {
|
||||||
@@ -222,7 +268,7 @@ type HourlyBucketsRow struct {
|
|||||||
|
|
||||||
// Per monitor and hour since $2, across all regions.
|
// Per monitor and hour since $2, across all regions.
|
||||||
func (q *Queries) HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error) {
|
func (q *Queries) HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error) {
|
||||||
rows, err := q.db.Query(ctx, hourlyBuckets, arg.OrgID, arg.Bucket)
|
rows, err := q.db.Query(ctx, hourlyBuckets, arg.OrgID, arg.Bucket, arg.Ids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -259,52 +305,6 @@ type InsertCheckResultsParams struct {
|
|||||||
Error *string
|
Error *string
|
||||||
}
|
}
|
||||||
|
|
||||||
const latestResults = `-- name: LatestResults :many
|
|
||||||
SELECT DISTINCT ON (monitor_id, region) monitor_id, region, time, ok, latency_ms, status_code, error
|
|
||||||
FROM check_results
|
|
||||||
WHERE org_id = $1 AND time > now() - interval '1 day'
|
|
||||||
ORDER BY monitor_id, region, time DESC
|
|
||||||
`
|
|
||||||
|
|
||||||
type LatestResultsRow struct {
|
|
||||||
MonitorID uuid.UUID
|
|
||||||
Region string
|
|
||||||
Time time.Time
|
|
||||||
Ok bool
|
|
||||||
LatencyMs *int32
|
|
||||||
StatusCode *int32
|
|
||||||
Error *string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Newest result per monitor and region in the org.
|
|
||||||
func (q *Queries) LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error) {
|
|
||||||
rows, err := q.db.Query(ctx, latestResults, orgID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
items := []LatestResultsRow{}
|
|
||||||
for rows.Next() {
|
|
||||||
var i LatestResultsRow
|
|
||||||
if err := rows.Scan(
|
|
||||||
&i.MonitorID,
|
|
||||||
&i.Region,
|
|
||||||
&i.Time,
|
|
||||||
&i.Ok,
|
|
||||||
&i.LatencyMs,
|
|
||||||
&i.StatusCode,
|
|
||||||
&i.Error,
|
|
||||||
); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
items = append(items, i)
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return items, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const latestResultsForMonitor = `-- name: LatestResultsForMonitor :many
|
const latestResultsForMonitor = `-- name: LatestResultsForMonitor :many
|
||||||
SELECT DISTINCT ON (region) region, ok, error
|
SELECT DISTINCT ON (region) region, ok, error
|
||||||
FROM check_results
|
FROM check_results
|
||||||
@@ -425,16 +425,16 @@ SELECT monitor_id, time_bucket($2::text::interval, time)::timestamptz AS bucket,
|
|||||||
coalesce(avg(latency_ms), 0)::real AS avg_latency_ms
|
coalesce(avg(latency_ms), 0)::real AS avg_latency_ms
|
||||||
FROM check_results
|
FROM check_results
|
||||||
WHERE org_id = $1 AND time >= $3
|
WHERE org_id = $1 AND time >= $3
|
||||||
AND ($4::uuid IS NULL OR monitor_id = $4)
|
AND monitor_id = ANY ($4::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2
|
ORDER BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
type RangeBucketsParams struct {
|
type RangeBucketsParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Width string
|
Width string
|
||||||
Since time.Time
|
Since time.Time
|
||||||
MonitorID *uuid.UUID
|
Ids []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type RangeBucketsRow struct {
|
type RangeBucketsRow struct {
|
||||||
@@ -451,7 +451,7 @@ func (q *Queries) RangeBuckets(ctx context.Context, arg RangeBucketsParams) ([]R
|
|||||||
arg.OrgID,
|
arg.OrgID,
|
||||||
arg.Width,
|
arg.Width,
|
||||||
arg.Since,
|
arg.Since,
|
||||||
arg.MonitorID,
|
arg.Ids,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -483,16 +483,16 @@ SELECT monitor_id, time_bucket($2::text::interval, bucket)::timestamptz AS bucke
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1d
|
FROM check_results_1d
|
||||||
WHERE org_id = $1 AND bucket >= $3
|
WHERE org_id = $1 AND bucket >= $3
|
||||||
AND ($4::uuid IS NULL OR monitor_id = $4)
|
AND monitor_id = ANY ($4::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2
|
ORDER BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
type RangeBucketsDailyParams struct {
|
type RangeBucketsDailyParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Width string
|
Width string
|
||||||
Since interface{}
|
Since interface{}
|
||||||
MonitorID *uuid.UUID
|
Ids []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type RangeBucketsDailyRow struct {
|
type RangeBucketsDailyRow struct {
|
||||||
@@ -509,7 +509,7 @@ func (q *Queries) RangeBucketsDaily(ctx context.Context, arg RangeBucketsDailyPa
|
|||||||
arg.OrgID,
|
arg.OrgID,
|
||||||
arg.Width,
|
arg.Width,
|
||||||
arg.Since,
|
arg.Since,
|
||||||
arg.MonitorID,
|
arg.Ids,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -541,16 +541,16 @@ SELECT monitor_id, time_bucket($2::text::interval, bucket)::timestamptz AS bucke
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1h
|
FROM check_results_1h
|
||||||
WHERE org_id = $1 AND bucket >= $3
|
WHERE org_id = $1 AND bucket >= $3
|
||||||
AND ($4::uuid IS NULL OR monitor_id = $4)
|
AND monitor_id = ANY ($4::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2
|
ORDER BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
type RangeBucketsHourlyParams struct {
|
type RangeBucketsHourlyParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Width string
|
Width string
|
||||||
Since interface{}
|
Since interface{}
|
||||||
MonitorID *uuid.UUID
|
Ids []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type RangeBucketsHourlyRow struct {
|
type RangeBucketsHourlyRow struct {
|
||||||
@@ -567,7 +567,7 @@ func (q *Queries) RangeBucketsHourly(ctx context.Context, arg RangeBucketsHourly
|
|||||||
arg.OrgID,
|
arg.OrgID,
|
||||||
arg.Width,
|
arg.Width,
|
||||||
arg.Since,
|
arg.Since,
|
||||||
arg.MonitorID,
|
arg.Ids,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -313,18 +313,23 @@ func (q *Queries) IncidentsForMonitors(ctx context.Context, arg IncidentsForMoni
|
|||||||
|
|
||||||
const incidentsSince = `-- name: IncidentsSince :many
|
const incidentsSince = `-- name: IncidentsSince :many
|
||||||
SELECT monitor_id, started_at, resolved_at FROM incidents
|
SELECT monitor_id, started_at, resolved_at FROM incidents
|
||||||
WHERE resolved_at IS NULL OR resolved_at > $1
|
WHERE org_id = $1 AND (resolved_at IS NULL OR resolved_at > $2)
|
||||||
`
|
`
|
||||||
|
|
||||||
|
type IncidentsSinceParams struct {
|
||||||
|
OrgID uuid.UUID
|
||||||
|
ResolvedAt *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type IncidentsSinceRow struct {
|
type IncidentsSinceRow struct {
|
||||||
MonitorID uuid.UUID
|
MonitorID uuid.UUID
|
||||||
StartedAt time.Time
|
StartedAt time.Time
|
||||||
ResolvedAt *time.Time
|
ResolvedAt *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incidents overlapping the time since $1, for SLA calculation.
|
// Incidents overlapping the time since $2, for SLA calculation.
|
||||||
func (q *Queries) IncidentsSince(ctx context.Context, resolvedAt *time.Time) ([]IncidentsSinceRow, error) {
|
func (q *Queries) IncidentsSince(ctx context.Context, arg IncidentsSinceParams) ([]IncidentsSinceRow, error) {
|
||||||
rows, err := q.db.Query(ctx, incidentsSince, resolvedAt)
|
rows, err := q.db.Query(ctx, incidentsSince, arg.OrgID, arg.ResolvedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -672,11 +677,11 @@ func (q *Queries) OpenIncident(ctx context.Context, arg OpenIncidentParams) (Inc
|
|||||||
}
|
}
|
||||||
|
|
||||||
const openIncidents = `-- name: OpenIncidents :many
|
const openIncidents = `-- name: OpenIncidents :many
|
||||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id FROM incidents WHERE resolved_at IS NULL
|
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id FROM incidents WHERE org_id = $1 AND resolved_at IS NULL
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
|
func (q *Queries) OpenIncidents(ctx context.Context, orgID uuid.UUID) ([]Incident, error) {
|
||||||
rows, err := q.db.Query(ctx, openIncidents)
|
rows, err := q.db.Query(ctx, openIncidents, orgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.31.1
|
||||||
|
// source: latest_results.sql
|
||||||
|
|
||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const latestResults = `-- name: LatestResults :many
|
||||||
|
SELECT monitor_id, region, time, ok, latency_ms, status_code, error
|
||||||
|
FROM latest_results
|
||||||
|
WHERE org_id = $1 AND time > now() - interval '1 day'
|
||||||
|
`
|
||||||
|
|
||||||
|
type LatestResultsRow struct {
|
||||||
|
MonitorID uuid.UUID
|
||||||
|
Region string
|
||||||
|
Time time.Time
|
||||||
|
Ok bool
|
||||||
|
LatencyMs *int32
|
||||||
|
StatusCode *int32
|
||||||
|
Error *string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Newest result per monitor and region in the org, of the last day.
|
||||||
|
func (q *Queries) LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error) {
|
||||||
|
rows, err := q.db.Query(ctx, latestResults, orgID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
items := []LatestResultsRow{}
|
||||||
|
for rows.Next() {
|
||||||
|
var i LatestResultsRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.MonitorID,
|
||||||
|
&i.Region,
|
||||||
|
&i.Time,
|
||||||
|
&i.Ok,
|
||||||
|
&i.LatencyMs,
|
||||||
|
&i.StatusCode,
|
||||||
|
&i.Error,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const latestResultsForMonitors = `-- name: LatestResultsForMonitors :many
|
||||||
|
SELECT monitor_id, region, time, ok, latency_ms, status_code, error
|
||||||
|
FROM latest_results
|
||||||
|
WHERE org_id = $1 AND monitor_id = ANY ($2::uuid[]) AND time > now() - interval '1 day'
|
||||||
|
`
|
||||||
|
|
||||||
|
type LatestResultsForMonitorsParams struct {
|
||||||
|
OrgID uuid.UUID
|
||||||
|
Ids []uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
type LatestResultsForMonitorsRow struct {
|
||||||
|
MonitorID uuid.UUID
|
||||||
|
Region string
|
||||||
|
Time time.Time
|
||||||
|
Ok bool
|
||||||
|
LatencyMs *int32
|
||||||
|
StatusCode *int32
|
||||||
|
Error *string
|
||||||
|
}
|
||||||
|
|
||||||
|
// LatestResults limited to the monitors ids.
|
||||||
|
func (q *Queries) LatestResultsForMonitors(ctx context.Context, arg LatestResultsForMonitorsParams) ([]LatestResultsForMonitorsRow, error) {
|
||||||
|
rows, err := q.db.Query(ctx, latestResultsForMonitors, arg.OrgID, arg.Ids)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
items := []LatestResultsForMonitorsRow{}
|
||||||
|
for rows.Next() {
|
||||||
|
var i LatestResultsForMonitorsRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.MonitorID,
|
||||||
|
&i.Region,
|
||||||
|
&i.Time,
|
||||||
|
&i.Ok,
|
||||||
|
&i.LatencyMs,
|
||||||
|
&i.StatusCode,
|
||||||
|
&i.Error,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const upsertLatestResults = `-- name: UpsertLatestResults :exec
|
||||||
|
|
||||||
|
INSERT INTO latest_results (monitor_id, region, org_id, time, ok, latency_ms, status_code, error)
|
||||||
|
SELECT DISTINCT ON (r.monitor_id, r.region) r.monitor_id, r.region, r.org_id, r.time, r.ok, r.latency_ms, r.status_code, r.error
|
||||||
|
FROM jsonb_to_recordset($1::jsonb)
|
||||||
|
AS r(monitor_id uuid, region text, org_id uuid, time timestamptz, ok boolean, latency_ms integer, status_code integer, error text)
|
||||||
|
ORDER BY r.monitor_id, r.region, r.time DESC
|
||||||
|
ON CONFLICT (monitor_id, region) DO UPDATE
|
||||||
|
SET org_id = excluded.org_id, time = excluded.time, ok = excluded.ok, latency_ms = excluded.latency_ms,
|
||||||
|
status_code = excluded.status_code, error = excluded.error
|
||||||
|
WHERE latest_results.time <= excluded.time
|
||||||
|
`
|
||||||
|
|
||||||
|
// latest_results holds the newest check result per monitor and region
|
||||||
|
// (see migration 00055) and has row-level security.
|
||||||
|
// Keeps the newest of rows, a JSON array of results, per monitor and
|
||||||
|
// region; results arriving late do not replace newer ones.
|
||||||
|
func (q *Queries) UpsertLatestResults(ctx context.Context, rows []byte) error {
|
||||||
|
_, err := q.db.Exec(ctx, upsertLatestResults, rows)
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
const adminListOrgs = `-- name: AdminListOrgs :many
|
const adminListOrgs = `-- name: AdminListOrgs :many
|
||||||
SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason,
|
SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason,
|
||||||
o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count,
|
o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count,
|
||||||
|
o.limit_monitors_per_page,
|
||||||
(SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors,
|
(SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors,
|
||||||
(SELECT count(*) FROM status_pages p WHERE p.org_id = o.id)::integer AS status_pages,
|
(SELECT count(*) FROM status_pages p WHERE p.org_id = o.id)::integer AS status_pages,
|
||||||
coalesce(ow.id, '00000000-0000-0000-0000-000000000000'::uuid)::uuid AS owner_id,
|
coalesce(ow.id, '00000000-0000-0000-0000-000000000000'::uuid)::uuid AS owner_id,
|
||||||
@@ -61,6 +62,7 @@ type AdminListOrgsRow struct {
|
|||||||
LimitStatusPages *int32
|
LimitStatusPages *int32
|
||||||
LimitRegionsPerMonitor *int32
|
LimitRegionsPerMonitor *int32
|
||||||
LimitOwnRegionsCount *bool
|
LimitOwnRegionsCount *bool
|
||||||
|
LimitMonitorsPerPage *int32
|
||||||
Monitors int32
|
Monitors int32
|
||||||
StatusPages int32
|
StatusPages int32
|
||||||
OwnerID uuid.UUID
|
OwnerID uuid.UUID
|
||||||
@@ -102,6 +104,7 @@ func (q *Queries) AdminListOrgs(ctx context.Context, arg AdminListOrgsParams) ([
|
|||||||
&i.LimitStatusPages,
|
&i.LimitStatusPages,
|
||||||
&i.LimitRegionsPerMonitor,
|
&i.LimitRegionsPerMonitor,
|
||||||
&i.LimitOwnRegionsCount,
|
&i.LimitOwnRegionsCount,
|
||||||
|
&i.LimitMonitorsPerPage,
|
||||||
&i.Monitors,
|
&i.Monitors,
|
||||||
&i.StatusPages,
|
&i.StatusPages,
|
||||||
&i.OwnerID,
|
&i.OwnerID,
|
||||||
@@ -133,6 +136,17 @@ func (q *Queries) CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, er
|
|||||||
return count, err
|
return count, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const countStatusPageMonitors = `-- name: CountStatusPageMonitors :one
|
||||||
|
SELECT count(*) FROM status_page_monitors WHERE page_id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) CountStatusPageMonitors(ctx context.Context, pageID uuid.UUID) (int64, error) {
|
||||||
|
row := q.db.QueryRow(ctx, countStatusPageMonitors, pageID)
|
||||||
|
var count int64
|
||||||
|
err := row.Scan(&count)
|
||||||
|
return count, err
|
||||||
|
}
|
||||||
|
|
||||||
const countStatusPages = `-- name: CountStatusPages :one
|
const countStatusPages = `-- name: CountStatusPages :one
|
||||||
SELECT count(*) FROM status_pages WHERE org_id = $1
|
SELECT count(*) FROM status_pages WHERE org_id = $1
|
||||||
`
|
`
|
||||||
@@ -157,8 +171,9 @@ func (q *Queries) LockOrgUsage(ctx context.Context, orgID uuid.UUID) error {
|
|||||||
|
|
||||||
const setOrgLimits = `-- name: SetOrgLimits :one
|
const setOrgLimits = `-- name: SetOrgLimits :one
|
||||||
UPDATE orgs SET limit_monitors = $1, limit_status_pages = $2,
|
UPDATE orgs SET limit_monitors = $1, limit_status_pages = $2,
|
||||||
limit_regions_per_monitor = $3, limit_own_regions_count = $4
|
limit_regions_per_monitor = $3, limit_own_regions_count = $4,
|
||||||
WHERE id = $5
|
limit_monitors_per_page = $5
|
||||||
|
WHERE id = $6
|
||||||
RETURNING id, slug
|
RETURNING id, slug
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -167,6 +182,7 @@ type SetOrgLimitsParams struct {
|
|||||||
StatusPages *int32
|
StatusPages *int32
|
||||||
RegionsPerMonitor *int32
|
RegionsPerMonitor *int32
|
||||||
OwnRegionsCount *bool
|
OwnRegionsCount *bool
|
||||||
|
MonitorsPerPage *int32
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +197,7 @@ func (q *Queries) SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (Set
|
|||||||
arg.StatusPages,
|
arg.StatusPages,
|
||||||
arg.RegionsPerMonitor,
|
arg.RegionsPerMonitor,
|
||||||
arg.OwnRegionsCount,
|
arg.OwnRegionsCount,
|
||||||
|
arg.MonitorsPerPage,
|
||||||
arg.ID,
|
arg.ID,
|
||||||
)
|
)
|
||||||
var i SetOrgLimitsRow
|
var i SetOrgLimitsRow
|
||||||
|
|||||||
@@ -197,6 +197,17 @@ type Invitation struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LatestResult struct {
|
||||||
|
MonitorID uuid.UUID
|
||||||
|
Region string
|
||||||
|
OrgID uuid.UUID
|
||||||
|
Time time.Time
|
||||||
|
Ok bool
|
||||||
|
LatencyMs *int32
|
||||||
|
StatusCode *int32
|
||||||
|
Error *string
|
||||||
|
}
|
||||||
|
|
||||||
type LegalAcceptance struct {
|
type LegalAcceptance struct {
|
||||||
UserID uuid.UUID
|
UserID uuid.UUID
|
||||||
Kind string
|
Kind string
|
||||||
@@ -257,6 +268,7 @@ type Monitor struct {
|
|||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
Confirmations int32
|
Confirmations int32
|
||||||
GroupID *uuid.UUID
|
GroupID *uuid.UUID
|
||||||
|
Position *int32
|
||||||
}
|
}
|
||||||
|
|
||||||
type MonitorAlertGroup struct {
|
type MonitorAlertGroup struct {
|
||||||
@@ -321,6 +333,7 @@ type Org struct {
|
|||||||
LimitStatusPages *int32
|
LimitStatusPages *int32
|
||||||
LimitRegionsPerMonitor *int32
|
LimitRegionsPerMonitor *int32
|
||||||
LimitOwnRegionsCount *bool
|
LimitOwnRegionsCount *bool
|
||||||
|
LimitMonitorsPerPage *int32
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlatformIdentity struct {
|
type PlatformIdentity struct {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (q *Queries) AddMonitorRegion(ctx context.Context, arg AddMonitorRegionPara
|
|||||||
}
|
}
|
||||||
|
|
||||||
const allMonitorRegions = `-- name: AllMonitorRegions :many
|
const allMonitorRegions = `-- name: AllMonitorRegions :many
|
||||||
SELECT monitor_id, region_id FROM monitor_regions
|
SELECT monitor_id, region_id FROM monitor_regions WHERE org_id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
type AllMonitorRegionsRow struct {
|
type AllMonitorRegionsRow struct {
|
||||||
@@ -35,8 +35,8 @@ type AllMonitorRegionsRow struct {
|
|||||||
RegionID uuid.UUID
|
RegionID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow, error) {
|
func (q *Queries) AllMonitorRegions(ctx context.Context, orgID uuid.UUID) ([]AllMonitorRegionsRow, error) {
|
||||||
rows, err := q.db.Query(ctx, allMonitorRegions)
|
rows, err := q.db.Query(ctx, allMonitorRegions, orgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ func (q *Queries) AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow
|
|||||||
const createMonitor = `-- name: CreateMonitor :one
|
const createMonitor = `-- name: CreateMonitor :one
|
||||||
INSERT INTO monitors (org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, confirmations, group_id)
|
INSERT INTO monitors (org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, confirmations, group_id)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id
|
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateMonitorParams struct {
|
type CreateMonitorParams struct {
|
||||||
@@ -102,6 +102,7 @@ func (q *Queries) CreateMonitor(ctx context.Context, arg CreateMonitorParams) (M
|
|||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
&i.Confirmations,
|
&i.Confirmations,
|
||||||
&i.GroupID,
|
&i.GroupID,
|
||||||
|
&i.Position,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@@ -128,7 +129,7 @@ func (q *Queries) DeleteMonitorRegions(ctx context.Context, monitorID uuid.UUID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getMonitor = `-- name: GetMonitor :one
|
const getMonitor = `-- name: GetMonitor :one
|
||||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id FROM monitors WHERE id = $1
|
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position FROM monitors WHERE id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetMonitor(ctx context.Context, id uuid.UUID) (Monitor, error) {
|
func (q *Queries) GetMonitor(ctx context.Context, id uuid.UUID) (Monitor, error) {
|
||||||
@@ -148,6 +149,7 @@ func (q *Queries) GetMonitor(ctx context.Context, id uuid.UUID) (Monitor, error)
|
|||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
&i.Confirmations,
|
&i.Confirmations,
|
||||||
&i.GroupID,
|
&i.GroupID,
|
||||||
|
&i.Position,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@@ -190,11 +192,12 @@ func (q *Queries) ListEnabledMonitorsForSchedule(ctx context.Context) ([]ListEna
|
|||||||
}
|
}
|
||||||
|
|
||||||
const listMonitors = `-- name: ListMonitors :many
|
const listMonitors = `-- name: ListMonitors :many
|
||||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id FROM monitors ORDER BY name
|
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position FROM monitors WHERE org_id = $1 ORDER BY name
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) ListMonitors(ctx context.Context) ([]Monitor, error) {
|
// The org filter, though row security implies it, lets the index be used.
|
||||||
rows, err := q.db.Query(ctx, listMonitors)
|
func (q *Queries) ListMonitors(ctx context.Context, orgID uuid.UUID) ([]Monitor, error) {
|
||||||
|
rows, err := q.db.Query(ctx, listMonitors, orgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -216,6 +219,7 @@ func (q *Queries) ListMonitors(ctx context.Context) ([]Monitor, error) {
|
|||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
&i.Confirmations,
|
&i.Confirmations,
|
||||||
&i.GroupID,
|
&i.GroupID,
|
||||||
|
&i.Position,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -228,7 +232,7 @@ func (q *Queries) ListMonitors(ctx context.Context) ([]Monitor, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const listMonitorsPage = `-- name: ListMonitorsPage :many
|
const listMonitorsPage = `-- name: ListMonitorsPage :many
|
||||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id FROM monitors
|
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position FROM monitors
|
||||||
WHERE true
|
WHERE true
|
||||||
AND ($1::text IS NULL OR (name, id) > ($1, $2::uuid))
|
AND ($1::text IS NULL OR (name, id) > ($1, $2::uuid))
|
||||||
AND ($3::text IS NULL OR (name, id) < ($3, $4::uuid))
|
AND ($3::text IS NULL OR (name, id) < ($3, $4::uuid))
|
||||||
@@ -277,6 +281,7 @@ func (q *Queries) ListMonitorsPage(ctx context.Context, arg ListMonitorsPagePara
|
|||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
&i.Confirmations,
|
&i.Confirmations,
|
||||||
&i.GroupID,
|
&i.GroupID,
|
||||||
|
&i.Position,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -313,7 +318,7 @@ func (q *Queries) MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uu
|
|||||||
}
|
}
|
||||||
|
|
||||||
const monitorsForJobs = `-- name: MonitorsForJobs :many
|
const monitorsForJobs = `-- name: MonitorsForJobs :many
|
||||||
SELECT m.id, m.org_id, m.name, m.type, m.target, m.interval_seconds, m.timeout_ms, m.config, m.enabled, m.created_at, m.updated_at, m.confirmations, m.group_id FROM monitors m
|
SELECT m.id, m.org_id, m.name, m.type, m.target, m.interval_seconds, m.timeout_ms, m.config, m.enabled, m.created_at, m.updated_at, m.confirmations, m.group_id, m.position FROM monitors m
|
||||||
JOIN monitor_regions r ON r.monitor_id = m.id AND r.region_id = $1
|
JOIN monitor_regions r ON r.monitor_id = m.id AND r.region_id = $1
|
||||||
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
|
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
|
||||||
WHERE m.id = ANY ($2::uuid[]) AND m.enabled
|
WHERE m.id = ANY ($2::uuid[]) AND m.enabled
|
||||||
@@ -352,6 +357,7 @@ func (q *Queries) MonitorsForJobs(ctx context.Context, arg MonitorsForJobsParams
|
|||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
&i.Confirmations,
|
&i.Confirmations,
|
||||||
&i.GroupID,
|
&i.GroupID,
|
||||||
|
&i.Position,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -419,11 +425,28 @@ func (q *Queries) MonitorsForResults(ctx context.Context, arg MonitorsForResults
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setMonitorPosition = `-- name: SetMonitorPosition :execrows
|
||||||
|
UPDATE monitors SET position = $1 WHERE id = $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type SetMonitorPositionParams struct {
|
||||||
|
Position *int32
|
||||||
|
ID uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) SetMonitorPosition(ctx context.Context, arg SetMonitorPositionParams) (int64, error) {
|
||||||
|
result, err := q.db.Exec(ctx, setMonitorPosition, arg.Position, arg.ID)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return result.RowsAffected(), nil
|
||||||
|
}
|
||||||
|
|
||||||
const updateMonitor = `-- name: UpdateMonitor :one
|
const updateMonitor = `-- name: UpdateMonitor :one
|
||||||
UPDATE monitors SET name = $2, type = $3, target = $4, interval_seconds = $5,
|
UPDATE monitors SET name = $2, type = $3, target = $4, interval_seconds = $5,
|
||||||
timeout_ms = $6, config = $7, enabled = $8, confirmations = $9, group_id = $10, updated_at = now()
|
timeout_ms = $6, config = $7, enabled = $8, confirmations = $9, group_id = $10, updated_at = now()
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id
|
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, position
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdateMonitorParams struct {
|
type UpdateMonitorParams struct {
|
||||||
@@ -467,6 +490,7 @@ func (q *Queries) UpdateMonitor(ctx context.Context, arg UpdateMonitorParams) (M
|
|||||||
&i.UpdatedAt,
|
&i.UpdatedAt,
|
||||||
&i.Confirmations,
|
&i.Confirmations,
|
||||||
&i.GroupID,
|
&i.GroupID,
|
||||||
|
&i.Position,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
const createOrg = `-- name: CreateOrg :one
|
const createOrg = `-- name: CreateOrg :one
|
||||||
INSERT INTO orgs (id, slug, name) VALUES ($1, $2, $3)
|
INSERT INTO orgs (id, slug, name) VALUES ($1, $2, $3)
|
||||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count
|
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count, limit_monitors_per_page
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateOrgParams struct {
|
type CreateOrgParams struct {
|
||||||
@@ -41,6 +41,7 @@ func (q *Queries) CreateOrg(ctx context.Context, arg CreateOrgParams) (Org, erro
|
|||||||
&i.LimitStatusPages,
|
&i.LimitStatusPages,
|
||||||
&i.LimitRegionsPerMonitor,
|
&i.LimitRegionsPerMonitor,
|
||||||
&i.LimitOwnRegionsCount,
|
&i.LimitOwnRegionsCount,
|
||||||
|
&i.LimitMonitorsPerPage,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@@ -58,7 +59,7 @@ func (q *Queries) DeleteOrg(ctx context.Context, id uuid.UUID) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getOrg = `-- name: GetOrg :one
|
const getOrg = `-- name: GetOrg :one
|
||||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count FROM orgs WHERE id = $1
|
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count, limit_monitors_per_page FROM orgs WHERE id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
|
func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
|
||||||
@@ -80,12 +81,13 @@ func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) {
|
|||||||
&i.LimitStatusPages,
|
&i.LimitStatusPages,
|
||||||
&i.LimitRegionsPerMonitor,
|
&i.LimitRegionsPerMonitor,
|
||||||
&i.LimitOwnRegionsCount,
|
&i.LimitOwnRegionsCount,
|
||||||
|
&i.LimitMonitorsPerPage,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const getOrgBySlug = `-- name: GetOrgBySlug :one
|
const getOrgBySlug = `-- name: GetOrgBySlug :one
|
||||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count FROM orgs WHERE slug = $1
|
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count, limit_monitors_per_page FROM orgs WHERE slug = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
||||||
@@ -107,12 +109,13 @@ func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) {
|
|||||||
&i.LimitStatusPages,
|
&i.LimitStatusPages,
|
||||||
&i.LimitRegionsPerMonitor,
|
&i.LimitRegionsPerMonitor,
|
||||||
&i.LimitOwnRegionsCount,
|
&i.LimitOwnRegionsCount,
|
||||||
|
&i.LimitMonitorsPerPage,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const listOrgs = `-- name: ListOrgs :many
|
const listOrgs = `-- name: ListOrgs :many
|
||||||
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count FROM orgs ORDER BY name
|
SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count, limit_monitors_per_page FROM orgs ORDER BY name
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
||||||
@@ -140,6 +143,7 @@ func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) {
|
|||||||
&i.LimitStatusPages,
|
&i.LimitStatusPages,
|
||||||
&i.LimitRegionsPerMonitor,
|
&i.LimitRegionsPerMonitor,
|
||||||
&i.LimitOwnRegionsCount,
|
&i.LimitOwnRegionsCount,
|
||||||
|
&i.LimitMonitorsPerPage,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -168,7 +172,7 @@ func (q *Queries) SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabl
|
|||||||
const updateOrgPolicy = `-- name: UpdateOrgPolicy :one
|
const updateOrgPolicy = `-- name: UpdateOrgPolicy :one
|
||||||
UPDATE orgs SET require_totp = $2, require_sso = $3, api_token_max_days = $4, updated_at = now()
|
UPDATE orgs SET require_totp = $2, require_sso = $3, api_token_max_days = $4, updated_at = now()
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count
|
RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count, limit_monitors_per_page
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdateOrgPolicyParams struct {
|
type UpdateOrgPolicyParams struct {
|
||||||
@@ -202,6 +206,7 @@ func (q *Queries) UpdateOrgPolicy(ctx context.Context, arg UpdateOrgPolicyParams
|
|||||||
&i.LimitStatusPages,
|
&i.LimitStatusPages,
|
||||||
&i.LimitRegionsPerMonitor,
|
&i.LimitRegionsPerMonitor,
|
||||||
&i.LimitOwnRegionsCount,
|
&i.LimitOwnRegionsCount,
|
||||||
|
&i.LimitMonitorsPerPage,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ type Querier interface {
|
|||||||
// System scope: the receiver a webhook token belongs to.
|
// System scope: the receiver a webhook token belongs to.
|
||||||
AlertmanagerReceiverByHash(ctx context.Context, tokenHash []byte) (AlertmanagerReceiverByHashRow, error)
|
AlertmanagerReceiverByHash(ctx context.Context, tokenHash []byte) (AlertmanagerReceiverByHashRow, error)
|
||||||
AllMonitorAlertGroups(ctx context.Context) ([]MonitorAlertGroup, error)
|
AllMonitorAlertGroups(ctx context.Context) ([]MonitorAlertGroup, error)
|
||||||
AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow, error)
|
AllMonitorRegions(ctx context.Context, orgID uuid.UUID) ([]AllMonitorRegionsRow, error)
|
||||||
AnyUserExists(ctx context.Context) (bool, error)
|
AnyUserExists(ctx context.Context) (bool, error)
|
||||||
// How much one instance checked for the organization in the last hour.
|
// How much one instance checked for the organization in the last hour.
|
||||||
CheckerStats(ctx context.Context, arg CheckerStatsParams) (CheckerStatsRow, error)
|
CheckerStats(ctx context.Context, arg CheckerStatsParams) (CheckerStatsRow, error)
|
||||||
@@ -56,6 +56,7 @@ type Querier interface {
|
|||||||
CountOwnedOrgs(ctx context.Context, userID uuid.UUID) (int64, error)
|
CountOwnedOrgs(ctx context.Context, userID uuid.UUID) (int64, error)
|
||||||
CountOwners(ctx context.Context, orgID uuid.UUID) (int64, error)
|
CountOwners(ctx context.Context, orgID uuid.UUID) (int64, error)
|
||||||
CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error)
|
CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error)
|
||||||
|
CountStatusPageMonitors(ctx context.Context, pageID uuid.UUID) (int64, error)
|
||||||
CountStatusPages(ctx context.Context, orgID uuid.UUID) (int64, error)
|
CountStatusPages(ctx context.Context, orgID uuid.UUID) (int64, error)
|
||||||
CountSupportTicketsSince(ctx context.Context, arg CountSupportTicketsSinceParams) (int64, error)
|
CountSupportTicketsSince(ctx context.Context, arg CountSupportTicketsSinceParams) (int64, error)
|
||||||
CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error)
|
CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error)
|
||||||
@@ -123,6 +124,12 @@ type Querier interface {
|
|||||||
// for two days, after which only the verify button tries again. A verified
|
// for two days, after which only the verify button tries again. A verified
|
||||||
// one is checked daily, hourly once its record went missing.
|
// one is checked daily, hourly once its record went missing.
|
||||||
DomainsToCheck(ctx context.Context, arg DomainsToCheckParams) ([]DomainsToCheckRow, error)
|
DomainsToCheck(ctx context.Context, arg DomainsToCheckParams) ([]DomainsToCheckRow, error)
|
||||||
|
// The day the organization's monitors first reported, if any did.
|
||||||
|
EarliestDataDaily(ctx context.Context, orgID uuid.UUID) (time.Time, error)
|
||||||
|
// When the organization's monitors first reported since $2, exactly: the
|
||||||
|
// first result of each monitor is found through its index, so the cost
|
||||||
|
// does not grow with the days of results.
|
||||||
|
EarliestDataRecent(ctx context.Context, arg EarliestDataRecentParams) (time.Time, error)
|
||||||
EmailKeyTaken(ctx context.Context, emailKey *string) (bool, error)
|
EmailKeyTaken(ctx context.Context, emailKey *string) (bool, error)
|
||||||
EnableTOTP(ctx context.Context, arg EnableTOTPParams) error
|
EnableTOTP(ctx context.Context, arg EnableTOTPParams) error
|
||||||
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
|
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
|
||||||
@@ -138,9 +145,9 @@ type Querier interface {
|
|||||||
// FiringAlerts newest first, a page from a keyset cursor (see paging.go)
|
// FiringAlerts newest first, a page from a keyset cursor (see paging.go)
|
||||||
// whose string key is the fingerprint.
|
// whose string key is the fingerprint.
|
||||||
FiringAlertsPage(ctx context.Context, arg FiringAlertsPageParams) ([]FiringAlertsPageRow, error)
|
FiringAlertsPage(ctx context.Context, arg FiringAlertsPageParams) ([]FiringAlertsPageRow, error)
|
||||||
// When each monitor and region first reported, to the day.
|
// When each region of a monitor first reported, to the day.
|
||||||
FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstDataDailyRow, error)
|
FirstDataDaily(ctx context.Context, arg FirstDataDailyParams) ([]FirstDataDailyRow, error)
|
||||||
// When each monitor and region first reported since $2, exactly. Used for
|
// When each region of a monitor first reported since $3, exactly. Used for
|
||||||
// data younger than the daily aggregate's resolution.
|
// data younger than the daily aggregate's resolution.
|
||||||
FirstDataRecent(ctx context.Context, arg FirstDataRecentParams) ([]FirstDataRecentRow, error)
|
FirstDataRecent(ctx context.Context, arg FirstDataRecentParams) ([]FirstDataRecentRow, error)
|
||||||
// Keeps organization and platform entries readable as "deleted user" but
|
// Keeps organization and platform entries readable as "deleted user" but
|
||||||
@@ -183,8 +190,8 @@ type Querier interface {
|
|||||||
// Per monitor and hour since $2, across all regions.
|
// Per monitor and hour since $2, across all regions.
|
||||||
HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error)
|
HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error)
|
||||||
IncidentsForMonitors(ctx context.Context, arg IncidentsForMonitorsParams) ([]Incident, error)
|
IncidentsForMonitors(ctx context.Context, arg IncidentsForMonitorsParams) ([]Incident, error)
|
||||||
// Incidents overlapping the time since $1, for SLA calculation.
|
// Incidents overlapping the time since $2, for SLA calculation.
|
||||||
IncidentsSince(ctx context.Context, resolvedAt *time.Time) ([]IncidentsSinceRow, error)
|
IncidentsSince(ctx context.Context, arg IncidentsSinceParams) ([]IncidentsSinceRow, error)
|
||||||
InsertAuditEvent(ctx context.Context, arg InsertAuditEventParams) error
|
InsertAuditEvent(ctx context.Context, arg InsertAuditEventParams) error
|
||||||
// check_results and its aggregates have no row-level security (see
|
// check_results and its aggregates have no row-level security (see
|
||||||
// migration 00013). Every query here must filter by org_id.
|
// migration 00013). Every query here must filter by org_id.
|
||||||
@@ -195,9 +202,11 @@ type Querier interface {
|
|||||||
IsMember(ctx context.Context, arg IsMemberParams) (bool, error)
|
IsMember(ctx context.Context, arg IsMemberParams) (bool, error)
|
||||||
LastFailureEvidence(ctx context.Context, arg LastFailureEvidenceParams) (LastFailureEvidenceRow, error)
|
LastFailureEvidence(ctx context.Context, arg LastFailureEvidenceParams) (LastFailureEvidenceRow, error)
|
||||||
LatestResultForMonitor(ctx context.Context, arg LatestResultForMonitorParams) (LatestResultForMonitorRow, error)
|
LatestResultForMonitor(ctx context.Context, arg LatestResultForMonitorParams) (LatestResultForMonitorRow, error)
|
||||||
// Newest result per monitor and region in the org.
|
// Newest result per monitor and region in the org, of the last day.
|
||||||
LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error)
|
LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error)
|
||||||
LatestResultsForMonitor(ctx context.Context, arg LatestResultsForMonitorParams) ([]LatestResultsForMonitorRow, error)
|
LatestResultsForMonitor(ctx context.Context, arg LatestResultsForMonitorParams) ([]LatestResultsForMonitorRow, error)
|
||||||
|
// LatestResults limited to the monitors ids.
|
||||||
|
LatestResultsForMonitors(ctx context.Context, arg LatestResultsForMonitorsParams) ([]LatestResultsForMonitorsRow, error)
|
||||||
LegalAcceptances(ctx context.Context, userID uuid.UUID) ([]LegalAcceptancesRow, error)
|
LegalAcceptances(ctx context.Context, userID uuid.UUID) ([]LegalAcceptancesRow, error)
|
||||||
// The organization's documents and the platform's, organization first.
|
// The organization's documents and the platform's, organization first.
|
||||||
LegalDocuments(ctx context.Context, orgID *uuid.UUID) ([]LegalDocument, error)
|
LegalDocuments(ctx context.Context, orgID *uuid.UUID) ([]LegalDocument, error)
|
||||||
@@ -228,7 +237,8 @@ type Querier interface {
|
|||||||
// Latest start first, a page from a keyset cursor (see paging.go).
|
// Latest start first, a page from a keyset cursor (see paging.go).
|
||||||
ListMaintenancePage(ctx context.Context, arg ListMaintenancePageParams) ([]MaintenanceWindow, error)
|
ListMaintenancePage(ctx context.Context, arg ListMaintenancePageParams) ([]MaintenanceWindow, error)
|
||||||
ListMaintenanceTargets(ctx context.Context) ([]MaintenanceTarget, error)
|
ListMaintenanceTargets(ctx context.Context) ([]MaintenanceTarget, error)
|
||||||
ListMonitors(ctx context.Context) ([]Monitor, error)
|
// The org filter, though row security implies it, lets the index be used.
|
||||||
|
ListMonitors(ctx context.Context, orgID uuid.UUID) ([]Monitor, error)
|
||||||
// By name, a page from a keyset cursor (see paging.go).
|
// By name, a page from a keyset cursor (see paging.go).
|
||||||
ListMonitorsPage(ctx context.Context, arg ListMonitorsPageParams) ([]Monitor, error)
|
ListMonitorsPage(ctx context.Context, arg ListMonitorsPageParams) ([]Monitor, error)
|
||||||
ListOrgMembers(ctx context.Context, orgID uuid.UUID) ([]ListOrgMembersRow, error)
|
ListOrgMembers(ctx context.Context, orgID uuid.UUID) ([]ListOrgMembersRow, error)
|
||||||
@@ -290,7 +300,7 @@ type Querier interface {
|
|||||||
// System scope.
|
// System scope.
|
||||||
NotificationDetails(ctx context.Context, ids []uuid.UUID) ([]NotificationDetailsRow, error)
|
NotificationDetails(ctx context.Context, ids []uuid.UUID) ([]NotificationDetailsRow, error)
|
||||||
OpenIncident(ctx context.Context, arg OpenIncidentParams) (Incident, error)
|
OpenIncident(ctx context.Context, arg OpenIncidentParams) (Incident, error)
|
||||||
OpenIncidents(ctx context.Context) ([]Incident, error)
|
OpenIncidents(ctx context.Context, orgID uuid.UUID) ([]Incident, error)
|
||||||
OrgAssignmentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgAssignmentsExportRow, error)
|
OrgAssignmentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgAssignmentsExportRow, error)
|
||||||
OrgAuditExport(ctx context.Context, orgID uuid.UUID) ([]OrgAuditExportRow, error)
|
OrgAuditExport(ctx context.Context, orgID uuid.UUID) ([]OrgAuditExportRow, error)
|
||||||
OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDailyStatsRow, error)
|
OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDailyStatsRow, error)
|
||||||
@@ -357,6 +367,7 @@ type Querier interface {
|
|||||||
ServablePages(ctx context.Context, agentOrg *uuid.UUID) ([]ServablePagesRow, error)
|
ServablePages(ctx context.Context, agentOrg *uuid.UUID) ([]ServablePagesRow, error)
|
||||||
SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error)
|
SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error)
|
||||||
SetIncidentTitle(ctx context.Context, arg SetIncidentTitleParams) (int64, error)
|
SetIncidentTitle(ctx context.Context, arg SetIncidentTitleParams) (int64, error)
|
||||||
|
SetMonitorPosition(ctx context.Context, arg SetMonitorPositionParams) (int64, error)
|
||||||
SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabledCheckTypesParams) error
|
SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabledCheckTypesParams) error
|
||||||
SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (SetOrgLimitsRow, error)
|
SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (SetOrgLimitsRow, error)
|
||||||
SetOwner(ctx context.Context, arg SetOwnerParams) (int64, error)
|
SetOwner(ctx context.Context, arg SetOwnerParams) (int64, error)
|
||||||
@@ -415,6 +426,11 @@ type Querier interface {
|
|||||||
UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error)
|
UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error)
|
||||||
UpdateStatusPageGroup(ctx context.Context, arg UpdateStatusPageGroupParams) (StatusPageGroup, error)
|
UpdateStatusPageGroup(ctx context.Context, arg UpdateStatusPageGroupParams) (StatusPageGroup, error)
|
||||||
UpsertAlertmanagerAlert(ctx context.Context, arg UpsertAlertmanagerAlertParams) error
|
UpsertAlertmanagerAlert(ctx context.Context, arg UpsertAlertmanagerAlertParams) error
|
||||||
|
// latest_results holds the newest check result per monitor and region
|
||||||
|
// (see migration 00055) and has row-level security.
|
||||||
|
// Keeps the newest of rows, a JSON array of results, per monitor and
|
||||||
|
// region; results arriving late do not replace newer ones.
|
||||||
|
UpsertLatestResults(ctx context.Context, rows []byte) error
|
||||||
// A new version starts when the document is created or when the edit asks
|
// A new version starts when the document is created or when the edit asks
|
||||||
// everyone to accept it again.
|
// everyone to accept it again.
|
||||||
UpsertLegalDocument(ctx context.Context, arg UpsertLegalDocumentParams) error
|
UpsertLegalDocument(ctx context.Context, arg UpsertLegalDocumentParams) error
|
||||||
|
|||||||
@@ -5,13 +5,6 @@
|
|||||||
INSERT INTO check_results (time, org_id, monitor_id, region, checker_id, ok, latency_ms, status_code, error)
|
INSERT INTO check_results (time, org_id, monitor_id, region, checker_id, ok, latency_ms, status_code, error)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
||||||
|
|
||||||
-- name: LatestResults :many
|
|
||||||
-- Newest result per monitor and region in the org.
|
|
||||||
SELECT DISTINCT ON (monitor_id, region) monitor_id, region, time, ok, latency_ms, status_code, error
|
|
||||||
FROM check_results
|
|
||||||
WHERE org_id = $1 AND time > now() - interval '1 day'
|
|
||||||
ORDER BY monitor_id, region, time DESC;
|
|
||||||
|
|
||||||
-- name: ListResults :many
|
-- name: ListResults :many
|
||||||
-- A monitor's results newest first, a page from a keyset cursor (see
|
-- A monitor's results newest first, a page from a keyset cursor (see
|
||||||
-- paging.go) whose string key is region and checker.
|
-- paging.go) whose string key is region and checker.
|
||||||
@@ -49,6 +42,7 @@ SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, s
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1h
|
FROM check_results_1h
|
||||||
WHERE org_id = $1 AND bucket >= $2
|
WHERE org_id = $1 AND bucket >= $2
|
||||||
|
AND (sqlc.narg(ids)::uuid[] IS NULL OR monitor_id = ANY (sqlc.narg(ids)::uuid[]))
|
||||||
GROUP BY monitor_id, bucket
|
GROUP BY monitor_id, bucket
|
||||||
ORDER BY monitor_id, bucket;
|
ORDER BY monitor_id, bucket;
|
||||||
|
|
||||||
@@ -73,7 +67,7 @@ SELECT monitor_id, time_bucket(sqlc.arg(width)::text::interval, time)::timestamp
|
|||||||
coalesce(avg(latency_ms), 0)::real AS avg_latency_ms
|
coalesce(avg(latency_ms), 0)::real AS avg_latency_ms
|
||||||
FROM check_results
|
FROM check_results
|
||||||
WHERE org_id = $1 AND time >= sqlc.arg(since)
|
WHERE org_id = $1 AND time >= sqlc.arg(since)
|
||||||
AND (sqlc.narg(monitor_id)::uuid IS NULL OR monitor_id = sqlc.narg(monitor_id))
|
AND monitor_id = ANY (sqlc.arg(ids)::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2;
|
ORDER BY 1, 2;
|
||||||
|
|
||||||
@@ -84,7 +78,7 @@ SELECT monitor_id, time_bucket(sqlc.arg(width)::text::interval, bucket)::timesta
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1h
|
FROM check_results_1h
|
||||||
WHERE org_id = $1 AND bucket >= sqlc.arg(since)
|
WHERE org_id = $1 AND bucket >= sqlc.arg(since)
|
||||||
AND (sqlc.narg(monitor_id)::uuid IS NULL OR monitor_id = sqlc.narg(monitor_id))
|
AND monitor_id = ANY (sqlc.arg(ids)::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2;
|
ORDER BY 1, 2;
|
||||||
|
|
||||||
@@ -95,7 +89,7 @@ SELECT monitor_id, time_bucket(sqlc.arg(width)::text::interval, bucket)::timesta
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1d
|
FROM check_results_1d
|
||||||
WHERE org_id = $1 AND bucket >= sqlc.arg(since)
|
WHERE org_id = $1 AND bucket >= sqlc.arg(since)
|
||||||
AND (sqlc.narg(monitor_id)::uuid IS NULL OR monitor_id = sqlc.narg(monitor_id))
|
AND monitor_id = ANY (sqlc.arg(ids)::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2;
|
ORDER BY 1, 2;
|
||||||
|
|
||||||
@@ -125,18 +119,35 @@ GROUP BY 1, 2
|
|||||||
ORDER BY 1, 2;
|
ORDER BY 1, 2;
|
||||||
|
|
||||||
-- name: FirstDataDaily :many
|
-- name: FirstDataDaily :many
|
||||||
-- When each monitor and region first reported, to the day.
|
-- When each region of a monitor first reported, to the day.
|
||||||
SELECT monitor_id, region, min(bucket)::timestamptz AS first
|
SELECT monitor_id, region, min(bucket)::timestamptz AS first
|
||||||
FROM check_results_1d
|
FROM check_results_1d
|
||||||
WHERE org_id = $1
|
WHERE org_id = $1 AND monitor_id = $2
|
||||||
GROUP BY 1, 2;
|
GROUP BY 1, 2;
|
||||||
|
|
||||||
|
-- name: EarliestDataDaily :one
|
||||||
|
-- The day the organization's monitors first reported, if any did.
|
||||||
|
SELECT bucket::timestamptz AS first FROM check_results_1d WHERE org_id = $1 ORDER BY bucket LIMIT 1;
|
||||||
|
|
||||||
|
-- name: EarliestDataRecent :one
|
||||||
|
-- When the organization's monitors first reported since $2, exactly: the
|
||||||
|
-- first result of each monitor is found through its index, so the cost
|
||||||
|
-- does not grow with the days of results.
|
||||||
|
SELECT f.time FROM monitors m
|
||||||
|
CROSS JOIN LATERAL (
|
||||||
|
SELECT c.time FROM check_results c
|
||||||
|
WHERE c.org_id = $1 AND c.monitor_id = m.id AND c.time >= $2
|
||||||
|
ORDER BY c.time LIMIT 1
|
||||||
|
) f
|
||||||
|
WHERE m.org_id = $1
|
||||||
|
ORDER BY f.time LIMIT 1;
|
||||||
|
|
||||||
-- name: FirstDataRecent :many
|
-- name: FirstDataRecent :many
|
||||||
-- When each monitor and region first reported since $2, exactly. Used for
|
-- When each region of a monitor first reported since $3, exactly. Used for
|
||||||
-- data younger than the daily aggregate's resolution.
|
-- data younger than the daily aggregate's resolution.
|
||||||
SELECT monitor_id, region, min(time)::timestamptz AS first
|
SELECT monitor_id, region, min(time)::timestamptz AS first
|
||||||
FROM check_results
|
FROM check_results
|
||||||
WHERE org_id = $1 AND time >= $2
|
WHERE org_id = $1 AND monitor_id = $2 AND time >= $3
|
||||||
GROUP BY 1, 2;
|
GROUP BY 1, 2;
|
||||||
|
|
||||||
-- name: ResultsByChecker :many
|
-- name: ResultsByChecker :many
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ SELECT * FROM notification_channels ORDER BY name;
|
|||||||
DELETE FROM notification_channels WHERE id = $1;
|
DELETE FROM notification_channels WHERE id = $1;
|
||||||
|
|
||||||
-- name: OpenIncidents :many
|
-- name: OpenIncidents :many
|
||||||
SELECT * FROM incidents WHERE resolved_at IS NULL;
|
SELECT * FROM incidents WHERE org_id = $1 AND resolved_at IS NULL;
|
||||||
|
|
||||||
-- name: IncidentsForMonitors :many
|
-- name: IncidentsForMonitors :many
|
||||||
SELECT * FROM incidents
|
SELECT * FROM incidents
|
||||||
@@ -93,9 +93,9 @@ ORDER BY started_at DESC
|
|||||||
LIMIT 50;
|
LIMIT 50;
|
||||||
|
|
||||||
-- name: IncidentsSince :many
|
-- name: IncidentsSince :many
|
||||||
-- Incidents overlapping the time since $1, for SLA calculation.
|
-- Incidents overlapping the time since $2, for SLA calculation.
|
||||||
SELECT monitor_id, started_at, resolved_at FROM incidents
|
SELECT monitor_id, started_at, resolved_at FROM incidents
|
||||||
WHERE resolved_at IS NULL OR resolved_at > $1;
|
WHERE org_id = $1 AND (resolved_at IS NULL OR resolved_at > $2);
|
||||||
|
|
||||||
-- name: GetIncident :one
|
-- name: GetIncident :one
|
||||||
SELECT i.*, m.name AS monitor_name, m.group_id AS monitor_group_id
|
SELECT i.*, m.name AS monitor_name, m.group_id AS monitor_group_id
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
-- latest_results holds the newest check result per monitor and region
|
||||||
|
-- (see migration 00055) and has row-level security.
|
||||||
|
|
||||||
|
-- name: UpsertLatestResults :exec
|
||||||
|
-- Keeps the newest of rows, a JSON array of results, per monitor and
|
||||||
|
-- region; results arriving late do not replace newer ones.
|
||||||
|
INSERT INTO latest_results (monitor_id, region, org_id, time, ok, latency_ms, status_code, error)
|
||||||
|
SELECT DISTINCT ON (r.monitor_id, r.region) r.monitor_id, r.region, r.org_id, r.time, r.ok, r.latency_ms, r.status_code, r.error
|
||||||
|
FROM jsonb_to_recordset(sqlc.arg(rows)::jsonb)
|
||||||
|
AS r(monitor_id uuid, region text, org_id uuid, time timestamptz, ok boolean, latency_ms integer, status_code integer, error text)
|
||||||
|
ORDER BY r.monitor_id, r.region, r.time DESC
|
||||||
|
ON CONFLICT (monitor_id, region) DO UPDATE
|
||||||
|
SET org_id = excluded.org_id, time = excluded.time, ok = excluded.ok, latency_ms = excluded.latency_ms,
|
||||||
|
status_code = excluded.status_code, error = excluded.error
|
||||||
|
WHERE latest_results.time <= excluded.time;
|
||||||
|
|
||||||
|
-- name: LatestResults :many
|
||||||
|
-- Newest result per monitor and region in the org, of the last day.
|
||||||
|
SELECT monitor_id, region, time, ok, latency_ms, status_code, error
|
||||||
|
FROM latest_results
|
||||||
|
WHERE org_id = $1 AND time > now() - interval '1 day';
|
||||||
|
|
||||||
|
-- name: LatestResultsForMonitors :many
|
||||||
|
-- LatestResults limited to the monitors ids.
|
||||||
|
SELECT monitor_id, region, time, ok, latency_ms, status_code, error
|
||||||
|
FROM latest_results
|
||||||
|
WHERE org_id = $1 AND monitor_id = ANY (sqlc.arg(ids)::uuid[]) AND time > now() - interval '1 day';
|
||||||
@@ -9,9 +9,13 @@ SELECT count(*) FROM monitors WHERE org_id = $1;
|
|||||||
-- name: CountStatusPages :one
|
-- name: CountStatusPages :one
|
||||||
SELECT count(*) FROM status_pages WHERE org_id = $1;
|
SELECT count(*) FROM status_pages WHERE org_id = $1;
|
||||||
|
|
||||||
|
-- name: CountStatusPageMonitors :one
|
||||||
|
SELECT count(*) FROM status_page_monitors WHERE page_id = $1;
|
||||||
|
|
||||||
-- name: SetOrgLimits :one
|
-- name: SetOrgLimits :one
|
||||||
UPDATE orgs SET limit_monitors = sqlc.narg(monitors), limit_status_pages = sqlc.narg(status_pages),
|
UPDATE orgs SET limit_monitors = sqlc.narg(monitors), limit_status_pages = sqlc.narg(status_pages),
|
||||||
limit_regions_per_monitor = sqlc.narg(regions_per_monitor), limit_own_regions_count = sqlc.narg(own_regions_count)
|
limit_regions_per_monitor = sqlc.narg(regions_per_monitor), limit_own_regions_count = sqlc.narg(own_regions_count),
|
||||||
|
limit_monitors_per_page = sqlc.narg(monitors_per_page)
|
||||||
WHERE id = sqlc.arg(id)
|
WHERE id = sqlc.arg(id)
|
||||||
RETURNING id, slug;
|
RETURNING id, slug;
|
||||||
|
|
||||||
@@ -25,6 +29,7 @@ RETURNING id, email;
|
|||||||
-- keyset cursor.
|
-- keyset cursor.
|
||||||
SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason,
|
SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason,
|
||||||
o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count,
|
o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count,
|
||||||
|
o.limit_monitors_per_page,
|
||||||
(SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors,
|
(SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors,
|
||||||
(SELECT count(*) FROM status_pages p WHERE p.org_id = o.id)::integer AS status_pages,
|
(SELECT count(*) FROM status_pages p WHERE p.org_id = o.id)::integer AS status_pages,
|
||||||
coalesce(ow.id, '00000000-0000-0000-0000-000000000000'::uuid)::uuid AS owner_id,
|
coalesce(ow.id, '00000000-0000-0000-0000-000000000000'::uuid)::uuid AS owner_id,
|
||||||
|
|||||||
@@ -16,13 +16,14 @@ DELETE FROM monitors WHERE id = $1;
|
|||||||
SELECT * FROM monitors WHERE id = $1;
|
SELECT * FROM monitors WHERE id = $1;
|
||||||
|
|
||||||
-- name: ListMonitors :many
|
-- name: ListMonitors :many
|
||||||
SELECT * FROM monitors ORDER BY name;
|
-- The org filter, though row security implies it, lets the index be used.
|
||||||
|
SELECT * FROM monitors WHERE org_id = $1 ORDER BY name;
|
||||||
|
|
||||||
-- name: MonitorRegions :many
|
-- name: MonitorRegions :many
|
||||||
SELECT region_id FROM monitor_regions WHERE monitor_id = $1 ORDER BY region_id;
|
SELECT region_id FROM monitor_regions WHERE monitor_id = $1 ORDER BY region_id;
|
||||||
|
|
||||||
-- name: AllMonitorRegions :many
|
-- name: AllMonitorRegions :many
|
||||||
SELECT monitor_id, region_id FROM monitor_regions;
|
SELECT monitor_id, region_id FROM monitor_regions WHERE org_id = $1;
|
||||||
|
|
||||||
-- name: DeleteMonitorRegions :exec
|
-- name: DeleteMonitorRegions :exec
|
||||||
DELETE FROM monitor_regions WHERE monitor_id = $1;
|
DELETE FROM monitor_regions WHERE monitor_id = $1;
|
||||||
@@ -72,3 +73,6 @@ ORDER BY
|
|||||||
CASE WHEN sqlc.narg(before_s)::text IS NULL THEN id END,
|
CASE WHEN sqlc.narg(before_s)::text IS NULL THEN id END,
|
||||||
name DESC, id DESC
|
name DESC, id DESC
|
||||||
LIMIT sqlc.arg(max_rows);
|
LIMIT sqlc.arg(max_rows);
|
||||||
|
|
||||||
|
-- name: SetMonitorPosition :execrows
|
||||||
|
UPDATE monitors SET position = sqlc.arg(position) WHERE id = sqlc.arg(id);
|
||||||
@@ -14,6 +14,7 @@ type LimitsView struct {
|
|||||||
RegionsPerMonitor int
|
RegionsPerMonitor int
|
||||||
OwnRegionsCount bool
|
OwnRegionsCount bool
|
||||||
OrgsPerAccount int
|
OrgsPerAccount int
|
||||||
|
MonitorsPerPage int
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrgsView lists organizations for platform admins.
|
// OrgsView lists organizations for platform admins.
|
||||||
@@ -36,6 +37,7 @@ type OrgRow struct {
|
|||||||
StatusPagesOverride string
|
StatusPagesOverride string
|
||||||
RegionsOverride string
|
RegionsOverride string
|
||||||
OwnRegionsOverride string
|
OwnRegionsOverride string
|
||||||
|
PerPageOverride string
|
||||||
Owner *ModeratedTarget
|
Owner *ModeratedTarget
|
||||||
OwnerOrgs int
|
OwnerOrgs int
|
||||||
OwnerOrgLimit string
|
OwnerOrgLimit string
|
||||||
@@ -62,6 +64,7 @@ templ limitsSection(d LimitsView) {
|
|||||||
@numberField(i18n.T(ctx, "limits.status_pages"), "status_pages", d.StatusPages, 0, 1000000, "")
|
@numberField(i18n.T(ctx, "limits.status_pages"), "status_pages", d.StatusPages, 0, 1000000, "")
|
||||||
@numberField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", d.RegionsPerMonitor, 0, 1000, "")
|
@numberField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", d.RegionsPerMonitor, 0, 1000, "")
|
||||||
@numberField(i18n.T(ctx, "limits.orgs_per_account"), "orgs_per_account", d.OrgsPerAccount, 0, 100000, "")
|
@numberField(i18n.T(ctx, "limits.orgs_per_account"), "orgs_per_account", d.OrgsPerAccount, 0, 100000, "")
|
||||||
|
@numberField(i18n.T(ctx, "limits.monitors_per_page"), "monitors_per_page", d.MonitorsPerPage, 0, 200, "")
|
||||||
</div>
|
</div>
|
||||||
@checkbox(i18n.T(ctx, "limits.own_regions_count"), "own_regions_count", d.OwnRegionsCount)
|
@checkbox(i18n.T(ctx, "limits.own_regions_count"), "own_regions_count", d.OwnRegionsCount)
|
||||||
<p class="mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "limits.own_regions_count_hint") }</p>
|
<p class="mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "limits.own_regions_count_hint") }</p>
|
||||||
@@ -149,6 +152,7 @@ templ orgsSection(v OrgsView) {
|
|||||||
@overrideField(i18n.T(ctx, "limits.monitors"), "monitors", o.MonitorsOverride, v.Defaults.Monitors, 1000000)
|
@overrideField(i18n.T(ctx, "limits.monitors"), "monitors", o.MonitorsOverride, v.Defaults.Monitors, 1000000)
|
||||||
@overrideField(i18n.T(ctx, "limits.status_pages"), "status_pages", o.StatusPagesOverride, v.Defaults.StatusPages, 1000000)
|
@overrideField(i18n.T(ctx, "limits.status_pages"), "status_pages", o.StatusPagesOverride, v.Defaults.StatusPages, 1000000)
|
||||||
@overrideField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", o.RegionsOverride, v.Defaults.RegionsPerMonitor, 1000)
|
@overrideField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", o.RegionsOverride, v.Defaults.RegionsPerMonitor, 1000)
|
||||||
|
@overrideField(i18n.T(ctx, "limits.monitors_per_page"), "monitors_per_page", o.PerPageOverride, v.Defaults.MonitorsPerPage, 200)
|
||||||
<label class="mb-3 block">
|
<label class="mb-3 block">
|
||||||
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "limits.own_regions_count") }</span>
|
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "limits.own_regions_count") }</span>
|
||||||
<select name="own_regions_count" class="w-full border border-rule bg-transparent px-2 py-1 text-sm">
|
<select name="own_regions_count" class="w-full border border-rule bg-transparent px-2 py-1 text-sm">
|
||||||
@@ -207,6 +211,8 @@ templ usageSection(u UsageView) {
|
|||||||
<dd class="font-mono text-xs">@usage(u.StatusPages, u.Limits.StatusPages)</dd>
|
<dd class="font-mono text-xs">@usage(u.StatusPages, u.Limits.StatusPages)</dd>
|
||||||
<dt>{ i18n.T(ctx, "limits.regions_per_monitor") }</dt>
|
<dt>{ i18n.T(ctx, "limits.regions_per_monitor") }</dt>
|
||||||
<dd class="font-mono text-xs">{ limitText(ctx, u.Limits.RegionsPerMonitor) }</dd>
|
<dd class="font-mono text-xs">{ limitText(ctx, u.Limits.RegionsPerMonitor) }</dd>
|
||||||
|
<dt>{ i18n.T(ctx, "limits.monitors_per_page") }</dt>
|
||||||
|
<dd class="font-mono text-xs">{ limitText(ctx, u.Limits.MonitorsPerPage) }</dd>
|
||||||
</dl>
|
</dl>
|
||||||
if u.Limits.RegionsPerMonitor > 0 && !u.Limits.OwnRegionsCount {
|
if u.Limits.RegionsPerMonitor > 0 && !u.Limits.OwnRegionsCount {
|
||||||
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "limits.own_regions_free") }</p>
|
<p class="mt-2 text-xs text-muted">{ i18n.T(ctx, "limits.own_regions_free") }</p>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ type LimitsView struct {
|
|||||||
RegionsPerMonitor int
|
RegionsPerMonitor int
|
||||||
OwnRegionsCount bool
|
OwnRegionsCount bool
|
||||||
OrgsPerAccount int
|
OrgsPerAccount int
|
||||||
|
MonitorsPerPage int
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrgsView lists organizations for platform admins.
|
// OrgsView lists organizations for platform admins.
|
||||||
@@ -45,6 +46,7 @@ type OrgRow struct {
|
|||||||
StatusPagesOverride string
|
StatusPagesOverride string
|
||||||
RegionsOverride string
|
RegionsOverride string
|
||||||
OwnRegionsOverride string
|
OwnRegionsOverride string
|
||||||
|
PerPageOverride string
|
||||||
Owner *ModeratedTarget
|
Owner *ModeratedTarget
|
||||||
OwnerOrgs int
|
OwnerOrgs int
|
||||||
OwnerOrgLimit string
|
OwnerOrgLimit string
|
||||||
@@ -92,7 +94,7 @@ func limitsSection(d LimitsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var2 string
|
var templ_7745c5c3_Var2 string
|
||||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.intro"))
|
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.intro"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 57, Col: 66}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 59, Col: 66}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -126,6 +128,10 @@ func limitsSection(d LimitsView) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
templ_7745c5c3_Err = numberField(i18n.T(ctx, "limits.monitors_per_page"), "monitors_per_page", d.MonitorsPerPage, 0, 200, "").Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</div>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</div>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
@@ -141,7 +147,7 @@ func limitsSection(d LimitsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var3 string
|
var templ_7745c5c3_Var3 string
|
||||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_regions_count_hint"))
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_regions_count_hint"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 67, Col: 89}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 70, Col: 89}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -154,7 +160,7 @@ func limitsSection(d LimitsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var4 string
|
var templ_7745c5c3_Var4 string
|
||||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.save"))
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.save"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 68, Col: 129}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 71, Col: 129}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -194,7 +200,7 @@ func overrideField(label, name, value string, def int, max int) templ.Component
|
|||||||
var templ_7745c5c3_Var6 string
|
var templ_7745c5c3_Var6 string
|
||||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(label)
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(label)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 77, Col: 90}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 80, Col: 90}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -207,7 +213,7 @@ func overrideField(label, name, value string, def int, max int) templ.Component
|
|||||||
var templ_7745c5c3_Var7 string
|
var templ_7745c5c3_Var7 string
|
||||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
|
templ_7745c5c3_Var7, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 80, Col: 14}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 83, Col: 14}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -220,7 +226,7 @@ func overrideField(label, name, value string, def int, max int) templ.Component
|
|||||||
var templ_7745c5c3_Var8 string
|
var templ_7745c5c3_Var8 string
|
||||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templruntime.NewAttributeExpression(strconv.Itoa(max)).Resolve(ctx)
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templruntime.NewAttributeExpression(strconv.Itoa(max)).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 84, Col: 26}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 87, Col: 26}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -233,7 +239,7 @@ func overrideField(label, name, value string, def int, max int) templ.Component
|
|||||||
var templ_7745c5c3_Var9 string
|
var templ_7745c5c3_Var9 string
|
||||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templruntime.NewAttributeExpression(value).Resolve(ctx)
|
templ_7745c5c3_Var9, templ_7745c5c3_Err = templruntime.NewAttributeExpression(value).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 85, Col: 16}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 88, Col: 16}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -246,7 +252,7 @@ func overrideField(label, name, value string, def int, max int) templ.Component
|
|||||||
var templ_7745c5c3_Var10 string
|
var templ_7745c5c3_Var10 string
|
||||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "limits.default", "Value", limitText(ctx, def))).Resolve(ctx)
|
templ_7745c5c3_Var10, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "limits.default", "Value", limitText(ctx, def))).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 86, Col: 76}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 89, Col: 76}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -292,7 +298,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var12 string
|
var templ_7745c5c3_Var12 string
|
||||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.intro"))
|
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.intro"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 95, Col: 74}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 98, Col: 74}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -305,7 +311,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var13 string
|
var templ_7745c5c3_Var13 string
|
||||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templruntime.NewAttributeExpression(v.Search).Resolve(ctx)
|
templ_7745c5c3_Var13, templ_7745c5c3_Err = templruntime.NewAttributeExpression(v.Search).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 100, Col: 20}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 103, Col: 20}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -318,7 +324,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var14 string
|
var templ_7745c5c3_Var14 string
|
||||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "orgs.search")).Resolve(ctx)
|
templ_7745c5c3_Var14, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "orgs.search")).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 101, Col: 44}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 104, Col: 44}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var14)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var14)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -331,7 +337,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var15 string
|
var templ_7745c5c3_Var15 string
|
||||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "orgs.search")).Resolve(ctx)
|
templ_7745c5c3_Var15, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "orgs.search")).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 102, Col: 43}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 105, Col: 43}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -344,7 +350,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var16 string
|
var templ_7745c5c3_Var16 string
|
||||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.search_button"))
|
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.search_button"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 105, Col: 142}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 108, Col: 142}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -362,7 +368,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var17 string
|
var templ_7745c5c3_Var17 string
|
||||||
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.none"))
|
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.none"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 108, Col: 59}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 111, Col: 59}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -380,7 +386,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var18 string
|
var templ_7745c5c3_Var18 string
|
||||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.org"))
|
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.org"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 114, Col: 72}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 117, Col: 72}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -393,7 +399,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var19 string
|
var templ_7745c5c3_Var19 string
|
||||||
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.owner"))
|
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.owner"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 115, Col: 74}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 118, Col: 74}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -406,7 +412,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var20 string
|
var templ_7745c5c3_Var20 string
|
||||||
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.monitors"))
|
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.monitors"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 116, Col: 73}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 119, Col: 73}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -419,7 +425,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var21 string
|
var templ_7745c5c3_Var21 string
|
||||||
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.status_pages"))
|
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.status_pages"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 117, Col: 77}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 120, Col: 77}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -432,7 +438,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var22 string
|
var templ_7745c5c3_Var22 string
|
||||||
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.created"))
|
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.created"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 118, Col: 76}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 121, Col: 76}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -450,7 +456,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var23 string
|
var templ_7745c5c3_Var23 string
|
||||||
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(o.Name)
|
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(o.Name)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 125, Col: 17}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 128, Col: 17}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -463,7 +469,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var24 string
|
var templ_7745c5c3_Var24 string
|
||||||
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(o.Slug)
|
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(o.Slug)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 126, Col: 66}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 129, Col: 66}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -489,7 +495,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var25 string
|
var templ_7745c5c3_Var25 string
|
||||||
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(o.Owner.Name)
|
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(o.Owner.Name)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 131, Col: 48}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 134, Col: 48}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -532,7 +538,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var26 string
|
var templ_7745c5c3_Var26 string
|
||||||
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(o.Created)
|
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(o.Created)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 139, Col: 72}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 142, Col: 72}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -545,7 +551,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var27 string
|
var templ_7745c5c3_Var27 string
|
||||||
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.manage"))
|
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.manage"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 144, Col: 96}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 147, Col: 96}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -558,7 +564,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var28 string
|
var templ_7745c5c3_Var28 string
|
||||||
templ_7745c5c3_Var28, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/admin/orgs/" + o.ID + "/limits").Resolve(ctx)
|
templ_7745c5c3_Var28, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/admin/orgs/" + o.ID + "/limits").Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 146, Col: 61}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 149, Col: 61}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var28)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var28)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -571,7 +577,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var29 string
|
var templ_7745c5c3_Var29 string
|
||||||
templ_7745c5c3_Var29, templ_7745c5c3_Err = templruntime.NewAttributeExpression(v.next()).Resolve(ctx)
|
templ_7745c5c3_Var29, templ_7745c5c3_Err = templruntime.NewAttributeExpression(v.next()).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 146, Col: 102}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 149, Col: 102}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var29)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var29)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -584,7 +590,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var30 string
|
var templ_7745c5c3_Var30 string
|
||||||
templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.limits"))
|
templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.limits"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 147, Col: 113}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 150, Col: 113}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -610,6 +616,10 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
templ_7745c5c3_Err = overrideField(i18n.T(ctx, "limits.monitors_per_page"), "monitors_per_page", o.PerPageOverride, v.Defaults.MonitorsPerPage, 200).Render(ctx, templ_7745c5c3_Buffer)
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "<label class=\"mb-3 block\"><span class=\"mb-1 block text-xs font-medium uppercase tracking-wider text-muted\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "<label class=\"mb-3 block\"><span class=\"mb-1 block text-xs font-medium uppercase tracking-wider text-muted\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
@@ -617,7 +627,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var31 string
|
var templ_7745c5c3_Var31 string
|
||||||
templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_regions_count"))
|
templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_regions_count"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 153, Col: 135}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 157, Col: 135}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -640,7 +650,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var32 string
|
var templ_7745c5c3_Var32 string
|
||||||
templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.default", "Value", i18n.T(ctx, "limits.own_"+strconv.FormatBool(v.Defaults.OwnRegionsCount))))
|
templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.default", "Value", i18n.T(ctx, "limits.own_"+strconv.FormatBool(v.Defaults.OwnRegionsCount))))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 155, Col: 187}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 159, Col: 187}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -663,7 +673,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var33 string
|
var templ_7745c5c3_Var33 string
|
||||||
templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_true"))
|
templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_true"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 156, Col: 112}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 160, Col: 112}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -686,7 +696,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var34 string
|
var templ_7745c5c3_Var34 string
|
||||||
templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_false"))
|
templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_false"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 157, Col: 115}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 161, Col: 115}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -699,7 +709,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var35 string
|
var templ_7745c5c3_Var35 string
|
||||||
templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.save"))
|
templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.save"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 160, Col: 130}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 164, Col: 130}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -721,7 +731,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var36 string
|
var templ_7745c5c3_Var36 string
|
||||||
templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.owner_is_admin"))
|
templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.owner_is_admin"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 164, Col: 84}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 168, Col: 84}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -739,7 +749,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var37 string
|
var templ_7745c5c3_Var37 string
|
||||||
templ_7745c5c3_Var37, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/admin/users/" + o.Owner.ID + "/limits").Resolve(ctx)
|
templ_7745c5c3_Var37, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/admin/users/" + o.Owner.ID + "/limits").Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 167, Col: 70}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 171, Col: 70}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var37)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var37)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -752,7 +762,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var38 string
|
var templ_7745c5c3_Var38 string
|
||||||
templ_7745c5c3_Var38, templ_7745c5c3_Err = templruntime.NewAttributeExpression(v.next()).Resolve(ctx)
|
templ_7745c5c3_Var38, templ_7745c5c3_Err = templruntime.NewAttributeExpression(v.next()).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 167, Col: 111}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 171, Col: 111}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var38)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var38)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -765,7 +775,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var39 string
|
var templ_7745c5c3_Var39 string
|
||||||
templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.target_owner"))
|
templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.target_owner"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 168, Col: 127}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 172, Col: 127}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -790,7 +800,7 @@ func orgsSection(v OrgsView) templ.Component {
|
|||||||
var templ_7745c5c3_Var40 string
|
var templ_7745c5c3_Var40 string
|
||||||
templ_7745c5c3_Var40, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.save"))
|
templ_7745c5c3_Var40, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.save"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 171, Col: 132}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 175, Col: 132}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var40))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var40))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -892,7 +902,7 @@ func usage(used, max int) templ.Component {
|
|||||||
var templ_7745c5c3_Var44 string
|
var templ_7745c5c3_Var44 string
|
||||||
templ_7745c5c3_Var44, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(used))
|
templ_7745c5c3_Var44, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(used))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 191, Col: 83}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 195, Col: 83}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var44))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var44))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -905,7 +915,7 @@ func usage(used, max int) templ.Component {
|
|||||||
var templ_7745c5c3_Var45 string
|
var templ_7745c5c3_Var45 string
|
||||||
templ_7745c5c3_Var45, templ_7745c5c3_Err = templ.JoinStringErrs(limitText(ctx, max))
|
templ_7745c5c3_Var45, templ_7745c5c3_Err = templ.JoinStringErrs(limitText(ctx, max))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 191, Col: 109}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 195, Col: 109}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var45))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var45))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -957,7 +967,7 @@ func usageSection(u UsageView) templ.Component {
|
|||||||
var templ_7745c5c3_Var47 string
|
var templ_7745c5c3_Var47 string
|
||||||
templ_7745c5c3_Var47, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.monitors"))
|
templ_7745c5c3_Var47, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.monitors"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 204, Col: 39}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 208, Col: 39}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var47))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var47))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -978,7 +988,7 @@ func usageSection(u UsageView) templ.Component {
|
|||||||
var templ_7745c5c3_Var48 string
|
var templ_7745c5c3_Var48 string
|
||||||
templ_7745c5c3_Var48, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.status_pages"))
|
templ_7745c5c3_Var48, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.status_pages"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 206, Col: 43}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 210, Col: 43}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var48))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var48))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -999,7 +1009,7 @@ func usageSection(u UsageView) templ.Component {
|
|||||||
var templ_7745c5c3_Var49 string
|
var templ_7745c5c3_Var49 string
|
||||||
templ_7745c5c3_Var49, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.regions_per_monitor"))
|
templ_7745c5c3_Var49, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.regions_per_monitor"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 208, Col: 50}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 212, Col: 50}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var49))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var49))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -1012,36 +1022,62 @@ func usageSection(u UsageView) templ.Component {
|
|||||||
var templ_7745c5c3_Var50 string
|
var templ_7745c5c3_Var50 string
|
||||||
templ_7745c5c3_Var50, templ_7745c5c3_Err = templ.JoinStringErrs(limitText(ctx, u.Limits.RegionsPerMonitor))
|
templ_7745c5c3_Var50, templ_7745c5c3_Err = templ.JoinStringErrs(limitText(ctx, u.Limits.RegionsPerMonitor))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 209, Col: 77}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 213, Col: 77}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var50))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var50))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 81, "</dd></dl>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 81, "</dd><dt>")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var51 string
|
||||||
|
templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.monitors_per_page"))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 214, Col: 48}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var51))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 82, "</dt><dd class=\"font-mono text-xs\">")
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
var templ_7745c5c3_Var52 string
|
||||||
|
templ_7745c5c3_Var52, templ_7745c5c3_Err = templ.JoinStringErrs(limitText(ctx, u.Limits.MonitorsPerPage))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 215, Col: 75}
|
||||||
|
}
|
||||||
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var52))
|
||||||
|
if templ_7745c5c3_Err != nil {
|
||||||
|
return templ_7745c5c3_Err
|
||||||
|
}
|
||||||
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 83, "</dd></dl>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if u.Limits.RegionsPerMonitor > 0 && !u.Limits.OwnRegionsCount {
|
if u.Limits.RegionsPerMonitor > 0 && !u.Limits.OwnRegionsCount {
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 82, "<p class=\"mt-2 text-xs text-muted\">")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 84, "<p class=\"mt-2 text-xs text-muted\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var51 string
|
var templ_7745c5c3_Var53 string
|
||||||
templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_regions_free"))
|
templ_7745c5c3_Var53, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_regions_free"))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 212, Col: 78}
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 218, Col: 78}
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var51))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var53))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 83, "</p>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 85, "</p>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 84, "</section>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 86, "</section>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,6 +178,43 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Saves the order of a list of monitors being arranged.
|
||||||
|
const saveOrder = async (list) => {
|
||||||
|
const ids = [...list.querySelectorAll(":scope > [data-sort-id]")].map((li) => li.dataset.sortId);
|
||||||
|
try {
|
||||||
|
await api.put(list.dataset.sortable, { monitor_ids: ids });
|
||||||
|
} catch (err) {
|
||||||
|
alert(message(err));
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let dragged = null;
|
||||||
|
document.addEventListener("dragstart", (ev) => {
|
||||||
|
const item = ev.target.closest?.("[data-sortable] > [data-sort-id]");
|
||||||
|
if (!item) return;
|
||||||
|
dragged = item;
|
||||||
|
ev.dataTransfer.effectAllowed = "move";
|
||||||
|
item.style.opacity = "0.5";
|
||||||
|
});
|
||||||
|
document.addEventListener("dragover", (ev) => {
|
||||||
|
const over = ev.target.closest?.("[data-sortable] > [data-sort-id]");
|
||||||
|
if (!dragged || !over || over === dragged || over.parentElement !== dragged.parentElement) return;
|
||||||
|
ev.preventDefault();
|
||||||
|
const box = over.getBoundingClientRect();
|
||||||
|
if (ev.clientY < box.top + box.height / 2) over.before(dragged);
|
||||||
|
else over.after(dragged);
|
||||||
|
});
|
||||||
|
document.addEventListener("drop", (ev) => {
|
||||||
|
if (dragged) ev.preventDefault();
|
||||||
|
});
|
||||||
|
document.addEventListener("dragend", async () => {
|
||||||
|
if (!dragged) return;
|
||||||
|
const list = dragged.parentElement;
|
||||||
|
dragged.style.opacity = "";
|
||||||
|
dragged = null;
|
||||||
|
await saveOrder(list);
|
||||||
|
});
|
||||||
|
|
||||||
document.addEventListener("click", async (ev) => {
|
document.addEventListener("click", async (ev) => {
|
||||||
const navToggle = ev.target.closest("[data-nav-toggle]");
|
const navToggle = ev.target.closest("[data-nav-toggle]");
|
||||||
if (navToggle) {
|
if (navToggle) {
|
||||||
@@ -186,6 +223,30 @@
|
|||||||
navToggle.setAttribute("aria-expanded", String(open));
|
navToggle.setAttribute("aria-expanded", String(open));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Moves a monitor up or down while arranging the monitor list.
|
||||||
|
const move = ev.target.closest("[data-sort-move]");
|
||||||
|
if (move) {
|
||||||
|
const item = move.closest("[data-sort-id]");
|
||||||
|
const other = move.dataset.sortMove === "up" ? item.previousElementSibling : item.nextElementSibling;
|
||||||
|
if (!other) return;
|
||||||
|
if (move.dataset.sortMove === "up") other.before(item);
|
||||||
|
else other.after(item);
|
||||||
|
move.focus();
|
||||||
|
await saveOrder(item.closest("[data-sortable]"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Ticks or clears every checkbox named by data-check-all in its form,
|
||||||
|
// of the rows a filter leaves visible.
|
||||||
|
const checkAll = ev.target.closest("[data-check-all]");
|
||||||
|
if (checkAll) {
|
||||||
|
const on = checkAll.dataset.checkAll === "on";
|
||||||
|
checkAll.closest("form")?.querySelectorAll(checkAll.dataset.checkTarget).forEach((box) => {
|
||||||
|
if (box.closest("[data-row]")?.hidden) return;
|
||||||
|
box.checked = on;
|
||||||
|
if (on) addRowFields(box);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const locale = ev.target.closest("[data-locale]");
|
const locale = ev.target.closest("[data-locale]");
|
||||||
if (locale) {
|
if (locale) {
|
||||||
await api.post("/locale", { locale: locale.dataset.locale }).catch(() => {});
|
await api.post("/locale", { locale: locale.dataset.locale }).catch(() => {});
|
||||||
@@ -268,6 +329,29 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// A row of a long list may come without its fields until it is ticked;
|
||||||
|
// they are copied in from the form's template[data-row-fields].
|
||||||
|
function addRowFields(box) {
|
||||||
|
const row = box.closest("[data-row]");
|
||||||
|
const tpl = row?.closest("form")?.querySelector("template[data-row-fields]");
|
||||||
|
if (!tpl || row.querySelector("[data-row-extra]")) return;
|
||||||
|
row.append(tpl.content.cloneNode(true));
|
||||||
|
}
|
||||||
|
document.addEventListener("change", (ev) => {
|
||||||
|
if (ev.target.matches('[data-row] [data-field="include"]') && ev.target.checked) addRowFields(ev.target);
|
||||||
|
});
|
||||||
|
|
||||||
|
// [data-filter-rows] hides the rows of the list it names whose text does
|
||||||
|
// not contain what is typed.
|
||||||
|
document.addEventListener("input", (ev) => {
|
||||||
|
const input = ev.target.closest("[data-filter-rows]");
|
||||||
|
if (!input) return;
|
||||||
|
const needle = input.value.trim().toLowerCase();
|
||||||
|
for (const row of document.querySelectorAll(input.dataset.filterRows + " > [data-row]")) {
|
||||||
|
row.hidden = needle !== "" && !row.textContent.toLowerCase().includes(needle);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Only the settings of the selected check type are shown and submitted.
|
// Only the settings of the selected check type are shown and submitted.
|
||||||
document.addEventListener("change", (ev) => {
|
document.addEventListener("change", (ev) => {
|
||||||
const sel = ev.target.closest("[data-type-select]");
|
const sel = ev.target.closest("[data-type-select]");
|
||||||
|
|||||||
+141
-17
@@ -31,6 +31,11 @@ type MonitorRow struct {
|
|||||||
// Unchecked is set when no region has reported recently: nobody is
|
// Unchecked is set when no region has reported recently: nobody is
|
||||||
// checking the monitor.
|
// checking the monitor.
|
||||||
Unchecked bool
|
Unchecked bool
|
||||||
|
// Position is the organization's own order, -1 when not set; Ratio
|
||||||
|
// the uptime in the range, -1 without data; LatencyMS -1 without data.
|
||||||
|
Position int
|
||||||
|
Ratio float64
|
||||||
|
LatencyMS int
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupNode is a monitor group with its monitors and subgroups.
|
// GroupNode is a monitor group with its monitors and subgroups.
|
||||||
@@ -65,7 +70,21 @@ type DashboardView struct {
|
|||||||
Empty bool
|
Empty bool
|
||||||
CanWrite bool
|
CanWrite bool
|
||||||
Counts map[Status]int
|
Counts map[Status]int
|
||||||
Range string
|
// Filters are the status counts, each linking to the monitors of
|
||||||
|
// that status.
|
||||||
|
Filters []StatusFilter
|
||||||
|
// Filter, if set, lists Results of that status instead of the tree.
|
||||||
|
Filter Status
|
||||||
|
// AllURL leaves the status filter, keeping the search and range.
|
||||||
|
AllURL string
|
||||||
|
// Sorts switch the order of the list; Sort is the active one.
|
||||||
|
Sorts []SortOption
|
||||||
|
Sort string
|
||||||
|
// Arrange shows the tree for putting monitors in order by hand;
|
||||||
|
// ArrangeURL turns it on or off, empty when not offered.
|
||||||
|
Arrange bool
|
||||||
|
ArrangeURL string
|
||||||
|
Range string
|
||||||
Ranges []RangeOption
|
Ranges []RangeOption
|
||||||
// Unchecked counts the monitors no region has reported for recently.
|
// Unchecked counts the monitors no region has reported for recently.
|
||||||
Unchecked int
|
Unchecked int
|
||||||
@@ -73,6 +92,22 @@ type DashboardView struct {
|
|||||||
DeadRegions []DeadRegion
|
DeadRegions []DeadRegion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SortOption is an entry of the sort switcher.
|
||||||
|
type SortOption struct {
|
||||||
|
Key string
|
||||||
|
URL string
|
||||||
|
Active bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusFilter is one status count; URL shows only its monitors, or all
|
||||||
|
// again when it is the active filter.
|
||||||
|
type StatusFilter struct {
|
||||||
|
Status Status
|
||||||
|
Count int
|
||||||
|
URL string
|
||||||
|
Active bool
|
||||||
|
}
|
||||||
|
|
||||||
// DeadRegion is a region without a live checker since Since.
|
// DeadRegion is a region without a live checker since Since.
|
||||||
type DeadRegion struct {
|
type DeadRegion struct {
|
||||||
Name, Since string
|
Name, Since string
|
||||||
@@ -163,14 +198,25 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
|||||||
<h1 class="text-lg font-semibold">{ i18n.T(ctx, "console.monitors.title") }</h1>
|
<h1 class="text-lg font-semibold">{ i18n.T(ctx, "console.monitors.title") }</h1>
|
||||||
<div class="flex flex-wrap items-center gap-x-5 gap-y-3 font-mono text-xs text-muted">
|
<div class="flex flex-wrap items-center gap-x-5 gap-y-3 font-mono text-xs text-muted">
|
||||||
@rangeSwitch(v.Ranges)
|
@rangeSwitch(v.Ranges)
|
||||||
for _, s := range []Status{StatusUp, StatusDegraded, StatusDown, StatusUnknown, StatusMaintenance, StatusPaused} {
|
@sortSwitch(v.Sorts)
|
||||||
if v.Counts[s] > 0 {
|
<nav class="flex flex-wrap items-center gap-x-1 gap-y-2" aria-label={ i18n.T(ctx, "monitors.filter_label") }>
|
||||||
<span class="flex items-center gap-1.5">
|
for _, f := range v.Filters {
|
||||||
@statusDot(s)
|
<a
|
||||||
<span>{ strconv.Itoa(v.Counts[s]) }</span>
|
href={ templ.SafeURL(f.URL) }
|
||||||
</span>
|
class={ "flex items-center gap-1.5 border px-1.5 py-0.5 hover:text-ink",
|
||||||
|
templ.KV("border-ink text-ink", f.Active),
|
||||||
|
templ.KV("border-transparent hover:border-rule", !f.Active) }
|
||||||
|
title={ filterTitle(ctx, f) }
|
||||||
|
aria-label={ filterTitle(ctx, f) }
|
||||||
|
if f.Active {
|
||||||
|
aria-current="true"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
@statusDot(f.Status)
|
||||||
|
<span>{ strconv.Itoa(f.Count) }</span>
|
||||||
|
</a>
|
||||||
}
|
}
|
||||||
}
|
</nav>
|
||||||
if v.CanWrite {
|
if v.CanWrite {
|
||||||
<a href="/monitors/new" class="whitespace-nowrap bg-ink px-3 py-1.5 font-sans text-sm text-paper hover:opacity-90">{ i18n.T(ctx, "monitors.new") }</a>
|
<a href="/monitors/new" class="whitespace-nowrap bg-ink px-3 py-1.5 font-sans text-sm text-paper hover:opacity-90">{ i18n.T(ctx, "monitors.new") }</a>
|
||||||
}
|
}
|
||||||
@@ -191,6 +237,9 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
|||||||
if v.Range != "" {
|
if v.Range != "" {
|
||||||
<input type="hidden" name="range" value={ v.Range }/>
|
<input type="hidden" name="range" value={ v.Range }/>
|
||||||
}
|
}
|
||||||
|
if v.Filter != "" {
|
||||||
|
<input type="hidden" name="status" value={ string(v.Filter) }/>
|
||||||
|
}
|
||||||
<input
|
<input
|
||||||
type="search"
|
type="search"
|
||||||
name="q"
|
name="q"
|
||||||
@@ -205,10 +254,24 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
|||||||
switch {
|
switch {
|
||||||
case v.Empty:
|
case v.Empty:
|
||||||
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
||||||
case v.Search != "":
|
case v.Search != "" || v.Filter != "":
|
||||||
<p class="mb-3 text-sm"><a href="/" class="text-muted hover:text-ink">← { i18n.T(ctx, "monitors.all") }</a></p>
|
<p class="mb-3 flex flex-wrap items-center gap-x-4 gap-y-1 text-sm">
|
||||||
|
<a href="/" class="text-muted hover:text-ink">← { i18n.T(ctx, "monitors.all") }</a>
|
||||||
|
if v.Filter != "" {
|
||||||
|
<span class="flex items-center gap-1.5">
|
||||||
|
{ i18n.T(ctx, "monitors.filter_only") }
|
||||||
|
@statusDot(v.Filter)
|
||||||
|
<span class="font-medium">{ i18n.T(ctx, "status."+string(v.Filter)) }</span>
|
||||||
|
<a href={ templ.SafeURL(v.AllURL) } class="ml-1 text-muted hover:text-ink" aria-label={ i18n.T(ctx, "monitors.filter_clear") } title={ i18n.T(ctx, "monitors.filter_clear") }>×</a>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
</p>
|
||||||
if len(v.Results) == 0 {
|
if len(v.Results) == 0 {
|
||||||
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "monitors.no_match") }</p>
|
if v.Search == "" {
|
||||||
|
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "monitors.no_status_match") }</p>
|
||||||
|
} else {
|
||||||
|
<p class="border-y border-rule py-10 text-center text-sm text-muted">{ i18n.T(ctx, "monitors.no_match") }</p>
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
<div class="border-t border-rule">
|
<div class="border-t border-rule">
|
||||||
@monitorList(v.Results)
|
@monitorList(v.Results)
|
||||||
@@ -223,17 +286,31 @@ templ Dashboard(p Page, me Me, v DashboardView) {
|
|||||||
<span class="font-medium">{ v.Focus }</span>
|
<span class="font-medium">{ v.Focus }</span>
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
|
if v.Arrange {
|
||||||
|
<p class="mb-3 border-l-2 border-ink pl-3 text-sm">{ i18n.T(ctx, "monitors.arrange_hint") }</p>
|
||||||
|
}
|
||||||
<div class="border-t border-rule">
|
<div class="border-t border-rule">
|
||||||
@monitorList(v.Root.Monitors)
|
@treeList(v.Root.Monitors, v.Arrange)
|
||||||
@moreLink(v.Root)
|
@moreLink(v.Root)
|
||||||
for _, g := range v.Root.Children {
|
for _, g := range v.Root.Children {
|
||||||
@groupBlock(g)
|
@groupBlock(g, v.Arrange)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@pager(v.Pager, "previous", "next")
|
@pager(v.Pager, "previous", "next")
|
||||||
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.range_note", "Range", v.Range) }</p>
|
<p class="mt-3 text-right text-xs text-muted">{ i18n.T(ctx, "monitors.range_note", "Range", v.Range) }</p>
|
||||||
}
|
}
|
||||||
<p class="mt-8 text-sm"><a href="/groups" class="text-muted hover:text-ink">{ i18n.T(ctx, "groups.manage") }</a></p>
|
<p class="mt-8 flex flex-wrap gap-x-6 gap-y-2 text-sm">
|
||||||
|
<a href="/groups" class="text-muted hover:text-ink">{ i18n.T(ctx, "groups.manage") }</a>
|
||||||
|
if v.ArrangeURL != "" {
|
||||||
|
<a href={ templ.SafeURL(v.ArrangeURL) } class="text-muted hover:text-ink">
|
||||||
|
if v.Arrange {
|
||||||
|
{ i18n.T(ctx, "monitors.arrange_done") }
|
||||||
|
} else {
|
||||||
|
{ i18n.T(ctx, "monitors.arrange") }
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
</p>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +350,7 @@ templ moreLink(g GroupNode) {
|
|||||||
|
|
||||||
// groupBlock renders a group and, recursively, its subgroups. <details>
|
// groupBlock renders a group and, recursively, its subgroups. <details>
|
||||||
// makes groups collapsible without JavaScript.
|
// makes groups collapsible without JavaScript.
|
||||||
templ groupBlock(g GroupNode) {
|
templ groupBlock(g GroupNode, arrange bool) {
|
||||||
<details open class="border-b border-rule">
|
<details open class="border-b border-rule">
|
||||||
<summary class="flex cursor-pointer items-center gap-2.5 py-2.5 text-sm font-medium select-none hover:bg-rule/30">
|
<summary class="flex cursor-pointer items-center gap-2.5 py-2.5 text-sm font-medium select-none hover:bg-rule/30">
|
||||||
@statusDot(g.Status)
|
@statusDot(g.Status)
|
||||||
@@ -281,10 +358,10 @@ templ groupBlock(g GroupNode) {
|
|||||||
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(g.Total) }</span>
|
<span class="font-mono text-xs font-normal text-muted">{ strconv.Itoa(g.Total) }</span>
|
||||||
</summary>
|
</summary>
|
||||||
<div class="ml-4 border-l border-rule pl-4">
|
<div class="ml-4 border-l border-rule pl-4">
|
||||||
@monitorList(g.Monitors)
|
@treeList(g.Monitors, arrange)
|
||||||
@moreLink(g)
|
@moreLink(g)
|
||||||
for _, c := range g.Children {
|
for _, c := range g.Children {
|
||||||
@groupBlock(c)
|
@groupBlock(c, arrange)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
@@ -1589,3 +1666,50 @@ templ IncidentStatusesPage(p Page, me Me, statuses []CustomIncidentStatus, canMa
|
|||||||
</section>
|
</section>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterTitle(ctx context.Context, f StatusFilter) string {
|
||||||
|
if f.Active {
|
||||||
|
return i18n.T(ctx, "monitors.filter_clear")
|
||||||
|
}
|
||||||
|
return i18n.T(ctx, "monitors.filter_show", "Status", i18n.T(ctx, "status."+string(f.Status)), "Count", f.Count)
|
||||||
|
}
|
||||||
|
|
||||||
|
templ sortSwitch(opts []SortOption) {
|
||||||
|
<nav class="flex min-w-0 max-w-full overflow-x-auto border border-rule font-mono text-xs" aria-label={ i18n.T(ctx, "monitors.sort") }>
|
||||||
|
for _, o := range opts {
|
||||||
|
if o.Active {
|
||||||
|
<span class="whitespace-nowrap bg-ink px-2 py-1 text-paper" aria-current="true">{ i18n.T(ctx, "monitors.sort_"+o.Key) }</span>
|
||||||
|
} else {
|
||||||
|
<a href={ templ.SafeURL(o.URL) } class="whitespace-nowrap px-2 py-1 text-muted hover:text-ink">{ i18n.T(ctx, "monitors.sort_"+o.Key) }</a>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</nav>
|
||||||
|
}
|
||||||
|
|
||||||
|
// treeList is a group's own monitors, as links or, while arranging, as
|
||||||
|
// rows to put in order.
|
||||||
|
templ treeList(ms []MonitorRow, arrange bool) {
|
||||||
|
if arrange {
|
||||||
|
@arrangeList(ms)
|
||||||
|
} else {
|
||||||
|
@monitorList(ms)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// arrangeList lets monitors be dragged or moved up and down; every change
|
||||||
|
// is saved at once.
|
||||||
|
templ arrangeList(ms []MonitorRow) {
|
||||||
|
if len(ms) > 0 {
|
||||||
|
<ul data-sortable="/org/monitors/order" class="divide-y divide-rule border-b border-rule text-sm">
|
||||||
|
for _, m := range ms {
|
||||||
|
<li data-sort-id={ m.ID } draggable="true" class="flex cursor-move items-center gap-3 py-2.5">
|
||||||
|
<span class="select-none text-muted" aria-hidden="true">⠿</span>
|
||||||
|
@statusDot(m.Status)
|
||||||
|
<span class="min-w-0 flex-1 truncate">{ m.Name }</span>
|
||||||
|
<button type="button" data-sort-move="up" class="px-1.5 text-muted hover:text-ink" aria-label={ i18n.T(ctx, "monitors.move_up", "Name", m.Name) } title={ i18n.T(ctx, "monitors.move_up", "Name", m.Name) }>↑</button>
|
||||||
|
<button type="button" data-sort-move="down" class="px-1.5 text-muted hover:text-ink" aria-label={ i18n.T(ctx, "monitors.move_down", "Name", m.Name) } title={ i18n.T(ctx, "monitors.move_down", "Name", m.Name) }>↓</button>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
|
}
|
||||||
+2925
-2335
File diff suppressed because it is too large.
Load diff
@@ -118,6 +118,8 @@ type PageEditor struct {
|
|||||||
SwitchOffAt string
|
SwitchOffAt string
|
||||||
// DomainChangesPerDay is how often the domain may be changed a day.
|
// DomainChangesPerDay is how often the domain may be changed a day.
|
||||||
DomainChangesPerDay int
|
DomainChangesPerDay int
|
||||||
|
// MonitorLimit is how many monitors the page may show; 0 is any.
|
||||||
|
MonitorLimit int
|
||||||
RecordName string
|
RecordName string
|
||||||
RecordValue string
|
RecordValue string
|
||||||
Suspended bool
|
Suspended bool
|
||||||
@@ -272,8 +274,22 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
|||||||
@formError()
|
@formError()
|
||||||
if len(e.Monitors) == 0 {
|
if len(e.Monitors) == 0 {
|
||||||
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
<p class="mb-4 text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
||||||
|
} else {
|
||||||
|
if e.MonitorLimit > 0 {
|
||||||
|
<p class="mb-2 text-xs text-muted">{ i18n.T(ctx, "pages.monitor_limit", "Max", e.MonitorLimit) }</p>
|
||||||
|
}
|
||||||
|
<p class="mb-2 flex gap-4 text-xs">
|
||||||
|
<button type="button" data-check-all="on" data-check-target="[data-field=include]" class="text-muted hover:text-ink">{ i18n.T(ctx, "pages.monitors_all") }</button>
|
||||||
|
<button type="button" data-check-all="off" data-check-target="[data-field=include]" class="text-muted hover:text-ink">{ i18n.T(ctx, "pages.monitors_none") }</button>
|
||||||
|
</p>
|
||||||
}
|
}
|
||||||
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
|
if len(e.Monitors) > monitorFilterFrom {
|
||||||
|
<input type="search" data-filter-rows="#page-monitors" placeholder={ i18n.T(ctx, "pages.monitors_filter") } aria-label={ i18n.T(ctx, "pages.monitors_filter") } class="mb-2 w-full border border-rule bg-transparent px-2 py-1 text-sm outline-none focus:border-ink"/>
|
||||||
|
}
|
||||||
|
<template data-row-fields>
|
||||||
|
@pageMonitorFields(e, PageMonitorOption{})
|
||||||
|
</template>
|
||||||
|
<ul id="page-monitors" class="mb-4 divide-y divide-rule border-y border-rule text-sm">
|
||||||
for _, m := range e.Monitors {
|
for _, m := range e.Monitors {
|
||||||
<li data-row class="grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 py-2">
|
<li data-row class="grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 py-2">
|
||||||
<input type="checkbox" data-field="include" checked?={ m.Included } class="accent-ink" aria-label={ m.Name }/>
|
<input type="checkbox" data-field="include" checked?={ m.Included } class="accent-ink" aria-label={ m.Name }/>
|
||||||
@@ -284,16 +300,11 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
|||||||
}
|
}
|
||||||
</span>
|
</span>
|
||||||
<input type="hidden" data-field="monitor_id" value={ m.ID }/>
|
<input type="hidden" data-field="monitor_id" value={ m.ID }/>
|
||||||
<span></span>
|
// Organizations may have thousands of monitors: only those on
|
||||||
<span class="flex gap-2">
|
// the page carry their fields, the others get them when ticked.
|
||||||
<select data-field="group_id" data-nullable aria-label={ i18n.T(ctx, "pages.group") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink">
|
if m.Included {
|
||||||
<option value="">{ i18n.T(ctx, "pages.no_group") }</option>
|
@pageMonitorFields(e, m)
|
||||||
for _, opt := range e.Groups {
|
}
|
||||||
<option value={ opt.ID } selected?={ opt.ID == m.GroupID }>{ opt.Label }</option>
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
<input data-field="label" value={ m.Label } placeholder={ i18n.T(ctx, "pages.label") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
|
|
||||||
</span>
|
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -369,3 +380,21 @@ templ dnsRecordList(kind, name, value string) {
|
|||||||
templ verifyButton(pageID, label string) {
|
templ verifyButton(pageID, label string) {
|
||||||
<button type="button" data-post={ "/org/statuspages/" + pageID + "/domain/verify" } data-ok={ i18n.T(ctx, "pages.domain_verified") } data-reload class="mt-3 border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, label) }</button>
|
<button type="button" data-post={ "/org/statuspages/" + pageID + "/domain/verify" } data-ok={ i18n.T(ctx, "pages.domain_verified") } data-reload class="mt-3 border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, label) }</button>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// monitorFilterFrom is how many monitors the page editor lists before it
|
||||||
|
// offers to filter them.
|
||||||
|
const monitorFilterFrom = 15
|
||||||
|
|
||||||
|
// pageMonitorFields are the group and label of m on the page.
|
||||||
|
templ pageMonitorFields(e PageEditor, m PageMonitorOption) {
|
||||||
|
<span data-row-extra></span>
|
||||||
|
<span class="flex gap-2">
|
||||||
|
<select data-field="group_id" data-nullable aria-label={ i18n.T(ctx, "pages.group") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink">
|
||||||
|
<option value="">{ i18n.T(ctx, "pages.no_group") }</option>
|
||||||
|
for _, opt := range e.Groups {
|
||||||
|
<option value={ opt.ID } selected?={ opt.ID == m.GroupID }>{ opt.Label }</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
<input data-field="label" value={ m.Label } placeholder={ i18n.T(ctx, "pages.label") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
+386
-254
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user