Compare commits

..
8 Commits
Author SHA1 Message Date
Sebi df39b765cb Merge pull request 'feat(agents): talk to the API over a WebSocket and push page changes' (#161) from feat/agent-websocket into main
release / release (push) Successful in 38m55s
ci / build (push) Successful in 20m33s
ci / lint (push) Successful in 12m10s
ci / image (push) Successful in 5m55s
ci / test (push) Successful in 9m25s
2026-11-26 16:48:08 +00:00
Sebi 26e7275dd3 Merge pull request 'perf: fast console pages for organizations with many monitors' (#160) from perf/console-many-monitors into main
ci / test (push) Canceled after 58s
ci / image (push) Canceled after 0s
ci / lint (push) Canceled after 59s
ci / build (push) Canceled after 0s
2026-11-26 16:46:59 +00:00
Sebastian UnterschützandClaude Opus 5.5 538c43b563 feat(agents): talk to the API over a WebSocket and push page changes
ci / test (pull_request) Successful in 12m55s
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / build (pull_request) Successful in 16m45s
ci / lint (push) Skipped
ci / lint (pull_request) Successful in 6m29s
ci / image (pull_request) Successful in 5m41s
Checkers and status page servers keep one WebSocket open to the API at
/agent/v1/stream and send their requests over it. The API answers them
through the agent API as if they had come over HTTP, each authenticated
again, so the protocol stays the same and a revoked token ends the
stream. While the stream is down agents fall back to plain HTTP, and an
API without it is asked again every five minutes.

Over the stream the API tells status page servers which of their pages
changed, so they fetch them at once instead of on their next refresh:
when a region of a monitor changes between up and down, an incident
opens or resolves, or anything of the organization is edited. Changes
are announced through Redis to every API instance and sent at most every
five seconds per stream. A page that changes while it is fetched is
fetched once more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-26 17:21:30 +01:00
Sebastian UnterschützandClaude Opus 5.5 27338f0557 perf(statuspages): build page snapshots in time for large organizations
ci / test (push) Skipped
ci / build (push) Skipped
ci / lint (pull_request) Successful in 6m29s
ci / test (pull_request) Successful in 12m37s
ci / lint (push) Skipped
ci / image (push) Skipped
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Successful in 5m39s
The snapshot read the incidents of a page without the organization, which
row level security keeps from using an index, and every status page
server asking for a page built it on its own. Snapshots now filter by the
organization and servers asking at the same time share one build, which
does not end when one of them gives up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-26 17:04:00 +01:00
Sebastian UnterschützandClaude Opus 5.5 1138d555aa perf: load console pages in time for organizations with many monitors
ci / lint (push) Skipped
ci / image (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / test (pull_request) Successful in 12m19s
ci / lint (pull_request) Successful in 11m10s
ci / build (pull_request) Successful in 18m13s
ci / image (pull_request) Successful in 5m20s
Every console page that shows monitor status (monitors, incidents,
monitor details, evidence) went through one loader that read, for all of
the organization's monitors:

- the newest result per monitor and region, by scanning a day of raw
  results;
- the bars of the selected range, from raw results for ranges up to 24h,
  though only one page of monitors is shown;
- when each monitor first reported, scanning two days of results.

With 3000 monitors that took about a second, growing with the number of
results. Now:

- latest_results keeps the newest result per monitor and region,
  updated as results are stored (migration 00055 fills it from the last
  day);
- bars are loaded only for the monitors a page shows;
- first data is loaded per monitor on its page, and the monitor list asks
  only for the organization's earliest data, by index;
- monitor, region and incident queries name the organization, so their
  indexes are used instead of row security filtering whole tables.

Public status pages also read only their own monitors' latest results
and hourly buckets instead of the whole organization's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-26 08:00:38 +01:00
Sebastian UnterschützandClaude Opus 5.5 2a440b9c5e perf(console): keep the status page editor light with many monitors
The editor rendered a group select and label field for every monitor of
the organization, about 2 MB of HTML for 3000 monitors. Only monitors on
the page carry their fields now; others get them from a template when
ticked. A filter field narrows long lists, and "Add all" ticks only the
monitors it leaves visible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-26 08:00:38 +01:00
Sebi b88ed4bfd2 Merge pull request 'test(checker): check the runner's error in the recovery test' (#159) from fix/lint-recovery-test into main
ci / image (push) Successful in 3m33s
ci / build (push) Successful in 11m12s
release / release (push) Successful in 30m28s
ci / lint (push) Successful in 6m32s
ci / test (push) Successful in 15m19s
2026-11-25 23:27:42 +00:00
Sebastian UnterschützandClaude Opus 5.5 1dcb1531d0 test(checker): check the runner's error in the recovery test
ci / build (pull_request) Successful in 18m3s
ci / image (pull_request) Successful in 5m18s
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (push) Skipped
ci / test (push) Skipped
ci / test (pull_request) Successful in 9m12s
ci / lint (pull_request) Successful in 11m24s
golangci-lint's errcheck failed the v0.7.1 build on the unchecked result
of the runner in TestRecoveryIsLogged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-26 00:27:14 +01:00
44 changed files with 2203 additions and 541 deletions

No files matched your search

+2
View File
@@ -102,6 +102,8 @@ docker run -d --restart unless-stopped -e UPTIME_API_URL=https://uptime.example.
git.zb-server.de/zb-server/uptimesebi-checker:latest
```
Agents keep one WebSocket open to the API (`/agent/v1/stream`) and send their requests over it. Over it the API also tells status page servers at once when a page changed, e.g. when a monitor fails or the page is edited. A proxy in front of the API must pass WebSocket upgrades. While the WebSocket is down, agents fall back to plain HTTPS requests, and pages are refreshed every 30 seconds as before.
The quickest way onto a Linux host with Docker is the install script your platform serves, with its address filled in. It checks the host, writes `/opt/uptimesebi/<kind>/compose.yaml` and `.env` (the token readable only by root) and starts the agent:
```sh
+1
View File
@@ -65,6 +65,7 @@ func run(log *slog.Logger, level *slog.LevelVar) error {
log = log.With("region", hello.Region, "agent", hello.Name, "instance", instance)
log.Info("connected to api")
client.UseStream(ctx, agentapi.StreamOptions{Log: log})
runner := checker.New(client, cfg.Concurrency, log)
health := platform.NewHealth(map[string]platform.Probe{"api": runner.Healthy})
r := platform.NewRouter(log)
+2
View File
@@ -77,6 +77,8 @@ func run(log *slog.Logger, level *slog.LevelVar) error {
if err != nil {
return err
}
// Pages are told about changes over the stream and fetched through it.
client.UseStream(ctx, agentapi.StreamOptions{Log: log, OnEvent: pages.OnEvent})
apiProbe := func(ctx context.Context) error { _, err := client.Hello(ctx); return err }
health := platform.NewHealth(map[string]platform.Probe{
"pages": func(ctx context.Context) error { return pages.Ready(ctx, apiProbe) },
+1 -1
View File
@@ -34,6 +34,7 @@ require (
golang.org/x/crypto/x509roots/fallback v0.0.0-20261123165210-6c21c5864259
golang.org/x/net v0.63.0
golang.org/x/oauth2 v0.38.0
golang.org/x/sync v0.25.0
golang.org/x/text v0.44.0
google.golang.org/grpc v1.85.0
layeh.com/radius v0.0.0-20231213012653-1006025d24f8
@@ -116,7 +117,6 @@ require (
golang.org/x/arch v0.22.0 // indirect
golang.org/x/exp v0.0.0-20261109185158-a52e3aef5920 // indirect
golang.org/x/mod v0.43.0 // indirect
golang.org/x/sync v0.25.0 // indirect
golang.org/x/sys v0.50.0 // indirect
golang.org/x/tools v0.52.1-0.20261106145633-d407941a339a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20261110000943-09e21b237f2c // indirect
+363
View File
@@ -0,0 +1,363 @@
package agentapi
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"strings"
"sync"
"time"
"github.com/coder/websocket"
)
// The stream is one WebSocket from an agent to the API. It carries the
// agent's requests, which the API answers as if they had come over HTTP,
// and events the API sends unasked, such as which status pages changed.
// Agents fall back to plain HTTP while it is down, and an API without it
// is asked again only now and then.
const (
// Prefix is the path of the agent API.
Prefix = "/agent/v1"
// StreamPath is where agents open the stream, below Prefix.
StreamPath = "/stream"
// MaxFrame bounds a frame read from the stream.
MaxFrame = 64 << 20
// EventPages lists pages that changed, as a PagesEvent.
EventPages = "pages"
)
// Frame is the header of a stream message. A message is the header as
// JSON, a newline and the body. Requests carry ID, Method and Path, replies
// the request's ID and Status, events Event; Cancel withdraws a request.
type Frame struct {
ID uint64 `json:"id,omitempty"`
Method string `json:"method,omitempty"`
// Path is below Prefix and includes the query.
Path string `json:"path,omitempty"`
Status int `json:"status,omitempty"`
Header http.Header `json:"header,omitempty"`
Cancel bool `json:"cancel,omitempty"`
Event string `json:"event,omitempty"`
}
// PagesEvent names status pages that changed and should be fetched again.
type PagesEvent struct {
Pages []PageRef `json:"pages"`
}
// EncodeFrame builds a stream message.
func EncodeFrame(f Frame, body []byte) []byte {
head, _ := json.Marshal(f)
out := make([]byte, 0, len(head)+1+len(body))
return append(append(append(out, head...), '\n'), body...)
}
// DecodeFrame splits a stream message into its header and body.
func DecodeFrame(msg []byte) (Frame, []byte, error) {
var f Frame
head, body, ok := bytes.Cut(msg, []byte{'\n'})
if !ok {
return f, nil, errors.New("agentapi: frame without header")
}
err := json.Unmarshal(head, &f)
return f, body, err
}
// StreamOptions configure UseStream.
type StreamOptions struct {
Log *slog.Logger
// OnEvent receives the events the API sends. It runs on the stream's
// reader and must not block.
OnEvent func(event string, body []byte)
}
const (
pingEvery = 20 * time.Second
pingTimeout = 15 * time.Second
// unsupportedRetry is how long an API without the stream is not asked
// again.
unsupportedRetry = 5 * time.Minute
)
var (
errStreamClosed = errors.New("agentapi: stream closed")
errStreamUnsupported = errors.New("agentapi: API has no stream")
)
// UseStream sends the client's requests over a WebSocket to the API from
// now on, while it is open, and keeps reopening it until ctx ends. Call it
// before the client is used concurrently.
func (c *Client) UseStream(ctx context.Context, o StreamOptions) {
if o.Log == nil {
o.Log = slog.New(slog.DiscardHandler)
}
fallback := c.hc.Transport
if fallback == nil {
fallback = http.DefaultTransport
}
// The handshake runs over the plain client; a client timeout would end
// the stream, so only the context bounds it.
dial := *c.hc
dial.Timeout = 0
t := &streamTransport{c: c, fallback: fallback, dial: &dial, opts: o}
hc := *c.hc
hc.Transport = t
c.hc = &hc
go t.run(ctx)
}
// Streaming reports whether requests currently go over the stream.
func (c *Client) Streaming() bool {
t, ok := c.hc.Transport.(*streamTransport)
return ok && t.current() != nil
}
// streamTransport sends requests over the stream while it is open and over
// fallback otherwise.
type streamTransport struct {
c *Client
fallback http.RoundTripper
dial *http.Client
opts StreamOptions
mu sync.Mutex
conn *streamConn
}
func (t *streamTransport) current() *streamConn {
t.mu.Lock()
defer t.mu.Unlock()
return t.conn
}
func (t *streamTransport) set(sc *streamConn) {
t.mu.Lock()
t.conn = sc
t.mu.Unlock()
}
// RoundTrip implements http.RoundTripper.
func (t *streamTransport) RoundTrip(req *http.Request) (*http.Response, error) {
sc := t.current()
path, below := strings.CutPrefix(req.URL.Path, Prefix)
if sc == nil || !below || path == StreamPath {
return t.fallback.RoundTrip(req)
}
var body []byte
if req.Body != nil {
var err error
body, err = io.ReadAll(req.Body)
_ = req.Body.Close()
if err != nil {
return nil, err
}
}
header := req.Header.Clone()
// The stream is authenticated once, as the agent that opened it.
for _, k := range []string{"Authorization", VersionHeader, InstanceHeader, ReleaseHeader} {
header.Del(k)
}
if req.URL.RawQuery != "" {
path += "?" + req.URL.RawQuery
}
f, rbody, sent, err := sc.roundTrip(req.Context(), Frame{Method: req.Method, Path: path, Header: header}, body)
if err != nil {
if !sent && req.Context().Err() == nil {
// Never reached the API: plain HTTP can still deliver it.
retry := req.Clone(req.Context())
retry.Body = io.NopCloser(bytes.NewReader(body))
return t.fallback.RoundTrip(retry)
}
return nil, err
}
if f.Header == nil {
f.Header = http.Header{}
}
return &http.Response{
Status: fmt.Sprintf("%d %s", f.Status, http.StatusText(f.Status)), StatusCode: f.Status,
Proto: "HTTP/1.1", ProtoMajor: 1, ProtoMinor: 1, Header: f.Header,
Body: io.NopCloser(bytes.NewReader(rbody)), ContentLength: int64(len(rbody)), Request: req,
}, nil
}
// run keeps the stream open until ctx ends.
func (t *streamTransport) run(ctx context.Context) {
backoff := time.Second
var down time.Time
for ctx.Err() == nil {
sc, err := t.open(ctx)
if err != nil {
wait := backoff
if errors.Is(err, errStreamUnsupported) {
wait = unsupportedRetry
t.opts.Log.Info("the API has no WebSocket stream yet; using HTTP", "retry_in", wait.String())
} else {
t.opts.Log.Debug("opening the WebSocket to the API failed", "error", err, "retry_in", wait.String())
backoff = min(backoff*2, 30*time.Second)
}
sleepCtx(ctx, wait)
continue
}
backoff = time.Second
if down.IsZero() {
t.opts.Log.Info("connected to the API over WebSocket")
} else {
t.opts.Log.Info("connected to the API over WebSocket again", "down_for", time.Since(down).Round(time.Second).String())
}
t.set(sc)
err = sc.serve(ctx, t.opts.OnEvent)
t.set(nil)
down = time.Now()
if ctx.Err() == nil {
t.opts.Log.Info("WebSocket to the API closed; using HTTP until it is back", "error", err)
}
}
}
func (t *streamTransport) open(ctx context.Context) (*streamConn, error) {
u := t.c.base + Prefix + StreamPath
switch {
case strings.HasPrefix(u, "https://"):
u = "wss://" + strings.TrimPrefix(u, "https://")
case strings.HasPrefix(u, "http://"):
u = "ws://" + strings.TrimPrefix(u, "http://")
}
h := http.Header{}
h.Set("Authorization", "Bearer "+t.c.token)
h.Set(VersionHeader, fmt.Sprint(Version))
h.Set(InstanceHeader, t.c.instance.String())
h.Set(ReleaseHeader, t.c.release)
dctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
ws, resp, err := websocket.Dial(dctx, u, &websocket.DialOptions{
HTTPClient: t.dial, HTTPHeader: h, CompressionMode: websocket.CompressionContextTakeover,
})
if err != nil {
if resp != nil {
switch resp.StatusCode {
case http.StatusNotFound, http.StatusMethodNotAllowed:
return nil, errStreamUnsupported
case http.StatusUnauthorized:
return nil, ErrUnauthorized
}
}
return nil, err
}
ws.SetReadLimit(MaxFrame)
return &streamConn{ws: ws, waiting: map[uint64]chan reply{}, closed: make(chan struct{})}, nil
}
type reply struct {
f Frame
body []byte
}
// streamConn is one open stream.
type streamConn struct {
ws *websocket.Conn
mu sync.Mutex
next uint64
waiting map[uint64]chan reply
closed chan struct{}
}
// roundTrip sends a request and waits for its reply. sent reports whether
// the request may have reached the API.
func (sc *streamConn) roundTrip(ctx context.Context, f Frame, body []byte) (Frame, []byte, bool, error) {
ch := make(chan reply, 1)
sc.mu.Lock()
sc.next++
f.ID = sc.next
sc.waiting[f.ID] = ch
sc.mu.Unlock()
defer func() {
sc.mu.Lock()
delete(sc.waiting, f.ID)
sc.mu.Unlock()
}()
select {
case <-sc.closed:
return Frame{}, nil, false, errStreamClosed
default:
}
if err := sc.ws.Write(ctx, websocket.MessageBinary, EncodeFrame(f, body)); err != nil {
return Frame{}, nil, false, err
}
select {
case r := <-ch:
return r.f, r.body, true, nil
case <-sc.closed:
return Frame{}, nil, true, errStreamClosed
case <-ctx.Done():
// The API stops working on it, e.g. ends a long poll.
cctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
_ = sc.ws.Write(cctx, websocket.MessageBinary, EncodeFrame(Frame{ID: f.ID, Cancel: true}, nil))
cancel()
return Frame{}, nil, true, ctx.Err()
}
}
// serve reads replies and events until the stream closes or ctx ends.
func (sc *streamConn) serve(ctx context.Context, onEvent func(string, []byte)) error {
defer close(sc.closed)
done := make(chan struct{})
defer close(done)
go func() {
tick := time.NewTicker(pingEvery)
defer tick.Stop()
for {
select {
case <-done:
return
case <-ctx.Done():
_ = sc.ws.Close(websocket.StatusNormalClosure, "agent stopping")
return
case <-tick.C:
pctx, cancel := context.WithTimeout(ctx, pingTimeout)
err := sc.ws.Ping(pctx)
cancel()
if err != nil && ctx.Err() == nil {
_ = sc.ws.CloseNow()
return
}
}
}
}()
for {
_, msg, err := sc.ws.Read(context.WithoutCancel(ctx))
if err != nil {
_ = sc.ws.CloseNow()
return err
}
f, body, err := DecodeFrame(msg)
if err != nil {
continue
}
if f.Event != "" {
if onEvent != nil {
onEvent(f.Event, body)
}
continue
}
sc.mu.Lock()
ch := sc.waiting[f.ID]
sc.mu.Unlock()
if ch != nil {
ch <- reply{f: f, body: body}
}
}
}
func sleepCtx(ctx context.Context, d time.Duration) {
select {
case <-ctx.Done():
case <-time.After(d):
}
}
+47
View File
@@ -0,0 +1,47 @@
package agentapi
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/google/uuid"
)
func TestFrameRoundTrip(t *testing.T) {
in := Frame{ID: 7, Method: http.MethodPut, Path: "/storage?key=a", Header: http.Header{"If-None-Match": {`"x"`}}}
f, body, err := DecodeFrame(EncodeFrame(in, []byte("line one\nline two")))
if err != nil || f.ID != 7 || f.Path != in.Path || f.Header.Get("If-None-Match") != `"x"` || string(body) != "line one\nline two" {
t.Errorf("DecodeFrame(EncodeFrame()) = %+v, %q, %v", f, body, err)
}
if _, _, err := DecodeFrame([]byte(`{"id":1}`)); err == nil {
t.Error("DecodeFrame(no newline) succeeded")
}
}
// An API without the stream is used over HTTP.
func TestStreamFallsBackToHTTP(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != Prefix+"/hello" {
http.NotFound(w, r)
return
}
_ = json.NewEncoder(w).Encode(Hello{Name: "plain", Kind: "checker"})
}))
defer srv.Close()
c := NewClient(srv.URL, "usa_x", uuid.New(), "test")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c.UseStream(ctx, StreamOptions{})
time.Sleep(100 * time.Millisecond)
h, err := c.Hello(ctx)
if err != nil || h.Name != "plain" {
t.Fatalf("Hello() = %+v, %v", h, err)
}
if c.Streaming() {
t.Error("Streaming() = true against an API without the stream")
}
}
+8 -3
View File
@@ -38,9 +38,10 @@ const (
)
func (s *Server) mountAgentAPI(r gin.IRouter) {
g := r.Group("/agent/v1", s.agentAuth())
g := r.Group(agentapi.Prefix, s.agentAuth())
g.GET("/hello", s.agentHello)
g.GET("/update", s.agentUpdate)
g.GET(agentapi.StreamPath, s.agentStream)
sp := g.Group("", requireAgentKind("statuspage"))
sp.GET("/pages", s.agentPage)
sp.GET("/pages/index", s.agentPageIndex)
@@ -301,7 +302,10 @@ func (s *Server) agentResults(c *gin.Context) {
}
now := time.Now()
monitors := map[uuid.UUID]store.MonitorsForResultsRow{}
var accepted []agentapi.Result
var (
accepted []agentapi.Result
changed []uuid.UUID
)
err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
a := agentOf(c)
rows, err := q.MonitorsForResults(ctx, store.MonitorsForResultsParams{RegionID: deref(a.RegionID), Ids: ids, AgentOrg: a.OrgID})
@@ -337,7 +341,7 @@ func (s *Server) agentResults(c *gin.Context) {
if len(params) == 0 {
return nil
}
_, err = q.InsertCheckResults(ctx, params)
changed, err = insertResults(ctx, q, params)
return err
})
if err != nil {
@@ -346,6 +350,7 @@ func (s *Server) agentResults(c *gin.Context) {
internalError(c, err)
return
}
s.pagesChanged(ctx, changed...)
s.evaluateResults(ctx, region, accepted, monitors)
s.storeEvidence(ctx, region, instance, accepted, monitors)
s.finishRunning(ctx, instance, accepted)
+3 -1
View File
@@ -50,7 +50,9 @@ func (s *Server) evaluateResults(ctx context.Context, region string, results []a
Interval: time.Duration(m.IntervalSeconds) * time.Second, Confirmations: int(m.Confirmations), Regions: m.Regions,
})
if err == nil && t != evaluate.None {
err = s.transition(ctx, m, t, r.StartedAt)
if err = s.transition(ctx, m, t, r.StartedAt); err == nil {
s.pagesChanged(ctx, m.OrgID)
}
}
if err != nil {
// The next result re-evaluates; a missed transition only delays
+2
View File
@@ -54,6 +54,8 @@ func (e *env) startChecker(t *testing.T, token string) (uuid.UUID, func()) {
id := uuid.New()
client := agentapi.NewClient(e.srv.URL, token, id, "test").WithHTTPClient(e.srv.Client())
ctx, cancel := context.WithCancel(context.Background())
// Checkers talk to the API over the stream, as in production.
client.UseStream(ctx, agentapi.StreamOptions{})
done := make(chan struct{})
go func() {
defer close(done)
+1 -1
View File
@@ -182,7 +182,7 @@ func (s *Server) loadCheckerActivity(ctx context.Context, p *principal, instance
a.Siblings = append(a.Siblings, sb.ID)
}
}
monitors, err := q.ListMonitors(ctx)
monitors, err := q.ListMonitors(ctx, p.Org.ID)
if err != nil {
return err
}
+139 -53
View File
@@ -84,12 +84,19 @@ func (s *Server) dashboard(c *gin.Context) {
if !s.dashboardPage(c, &v, data) {
return
}
if err := s.dashboardBars(c.Request.Context(), p, &v, &data); err != nil {
internalError(c, err)
return
}
v.Range = data.rng.Key
var earliest time.Time
for _, m := range data.byID {
if f, ok := data.first[m.ID]; ok && (earliest.IsZero() || f.Before(earliest)) {
earliest = f
}
if err := s.db.Tx(c.Request.Context(), p.scope(), func(q *store.Queries) error {
var err error
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)
for _, m := range data.rows {
@@ -107,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))
}
// 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
// dashboard before linking to all of them.
const groupMonitorsShown = 50
@@ -324,80 +372,96 @@ type monitorData struct {
maint map[uuid.UUID][]store.MaintenanceWindow
rows []web.MonitorRow
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
down map[uuid.UUID][]web.Span
regionOf map[uuid.UUID]store.Region
rng web.TimeRange
now time.Time
// first is when each monitor first reported, from any region;
// firstRegion the same per region.
first map[uuid.UUID]time.Time
firstRegion map[uuid.UUID]map[string]time.Time
// first is when the monitor of a detail page first reported, from
// any region; firstRegion the same per region.
first time.Time
firstRegion map[string]time.Time
// statuses are the organization's own incident statuses.
statuses customStatuses
// usedRegions are the regions the enabled monitors are checked from.
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
// older than two days; younger data is looked up in the raw results.
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) {
first := map[uuid.UUID]time.Time{}
perRegion := map[uuid.UUID]map[string]time.Time{}
note := func(m uuid.UUID, region string, t time.Time) {
if perRegion[m] == nil {
perRegion[m] = map[string]time.Time{}
// older than two days; younger data is looked up exactly.
func loadFirstData(ctx context.Context, q *store.Queries, org, monitor uuid.UUID, now time.Time) (time.Time, map[string]time.Time, error) {
var first time.Time
perRegion := map[string]time.Time{}
note := func(region string, t time.Time) {
if cur, ok := perRegion[region]; !ok || t.Before(cur) {
perRegion[region] = t
}
if cur, ok := perRegion[m][region]; !ok || t.Before(cur) {
perRegion[m][region] = t
}
if cur, ok := first[m]; !ok || t.Before(cur) {
first[m] = t
if first.IsZero() || t.Before(first) {
first = t
}
}
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 {
return nil, nil, err
return first, nil, err
}
for _, r := range daily {
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 {
return nil, nil, err
return first, nil, err
}
for _, r := range recent {
note(r.MonitorID, r.Region, r.First)
note(r.Region, r.First)
}
return first, perRegion, nil
}
// rangeBuckets loads the selected range for all monitors, or one if
// monitor is set.
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) {
// earliestData finds when any monitor of org first reported, for the
// ranges the monitor list offers: to the day if that was over two days
// 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{}
since := now.Add(-rng.Window).Truncate(rng.Bucket)
width := fmt.Sprintf("%d seconds", int(rng.Bucket.Seconds()))
switch rng.Source {
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 {
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
}
return out, err
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 {
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
}
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 {
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
}
@@ -414,9 +478,10 @@ func (d monitorData) slaFor(m store.Monitor, window time.Duration) float64 {
return web.SLA(d.down[m.ID], from, d.now)
}
// loadMonitorData assembles everything the monitor list shows.
// loadMonitorData assembles everything the monitor list shows for rng.
// Incidents are loaded far enough back for every SLA window.
// loadMonitorData assembles the status of every monitor for rng.
// Incidents are loaded far enough back for every SLA window. The bars of
// 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) {
now := time.Now()
d := monitorData{
@@ -438,10 +503,10 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
if groups, err = q.ListGroups(ctx); err != nil {
return err
}
if monitors, err = q.ListMonitors(ctx); err != nil {
if monitors, err = q.ListMonitors(ctx, p.Org.ID); err != nil {
return err
}
if assigned, err = q.AllMonitorRegions(ctx); err != nil {
if assigned, err = q.AllMonitorRegions(ctx, p.Org.ID); err != nil {
return err
}
if regions, err = q.ListVisibleRegions(ctx); err != nil {
@@ -450,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 {
return err
}
if open, err = q.OpenIncidents(ctx); err != nil {
if open, err = q.OpenIncidents(ctx, p.Org.ID); err != nil {
return err
}
if spans, err = q.IncidentsSince(ctx, 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 {
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.statuses, err = loadCustomStatuses(ctx, q); err != nil {
@@ -466,10 +528,7 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
for i, m := range monitors {
ids[i] = m.ID
}
if d.maint, err = maintenanceFor(ctx, q, ids); err != nil {
return err
}
d.buckets, err = rangeBuckets(ctx, q, p.Org.ID, nil, rng, now)
d.maint, err = maintenanceFor(ctx, q, ids)
return err
})
if err != nil {
@@ -581,7 +640,6 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
}
row.Ratio = d.slaFor(m, rng.Window)
row.Uptime = web.SLAText(row.Ratio)
row.Bars = web.UptimeBars(d.buckets[m.ID], now, rng.Bucket, rng.Bars(), rng.Layout)
d.rows = append(d.rows, row)
}
// Problems first, then by name.
@@ -589,6 +647,23 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
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 {
if r, ok := d.regionOf[id]; ok {
return r.Name
@@ -611,6 +686,16 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
if !ok {
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{
Interval: (time.Duration(m.IntervalSeconds) * time.Second).String(),
PingURL: s.detailPingURL(p, d, m),
@@ -618,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),
Maintenance: maintenanceItems(d.maint[id], d.now),
Range: d.rng.Key,
Ranges: rangeOptions(c, d.rng, d.first[id], d.now),
Ranges: rangeOptions(c, d.rng, d.first, d.now),
Uptime90: "–",
}
for _, r := range d.rows {
@@ -626,6 +711,7 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
v.Row = r
}
}
v.Row.Bars = d.bars(id)
var (
daily []store.DailyBucketsRow
recent []store.ListResultsRow
@@ -654,7 +740,7 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
for _, w := range web.SLAWindows {
v.SLAs = append(v.SLAs, web.SLAEntry{
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)
@@ -1248,7 +1334,7 @@ func (s *Server) statusPageEditor(c *gin.Context, p *principal, page web.Page, m
if orgGroups, err = q.ListGroups(ctx); err != nil {
return err
}
if monitors, err = q.ListMonitors(ctx); err != nil {
if monitors, err = q.ListMonitors(ctx, p.Org.ID); err != nil {
return err
}
own, err = q.OrgServesOwnPages(ctx, &p.Org.ID)
@@ -1479,7 +1565,7 @@ func (s *Server) regionHistory(ctx context.Context, p *principal, d monitorData,
Name: d.regionNameString(r),
Bars: web.UptimeBars(byRegion[r], d.now, rng.Bucket, rng.Bars(), rng.Layout),
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 {
h.Uptime = web.PercentPrecise(u)
+11 -1
View File
@@ -74,7 +74,8 @@ func TestPageEditorOffersAddAndRemoveAll(t *testing.T) {
_, region := e.platformChecker(t, uniq("eu-"))
owner := e.browser(t)
owner.signup("o@"+uniq("pa")+".test", uniq("pa-"))
owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": "Shop", "type": "http", "target": "https://shop.test", "interval_seconds": 60, "regions": []string{region}})
_, 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"} {
@@ -82,6 +83,15 @@ func TestPageEditorOffersAddAndRemoveAll(t *testing.T) {
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) {
+2 -2
View File
@@ -472,7 +472,7 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
for _, a := range alertAssignments {
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 {
return err
}
@@ -480,7 +480,7 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
for _, r := range regionRows {
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 {
return err
}
+4 -1
View File
@@ -92,13 +92,16 @@ func (s *Server) recordPassive(ctx context.Context, region string, id, org uuid.
if msg != "" {
row.Error = ptr(truncateValid(msg, 500))
}
var changed []uuid.UUID
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
_, err := q.InsertCheckResults(ctx, []store.InsertCheckResultsParams{row})
var err error
changed, err = insertResults(ctx, q, []store.InsertCheckResultsParams{row})
return err
})
if err != nil {
return err
}
s.pagesChanged(ctx, changed...)
s.evaluateResults(ctx, region,
[]agentapi.Result{{MonitorID: id, ScheduledAt: at, StartedAt: at, OK: ok}},
map[uuid.UUID]store.MonitorsForResultsRow{id: {
+72
View File
@@ -0,0 +1,72 @@
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 {
_, err := store.New(tx).UpsertLatestResults(context.Background(), b)
return err
}); 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")
}
}
+1 -1
View File
@@ -234,7 +234,7 @@ func (s *Server) loadMaintenanceScope(ctx context.Context, p *principal) (mainte
return ms, err
}
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 {
ms.monitors[m.ID] = m
}
+1 -1
View File
@@ -220,7 +220,7 @@ func (s *Server) listMonitors(c *gin.Context) {
for _, a := range assignments {
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 {
return err
}
+7 -2
View File
@@ -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 {
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)`,
org, id, region, uuid.New())
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()); 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
}); err != nil {
t.Fatal(err)
+74
View File
@@ -0,0 +1,74 @@
package api
import (
"context"
"encoding/json"
"slices"
"time"
"github.com/google/uuid"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
)
// regionKey identifies a monitor in one region.
type regionKey struct {
monitor uuid.UUID
region string
}
// 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. It returns the organizations whose status changed somewhere,
// for pagesChanged once the transaction is committed.
func insertResults(ctx context.Context, q *store.Queries, rows []store.InsertCheckResultsParams) ([]uuid.UUID, error) {
if _, err := q.InsertCheckResults(ctx, rows); err != nil {
return nil, 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 nil, err
}
ids := make([]uuid.UUID, len(rows))
for i, r := range rows {
ids[i] = r.MonitorID
}
before, err := q.LatestOK(ctx, ids)
if err != nil {
return nil, err
}
was := make(map[regionKey]bool, len(before))
for _, r := range before {
was[regionKey{r.MonitorID, r.Region}] = r.Ok
}
written, err := q.UpsertLatestResults(ctx, b)
if err != nil {
return nil, err
}
var changed []uuid.UUID
for _, w := range written {
if ok, seen := was[regionKey{w.MonitorID, w.Region}]; (!seen || ok != w.Ok) && !slices.Contains(changed, w.OrgID) {
changed = append(changed, w.OrgID)
}
}
return changed, nil
}
+11 -2
View File
@@ -10,6 +10,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"github.com/redis/go-redis/v9"
"golang.org/x/sync/singleflight"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
@@ -57,6 +58,11 @@ type Server struct {
support *versioned[supportSettings]
// draining, once closed, ends the long polls of checkers.
draining <-chan struct{}
// handler serves the requests agents send over their streams.
handler http.Handler
// snapshots lets status page servers asking for the same page at once
// share one build of it.
snapshots singleflight.Group
}
// Deps are the external resources a Server needs.
@@ -103,6 +109,9 @@ func (s *Server) EndLongPollsOn(ch <-chan struct{}) { s.draining = ch }
// Mount installs session loading, locale resolution and CSRF protection and
// registers the JSON API and the console pages below them.
func (s *Server) Mount(r gin.IRouter) {
if h, ok := r.(http.Handler); ok {
s.handler = h
}
// Agents authenticate with tokens and never carry cookies, so they skip
// the session and CSRF middleware.
s.mountAgentAPI(r)
@@ -151,7 +160,7 @@ func (s *Server) Mount(r gin.IRouter) {
v1.POST("/invitations/:token/accept", auth.Require(), s.acceptInvitation)
v1.POST("/invitations/:token/signup", s.inviteSignup)
org := v1.Group("/org", s.orgAccess())
org := v1.Group("/org", s.orgAccess(), s.announcePages())
org.PUT("/policy", sessionOnly(), can(authz.OrgManage), s.updatePolicy)
org.GET("/export", sessionOnly(), can(authz.OrgManage), s.exportOrg)
org.GET("/legal", can(authz.OrgManage), s.orgListLegal)
@@ -193,7 +202,7 @@ func (s *Server) Mount(r gin.IRouter) {
org.PATCH("/agents/:id", sessionOnly(), can(authz.OrgManage), s.updateOrgAgent)
org.DELETE("/agents/:id", sessionOnly(), can(authz.OrgManage), s.deleteOrgAgent)
admin := v1.Group("/admin", s.requireAdmin())
admin := v1.Group("/admin", s.requireAdmin(), s.announcePages())
admin.GET("/audit", s.listPlatformAudit)
admin.GET("/check-types", s.adminListCheckTypes)
admin.PUT("/check-types", s.adminSetCheckTypes)
+34 -5
View File
@@ -84,10 +84,15 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
for i, m := range listed {
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
}
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
}
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 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 {
return err
}
@@ -105,7 +110,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
return err
}
}
if incidents, err = q.IncidentsForMonitors(ctx, store.IncidentsForMonitorsParams{Ids: ids, Since: ptr(now.Add(-incidentLookback))}); err != nil {
if incidents, err = q.IncidentsForMonitors(ctx, store.IncidentsForMonitorsParams{OrgID: page.OrgID, Ids: ids, Since: ptr(now.Add(-incidentLookback))}); err != nil {
return err
}
incidentIDs := make([]uuid.UUID, len(incidents))
@@ -371,7 +376,7 @@ func (s *Server) agentPage(c *gin.Context) {
fail(c, http.StatusNotFound, "not_found")
return
}
snap, err := s.buildSnapshot(ctx, page)
snap, err := s.sharedSnapshot(ctx, page)
if err != nil {
internalError(c, err)
return
@@ -387,6 +392,30 @@ func (s *Server) agentPage(c *gin.Context) {
c.JSON(http.StatusOK, snap)
}
// snapshotTimeout bounds a shared snapshot build, which outlives the
// request that started it.
const snapshotTimeout = time.Minute
// sharedSnapshot builds page once for all status page servers asking for it
// at the same time, as they do when told that it changed. A server giving
// up does not cancel the build for the others.
func (s *Server) sharedSnapshot(ctx context.Context, page store.StatusPage) (agentapi.PageSnapshot, error) {
ch := s.snapshots.DoChan(page.ID.String(), func() (any, error) {
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), snapshotTimeout)
defer cancel()
return s.buildSnapshot(ctx, page)
})
select {
case <-ctx.Done():
return agentapi.PageSnapshot{}, ctx.Err()
case r := <-ch:
if r.Err != nil {
return agentapi.PageSnapshot{}, r.Err
}
return r.Val.(agentapi.PageSnapshot), nil
}
}
// agentServes finds the published page a status page agent serves at host
// or slug. The platform's servers leave the pages of organizations that
// serve them on their own servers to those, which receive only their own
+357
View File
@@ -0,0 +1,357 @@
package api
import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/url"
"path"
"strings"
"sync"
"time"
"github.com/coder/websocket"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
)
const (
// pagesChannel is the Redis channel announcing organizations whose
// status pages changed; uuid.Nil stands for all of them.
pagesChannel = "uptimesebi:pages-changed"
// streamInFlight bounds the requests of one stream handled at once.
streamInFlight = 128
// streamReadLimit bounds a request read from a stream.
streamReadLimit = 16 << 20
streamPing = 30 * time.Second
// pushFirst and pushEvery pace the page events of one stream: changes
// are collected for pushFirst, and a stream gets at most one event per
// pushEvery, so a flapping monitor does not have its pages rebuilt
// over and over.
pushFirst = time.Second
pushEvery = 5 * time.Second
// drainWait is how long a draining instance lets requests on a stream
// finish before closing it.
drainWait = 5 * time.Second
)
// streamedKey marks requests that arrived over a stream.
type streamedKey struct{}
// pagesChanged announces that status pages of orgs may look different
// now, so status page servers fetch them at once instead of on their next
// refresh. Losing the announcement only delays that.
func (s *Server) pagesChanged(ctx context.Context, orgs ...uuid.UUID) {
if s.rdb == nil {
return
}
for _, org := range orgs {
if err := s.rdb.Publish(ctx, pagesChannel, org.String()).Err(); err != nil {
s.log.WarnContext(ctx, "announcing changed status pages failed", "org", org, "error", err)
return
}
}
}
// announcePages is middleware announcing the changed status pages of the
// request's organization, or of all with no organization, after every
// change made through it.
func (s *Server) announcePages() gin.HandlerFunc {
return func(c *gin.Context) {
c.Next()
if c.Request.Method == http.MethodGet || c.Request.Method == http.MethodHead || c.Writer.Status() >= 400 {
return
}
org := uuid.Nil
if p, ok := c.Get(ctxPrincipal); ok {
org = p.(*principal).Org.ID
}
s.pagesChanged(context.WithoutCancel(c.Request.Context()), org)
}
}
// agentStream serves an agent's stream: its requests run through the
// agent API as if they had come over HTTP, each authenticated again, and
// status page servers get told which of their pages changed.
func (s *Server) agentStream(c *gin.Context) {
up := c.Request
if up.Context().Value(streamedKey{}) != nil || s.handler == nil {
fail(c, http.StatusNotFound, "not_found")
return
}
ws, err := websocket.Accept(c.Writer, up, &websocket.AcceptOptions{CompressionMode: websocket.CompressionContextTakeover})
if err != nil {
// Accept has answered the request.
return
}
ws.SetReadLimit(streamReadLimit)
a := agentOf(c)
ctx, cancel := context.WithCancel(context.WithoutCancel(up.Context()))
defer cancel()
st := &stream{s: s, ws: ws, up: up.Clone(ctx), ctx: ctx, inflight: map[uint64]context.CancelFunc{}}
go st.ping(cancel)
if a.Kind == "statuspage" {
go s.pushPages(ctx, st, a.OrgID)
}
if s.draining != nil {
go func() {
select {
case <-s.draining:
st.drain()
case <-ctx.Done():
}
}()
}
err = st.read()
cancel()
st.wg.Wait()
_ = ws.CloseNow()
s.log.DebugContext(ctx, "agent stream closed", "agent", a.ID, "error", err)
}
// stream is one open agent stream on the API's side.
type stream struct {
s *Server
ws *websocket.Conn
up *http.Request
ctx context.Context
mu sync.Mutex
inflight map[uint64]context.CancelFunc
draining bool
wg sync.WaitGroup
}
func (st *stream) read() error {
for {
_, msg, err := st.ws.Read(st.ctx)
if err != nil {
return err
}
f, body, err := agentapi.DecodeFrame(msg)
if err != nil {
continue
}
st.mu.Lock()
if f.Cancel {
if cancel := st.inflight[f.ID]; cancel != nil {
cancel()
}
st.mu.Unlock()
continue
}
_, dup := st.inflight[f.ID]
refuse := 0
switch {
case st.draining:
refuse = http.StatusServiceUnavailable
case dup || f.ID == 0:
refuse = http.StatusBadRequest
case len(st.inflight) >= streamInFlight:
refuse = http.StatusTooManyRequests
}
if refuse != 0 {
st.mu.Unlock()
st.reply(f.ID, refuse, nil, nil)
continue
}
rctx, cancel := context.WithCancel(context.WithValue(st.ctx, streamedKey{}, true))
st.inflight[f.ID] = cancel
st.wg.Add(1)
st.mu.Unlock()
go func() {
defer st.wg.Done()
defer func() {
st.mu.Lock()
delete(st.inflight, f.ID)
st.mu.Unlock()
cancel()
}()
st.serve(rctx, f, body)
}()
}
}
// serve runs one request through the agent API.
func (st *stream) serve(ctx context.Context, f agentapi.Frame, body []byte) {
u, err := url.Parse(agentapi.Prefix + f.Path)
switch {
case err != nil, path.Clean(u.Path) != u.Path, !strings.HasPrefix(u.Path, agentapi.Prefix+"/"),
u.Path == agentapi.Prefix+agentapi.StreamPath:
st.reply(f.ID, http.StatusBadRequest, nil, nil)
return
}
switch f.Method {
case http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch:
default:
st.reply(f.ID, http.StatusMethodNotAllowed, nil, nil)
return
}
req, err := http.NewRequestWithContext(ctx, f.Method, u.String(), bytes.NewReader(body))
if err != nil {
st.reply(f.ID, http.StatusBadRequest, nil, nil)
return
}
if f.Header != nil {
req.Header = f.Header
}
// Who is asking comes from the stream, never from the request.
for _, k := range []string{"Authorization", agentapi.VersionHeader, agentapi.InstanceHeader, agentapi.ReleaseHeader,
"X-Forwarded-For", "X-Real-Ip", "X-Forwarded-Proto", "X-Forwarded-Host"} {
req.Header.Del(k)
if v := st.up.Header.Values(k); len(v) > 0 {
req.Header[k] = v
}
}
req.Host, req.RemoteAddr, req.RequestURI = st.up.Host, st.up.RemoteAddr, u.RequestURI()
w := &replyWriter{header: http.Header{}}
st.s.handler.ServeHTTP(w, req)
if w.status == 0 {
w.status = http.StatusOK
}
st.reply(f.ID, w.status, w.header, w.body.Bytes())
if w.status == http.StatusUnauthorized {
// The token was revoked: the stream ends with it.
_ = st.ws.Close(websocket.StatusPolicyViolation, "unauthenticated")
}
}
func (st *stream) reply(id uint64, status int, h http.Header, body []byte) {
st.send(agentapi.Frame{ID: id, Status: status, Header: h}, body)
}
func (st *stream) send(f agentapi.Frame, body []byte) {
ctx, cancel := context.WithTimeout(st.ctx, time.Minute)
defer cancel()
if err := st.ws.Write(ctx, websocket.MessageBinary, agentapi.EncodeFrame(f, body)); err != nil {
_ = st.ws.CloseNow()
}
}
// ping closes streams whose agent stopped answering.
func (st *stream) ping(cancel context.CancelFunc) {
tick := time.NewTicker(streamPing)
defer tick.Stop()
for {
select {
case <-st.ctx.Done():
return
case <-tick.C:
ctx, stop := context.WithTimeout(st.ctx, streamPing/2)
err := st.ws.Ping(ctx)
stop()
if err != nil {
cancel()
_ = st.ws.CloseNow()
return
}
}
}
}
// drain refuses new requests, lets those running finish for a while and
// closes the stream, so the agent reconnects to another instance.
func (st *stream) drain() {
st.mu.Lock()
st.draining = true
st.mu.Unlock()
done := make(chan struct{})
go func() { st.wg.Wait(); close(done) }()
select {
case <-done:
case <-time.After(drainWait):
case <-st.ctx.Done():
}
_ = st.ws.Close(websocket.StatusGoingAway, "instance shutting down")
}
// pushPages tells a status page server which of its pages changed, for an
// organization's server only those of its organization.
func (s *Server) pushPages(ctx context.Context, st *stream, agentOrg *uuid.UUID) {
sub := s.rdb.Subscribe(ctx, pagesChannel)
defer func() { _ = sub.Close() }()
msgs := sub.Channel()
changed := map[uuid.UUID]bool{}
var (
due <-chan time.Time
last time.Time
)
for {
select {
case <-ctx.Done():
return
case m, ok := <-msgs:
if !ok {
return
}
org, err := uuid.Parse(m.Payload)
if err != nil || (agentOrg != nil && org != *agentOrg && org != uuid.Nil) {
continue
}
changed[org] = true
if due == nil {
due = time.After(max(pushFirst, pushEvery-time.Since(last)))
}
case <-due:
due, last = nil, time.Now()
refs, err := s.changedPages(ctx, agentOrg, changed)
clear(changed)
if err != nil {
s.log.WarnContext(ctx, "finding changed status pages failed", "error", err)
continue
}
if len(refs) == 0 {
continue
}
body, _ := json.Marshal(agentapi.PagesEvent{Pages: refs})
st.send(agentapi.Frame{Event: agentapi.EventPages}, body)
}
}
}
// changedPages lists the pages the server of agentOrg serves of the
// organizations changed.
func (s *Server) changedPages(ctx context.Context, agentOrg *uuid.UUID, changed map[uuid.UUID]bool) ([]agentapi.PageRef, error) {
var rows []store.ServablePagesRow
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
var err error
rows, err = q.ServablePages(ctx, agentOrg)
return err
})
var refs []agentapi.PageRef
for _, r := range rows {
if changed[uuid.Nil] || changed[r.OrgID] {
refs = append(refs, agentapi.PageRef{Slug: r.Slug, Host: r.Host})
}
}
return refs, err
}
// replyWriter collects a response to send back over a stream.
type replyWriter struct {
header http.Header
status int
body bytes.Buffer
}
// Header implements http.ResponseWriter.
func (w *replyWriter) Header() http.Header { return w.header }
// WriteHeader implements http.ResponseWriter.
func (w *replyWriter) WriteHeader(status int) {
if w.status == 0 {
w.status = status
}
}
// Write implements http.ResponseWriter.
func (w *replyWriter) Write(b []byte) (int, error) {
w.WriteHeader(http.StatusOK)
return w.body.Write(b)
}
+78
View File
@@ -0,0 +1,78 @@
package api_test
import (
"context"
"encoding/json"
"errors"
"slices"
"testing"
"time"
"github.com/jackc/pgx/v5"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
)
func TestAgentStream(t *testing.T) {
e := newEnv(t)
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
owner := e.browser(t)
owner.signup("o@"+uniq("st")+".test", uniq("st-"))
slug := uniq("stream-")
_, body := owner.do("POST", "/api/v1/org/statuspages", map[string]any{"slug": slug, "title": "Before"})
pageID := body["id"].(string)
owner.do("PUT", "/api/v1/org/statuspages/"+pageID, map[string]any{"slug": slug, "title": "Before", "published": true})
sp := e.statuspageClient(t, nil)
events := make(chan agentapi.PagesEvent, 16)
sp.UseStream(ctx, agentapi.StreamOptions{OnEvent: func(event string, body []byte) {
var ev agentapi.PagesEvent
if event == agentapi.EventPages && json.Unmarshal(body, &ev) == nil {
events <- ev
}
}})
waitFor(t, 10*time.Second, "stream to open", sp.Streaming)
snap, err := sp.Page(ctx, "", slug)
if err != nil || snap.Title != "Before" {
t.Fatalf("Page() over the stream = %q, %v", snap.Title, err)
}
if _, err := sp.PageIfChanged(ctx, "", slug, snap.Checksum()); !errors.Is(err, agentapi.ErrNotModified) {
t.Errorf("PageIfChanged(current checksum) over the stream error = %v, want not modified", err)
}
if _, err := sp.Page(ctx, "", uniq("missing-")); !errors.Is(err, agentapi.ErrNotFound) {
t.Errorf("Page(missing) over the stream error = %v, want not found", err)
}
// Editing the page tells the server at once.
owner.do("PUT", "/api/v1/org/statuspages/"+pageID, map[string]any{"slug": slug, "title": "After", "published": true})
deadline := time.After(10 * time.Second)
for told := false; !told; {
select {
case ev := <-events:
told = slices.ContainsFunc(ev.Pages, func(r agentapi.PageRef) bool { return r.Slug == slug })
case <-deadline:
t.Fatal("no event for the edited page")
}
}
if snap, err := sp.Page(ctx, "", slug); err != nil || snap.Title != "After" {
t.Errorf("Page() after the edit = %q, %v", snap.Title, err)
}
// A revoked token ends the stream.
hello, err := sp.Hello(ctx)
if err != nil {
t.Fatal(err)
}
if err := e.asSystem(t, func(tx pgx.Tx) error {
_, err := tx.Exec(ctx, `DELETE FROM agents WHERE id = $1`, hello.AgentID)
return err
}); err != nil {
t.Fatal(err)
}
if _, err := sp.Hello(ctx); !errors.Is(err, agentapi.ErrUnauthorized) {
t.Errorf("Hello() with a revoked token error = %v, want unauthorized", err)
}
waitFor(t, 10*time.Second, "stream to close", func() bool { return !sp.Streaming() })
}
+3 -1
View File
@@ -93,7 +93,9 @@ func TestRecoveryIsLogged(t *testing.T) {
time.Sleep(50 * time.Millisecond)
}
cancel()
<-done
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) {
+1
View File
@@ -1305,6 +1305,7 @@
"pages.label": "Öffentlicher Name",
"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",
+1
View File
@@ -1305,6 +1305,7 @@
"pages.label": "Public name",
"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",
@@ -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;
+50 -8
View File
@@ -49,6 +49,8 @@ const (
// without asking the API again.
missFor = time.Minute
maxMissing = 10_000
// refreshTimeout bounds fetching one page.
refreshTimeout = 30 * time.Second
// unknownPerSecond bounds the lookups of hosts and slugs that are
// neither cached nor known to be missing, so a flood of made-up names
// is not passed on to the API. Every page the API lists is cached by
@@ -79,6 +81,9 @@ type Server struct {
mu sync.Mutex
cache map[string]entry
refreshing map[string]bool
// again holds pages that changed while being refreshed, which are
// fetched once more.
again map[string]bool
// visited holds when each cached page was last visited.
visited map[string]time.Time
// missing holds when a key was last found to have no page.
@@ -118,7 +123,7 @@ type Options struct {
func New(src Source, catalog *i18n.Catalog, log *slog.Logger, o Options) (*Server, error) {
s := &Server{
src: src, catalog: catalog, log: log, ownHosts: map[string]bool{}, dir: o.CacheDir,
now: time.Now, cache: map[string]entry{}, refreshing: map[string]bool{}, visited: map[string]time.Time{},
now: time.Now, cache: map[string]entry{}, refreshing: map[string]bool{}, again: map[string]bool{}, visited: map[string]time.Time{},
missing: map[string]time.Time{},
}
for _, h := range o.Hosts {
@@ -419,7 +424,8 @@ func (s *Server) fetch(ctx context.Context, key, host, slug string) (entry, bool
return e, true
}
// refresh fetches key unless another refresh of it is running.
// refresh fetches key unless another refresh of it is running, and once
// more if it changed meanwhile.
func (s *Server) refresh(ctx context.Context, key, host, slug string) {
s.mu.Lock()
if s.refreshing[key] {
@@ -428,14 +434,50 @@ func (s *Server) refresh(ctx context.Context, key, host, slug string) {
}
s.refreshing[key] = true
s.mu.Unlock()
defer func() {
for {
fctx, cancel := context.WithTimeout(ctx, refreshTimeout)
s.fetch(fctx, key, host, slug)
cancel()
s.mu.Lock()
delete(s.refreshing, key)
again := s.again[key] && ctx.Err() == nil
delete(s.again, key)
if !again {
delete(s.refreshing, key)
s.mu.Unlock()
return
}
s.mu.Unlock()
}()
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
s.fetch(ctx, key, host, slug)
}
}
// OnEvent handles the events the API sends over its stream: pages that
// changed are fetched at once instead of on their next refresh.
func (s *Server) OnEvent(event string, body []byte) {
if event != agentapi.EventPages {
return
}
var ev agentapi.PagesEvent
if err := json.Unmarshal(body, &ev); err != nil {
s.log.Warn("ignoring unreadable event", "event", event, "error", err)
return
}
for _, r := range ev.Pages {
s.changed("slug:"+r.Slug, "", r.Slug)
if r.Host != "" {
s.changed("host:"+r.Host, r.Host, "")
}
}
}
func (s *Server) changed(key, host, slug string) {
s.mu.Lock()
if s.refreshing[key] {
s.again[key] = true
s.mu.Unlock()
return
}
s.mu.Unlock()
s.background.Go(func() { s.refresh(context.Background(), key, host, slug) })
}
// Wait returns once the background refreshes started by visits are done.
+32
View File
@@ -555,3 +555,35 @@ func TestRefreshSkipsUnchangedPages(t *testing.T) {
t.Errorf("after a change: renamed %t, unchanged answers %d, want 3", strings.Contains(body, "Renamed"), unchanged)
}
}
// Pages the API says changed are fetched at once, and once more when they
// change during that fetch.
func TestEventsRefreshPagesAtOnce(t *testing.T) {
now := time.Now()
src := newSource()
h := newHarness(t, src, t.TempDir(), &now)
if code, body := h.get("status.example.test", "/acme"); code != 200 || !strings.Contains(body, "Acme status") {
t.Fatalf("first GET = %d", code)
}
src.set(func(f *fakeSource) {
f.pages["|acme"] = agentapi.PageSnapshot{Title: "Acme renamed", Status: agentapi.PageOperational}
f.delay = 200 * time.Millisecond
f.calls = 0
})
event := []byte(`{"pages":[{"slug":"acme"}]}`)
h.srv.OnEvent(agentapi.EventPages, event)
time.Sleep(50 * time.Millisecond)
// Arrives while the first fetch runs.
h.srv.OnEvent(agentapi.EventPages, event)
h.srv.OnEvent("unknown", nil)
h.srv.Wait()
if _, body := h.get("status.example.test", "/acme"); !strings.Contains(body, "Acme renamed") {
t.Error("page not refreshed after the event")
}
src.mu.Lock()
calls := src.calls
src.mu.Unlock()
if calls != 2 {
t.Errorf("fetches = %d, want 2: one for the event, one for the change during it", calls)
}
}
+74 -74
View File
@@ -124,22 +124,65 @@ func (q *Queries) DailyBucketsForMonitors(ctx context.Context, arg DailyBucketsF
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
SELECT monitor_id, region, min(bucket)::timestamptz AS first
FROM check_results_1d
WHERE org_id = $1
WHERE org_id = $1 AND monitor_id = $2
GROUP BY 1, 2
`
type FirstDataDailyParams struct {
OrgID uuid.UUID
MonitorID uuid.UUID
}
type FirstDataDailyRow struct {
MonitorID uuid.UUID
Region string
First time.Time
}
// When each monitor and region first reported, to the day.
func (q *Queries) FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstDataDailyRow, error) {
rows, err := q.db.Query(ctx, firstDataDaily, orgID)
// When each region of a monitor first reported, to the day.
func (q *Queries) FirstDataDaily(ctx context.Context, arg FirstDataDailyParams) ([]FirstDataDailyRow, error) {
rows, err := q.db.Query(ctx, firstDataDaily, arg.OrgID, arg.MonitorID)
if err != nil {
return nil, err
}
@@ -161,13 +204,14 @@ func (q *Queries) FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstD
const firstDataRecent = `-- name: FirstDataRecent :many
SELECT monitor_id, region, min(time)::timestamptz AS first
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
`
type FirstDataRecentParams struct {
OrgID uuid.UUID
Time time.Time
OrgID uuid.UUID
MonitorID uuid.UUID
Time time.Time
}
type FirstDataRecentRow struct {
@@ -176,10 +220,10 @@ type FirstDataRecentRow struct {
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.
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 {
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
FROM check_results_1h
WHERE org_id = $1 AND bucket >= $2
AND ($3::uuid[] IS NULL OR monitor_id = ANY ($3::uuid[]))
GROUP BY monitor_id, bucket
ORDER BY monitor_id, bucket
`
@@ -210,6 +255,7 @@ ORDER BY monitor_id, bucket
type HourlyBucketsParams struct {
OrgID uuid.UUID
Bucket interface{}
Ids []uuid.UUID
}
type HourlyBucketsRow struct {
@@ -222,7 +268,7 @@ type HourlyBucketsRow struct {
// Per monitor and hour since $2, across all regions.
func (q *Queries) HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error) {
rows, err := q.db.Query(ctx, hourlyBuckets, arg.OrgID, arg.Bucket)
rows, err := q.db.Query(ctx, hourlyBuckets, arg.OrgID, arg.Bucket, arg.Ids)
if err != nil {
return nil, err
}
@@ -259,52 +305,6 @@ type InsertCheckResultsParams struct {
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
SELECT DISTINCT ON (region) region, ok, error
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
FROM check_results
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
ORDER BY 1, 2
`
type RangeBucketsParams struct {
OrgID uuid.UUID
Width string
Since time.Time
MonitorID *uuid.UUID
OrgID uuid.UUID
Width string
Since time.Time
Ids []uuid.UUID
}
type RangeBucketsRow struct {
@@ -451,7 +451,7 @@ func (q *Queries) RangeBuckets(ctx context.Context, arg RangeBucketsParams) ([]R
arg.OrgID,
arg.Width,
arg.Since,
arg.MonitorID,
arg.Ids,
)
if err != nil {
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
FROM check_results_1d
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
ORDER BY 1, 2
`
type RangeBucketsDailyParams struct {
OrgID uuid.UUID
Width string
Since interface{}
MonitorID *uuid.UUID
OrgID uuid.UUID
Width string
Since interface{}
Ids []uuid.UUID
}
type RangeBucketsDailyRow struct {
@@ -509,7 +509,7 @@ func (q *Queries) RangeBucketsDaily(ctx context.Context, arg RangeBucketsDailyPa
arg.OrgID,
arg.Width,
arg.Since,
arg.MonitorID,
arg.Ids,
)
if err != nil {
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
FROM check_results_1h
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
ORDER BY 1, 2
`
type RangeBucketsHourlyParams struct {
OrgID uuid.UUID
Width string
Since interface{}
MonitorID *uuid.UUID
OrgID uuid.UUID
Width string
Since interface{}
Ids []uuid.UUID
}
type RangeBucketsHourlyRow struct {
@@ -567,7 +567,7 @@ func (q *Queries) RangeBucketsHourly(ctx context.Context, arg RangeBucketsHourly
arg.OrgID,
arg.Width,
arg.Since,
arg.MonitorID,
arg.Ids,
)
if err != nil {
return nil, err
+15 -9
View File
@@ -271,18 +271,19 @@ func (q *Queries) GetIncident(ctx context.Context, id uuid.UUID) (GetIncidentRow
const incidentsForMonitors = `-- name: IncidentsForMonitors :many
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id FROM incidents
WHERE monitor_id = ANY ($1::uuid[]) AND (resolved_at IS NULL OR resolved_at > $2)
WHERE org_id = $1 AND monitor_id = ANY ($2::uuid[]) AND (resolved_at IS NULL OR resolved_at > $3)
ORDER BY started_at DESC
LIMIT 50
`
type IncidentsForMonitorsParams struct {
OrgID uuid.UUID
Ids []uuid.UUID
Since *time.Time
}
func (q *Queries) IncidentsForMonitors(ctx context.Context, arg IncidentsForMonitorsParams) ([]Incident, error) {
rows, err := q.db.Query(ctx, incidentsForMonitors, arg.Ids, arg.Since)
rows, err := q.db.Query(ctx, incidentsForMonitors, arg.OrgID, arg.Ids, arg.Since)
if err != nil {
return nil, err
}
@@ -313,18 +314,23 @@ func (q *Queries) IncidentsForMonitors(ctx context.Context, arg IncidentsForMoni
const incidentsSince = `-- name: IncidentsSince :many
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 {
MonitorID uuid.UUID
StartedAt time.Time
ResolvedAt *time.Time
}
// Incidents overlapping the time since $1, for SLA calculation.
func (q *Queries) IncidentsSince(ctx context.Context, resolvedAt *time.Time) ([]IncidentsSinceRow, error) {
rows, err := q.db.Query(ctx, incidentsSince, resolvedAt)
// Incidents overlapping the time since $2, for SLA calculation.
func (q *Queries) IncidentsSince(ctx context.Context, arg IncidentsSinceParams) ([]IncidentsSinceRow, error) {
rows, err := q.db.Query(ctx, incidentsSince, arg.OrgID, arg.ResolvedAt)
if err != nil {
return nil, err
}
@@ -672,11 +678,11 @@ func (q *Queries) OpenIncident(ctx context.Context, arg OpenIncidentParams) (Inc
}
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) {
rows, err := q.db.Query(ctx, openIncidents)
func (q *Queries) OpenIncidents(ctx context.Context, orgID uuid.UUID) ([]Incident, error) {
rows, err := q.db.Query(ctx, openIncidents, orgID)
if err != nil {
return nil, err
}
+190
View File
@@ -0,0 +1,190 @@
// 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 latestOK = `-- name: LatestOK :many
SELECT monitor_id, region, ok FROM latest_results WHERE monitor_id = ANY ($1::uuid[])
`
type LatestOKRow struct {
MonitorID uuid.UUID
Region string
Ok bool
}
// latest_results holds the newest check result per monitor and region
// (see migration 00055) and has row-level security.
// Whether the newest result of each region of the monitors ids succeeded.
func (q *Queries) LatestOK(ctx context.Context, ids []uuid.UUID) ([]LatestOKRow, error) {
rows, err := q.db.Query(ctx, latestOK, ids)
if err != nil {
return nil, err
}
defer rows.Close()
items := []LatestOKRow{}
for rows.Next() {
var i LatestOKRow
if err := rows.Scan(&i.MonitorID, &i.Region, &i.Ok); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
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 :many
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
RETURNING monitor_id, region, org_id, ok
`
type UpsertLatestResultsRow struct {
MonitorID uuid.UUID
Region string
OrgID uuid.UUID
Ok bool
}
// Keeps the newest of results, a JSON array, per monitor and
// region; results arriving late do not replace newer ones. It returns the
// rows it wrote.
func (q *Queries) UpsertLatestResults(ctx context.Context, results []byte) ([]UpsertLatestResultsRow, error) {
rows, err := q.db.Query(ctx, upsertLatestResults, results)
if err != nil {
return nil, err
}
defer rows.Close()
items := []UpsertLatestResultsRow{}
for rows.Next() {
var i UpsertLatestResultsRow
if err := rows.Scan(
&i.MonitorID,
&i.Region,
&i.OrgID,
&i.Ok,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
+11
View File
@@ -197,6 +197,17 @@ type Invitation struct {
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 {
UserID uuid.UUID
Kind string
+7 -6
View File
@@ -27,7 +27,7 @@ func (q *Queries) AddMonitorRegion(ctx context.Context, arg AddMonitorRegionPara
}
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 {
@@ -35,8 +35,8 @@ type AllMonitorRegionsRow struct {
RegionID uuid.UUID
}
func (q *Queries) AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow, error) {
rows, err := q.db.Query(ctx, allMonitorRegions)
func (q *Queries) AllMonitorRegions(ctx context.Context, orgID uuid.UUID) ([]AllMonitorRegionsRow, error) {
rows, err := q.db.Query(ctx, allMonitorRegions, orgID)
if err != nil {
return nil, err
}
@@ -192,11 +192,12 @@ func (q *Queries) ListEnabledMonitorsForSchedule(ctx context.Context) ([]ListEna
}
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, position 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) {
rows, err := q.db.Query(ctx, listMonitors)
// The org filter, though row security implies it, lets the index be used.
func (q *Queries) ListMonitors(ctx context.Context, orgID uuid.UUID) ([]Monitor, error) {
rows, err := q.db.Query(ctx, listMonitors, orgID)
if err != nil {
return nil, err
}
+26 -9
View File
@@ -39,7 +39,7 @@ type Querier interface {
// System scope: the receiver a webhook token belongs to.
AlertmanagerReceiverByHash(ctx context.Context, tokenHash []byte) (AlertmanagerReceiverByHashRow, 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)
// How much one instance checked for the organization in the last hour.
CheckerStats(ctx context.Context, arg CheckerStatsParams) (CheckerStatsRow, error)
@@ -124,6 +124,12 @@ type Querier interface {
// for two days, after which only the verify button tries again. A verified
// one is checked daily, hourly once its record went missing.
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)
EnableTOTP(ctx context.Context, arg EnableTOTPParams) error
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
@@ -139,9 +145,9 @@ type Querier interface {
// FiringAlerts newest first, a page from a keyset cursor (see paging.go)
// whose string key is the fingerprint.
FiringAlertsPage(ctx context.Context, arg FiringAlertsPageParams) ([]FiringAlertsPageRow, error)
// When each monitor and region first reported, to the day.
FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstDataDailyRow, error)
// When each monitor and region first reported since $2, exactly. Used for
// When each region of a monitor first reported, to the day.
FirstDataDaily(ctx context.Context, arg FirstDataDailyParams) ([]FirstDataDailyRow, error)
// When each region of a monitor first reported since $3, exactly. Used for
// data younger than the daily aggregate's resolution.
FirstDataRecent(ctx context.Context, arg FirstDataRecentParams) ([]FirstDataRecentRow, error)
// Keeps organization and platform entries readable as "deleted user" but
@@ -184,8 +190,8 @@ type Querier interface {
// Per monitor and hour since $2, across all regions.
HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error)
IncidentsForMonitors(ctx context.Context, arg IncidentsForMonitorsParams) ([]Incident, error)
// Incidents overlapping the time since $1, for SLA calculation.
IncidentsSince(ctx context.Context, resolvedAt *time.Time) ([]IncidentsSinceRow, error)
// Incidents overlapping the time since $2, for SLA calculation.
IncidentsSince(ctx context.Context, arg IncidentsSinceParams) ([]IncidentsSinceRow, error)
InsertAuditEvent(ctx context.Context, arg InsertAuditEventParams) error
// check_results and its aggregates have no row-level security (see
// migration 00013). Every query here must filter by org_id.
@@ -195,10 +201,16 @@ type Querier interface {
InvitationOrg(ctx context.Context, hash []byte) (uuid.UUID, error)
IsMember(ctx context.Context, arg IsMemberParams) (bool, error)
LastFailureEvidence(ctx context.Context, arg LastFailureEvidenceParams) (LastFailureEvidenceRow, error)
// latest_results holds the newest check result per monitor and region
// (see migration 00055) and has row-level security.
// Whether the newest result of each region of the monitors ids succeeded.
LatestOK(ctx context.Context, ids []uuid.UUID) ([]LatestOKRow, 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)
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)
// The organization's documents and the platform's, organization first.
LegalDocuments(ctx context.Context, orgID *uuid.UUID) ([]LegalDocument, error)
@@ -229,7 +241,8 @@ type Querier interface {
// Latest start first, a page from a keyset cursor (see paging.go).
ListMaintenancePage(ctx context.Context, arg ListMaintenancePageParams) ([]MaintenanceWindow, 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).
ListMonitorsPage(ctx context.Context, arg ListMonitorsPageParams) ([]Monitor, error)
ListOrgMembers(ctx context.Context, orgID uuid.UUID) ([]ListOrgMembersRow, error)
@@ -291,7 +304,7 @@ type Querier interface {
// System scope.
NotificationDetails(ctx context.Context, ids []uuid.UUID) ([]NotificationDetailsRow, error)
OpenIncident(ctx context.Context, arg OpenIncidentParams) (Incident, error)
OpenIncidents(ctx context.Context) ([]Incident, error)
OpenIncidents(ctx context.Context, orgID uuid.UUID) ([]Incident, error)
OrgAssignmentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgAssignmentsExportRow, error)
OrgAuditExport(ctx context.Context, orgID uuid.UUID) ([]OrgAuditExportRow, error)
OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDailyStatsRow, error)
@@ -417,6 +430,10 @@ type Querier interface {
UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error)
UpdateStatusPageGroup(ctx context.Context, arg UpdateStatusPageGroupParams) (StatusPageGroup, error)
UpsertAlertmanagerAlert(ctx context.Context, arg UpsertAlertmanagerAlertParams) error
// Keeps the newest of results, a JSON array, per monitor and
// region; results arriving late do not replace newer ones. It returns the
// rows it wrote.
UpsertLatestResults(ctx context.Context, results []byte) ([]UpsertLatestResultsRow, error)
// A new version starts when the document is created or when the edit asks
// everyone to accept it again.
UpsertLegalDocument(ctx context.Context, arg UpsertLegalDocumentParams) error
+25 -14
View File
@@ -5,13 +5,6 @@
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);
-- 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
-- A monitor's results newest first, a page from a keyset cursor (see
-- 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
FROM check_results_1h
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
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
FROM check_results
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
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
FROM check_results_1h
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
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
FROM check_results_1d
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
ORDER BY 1, 2;
@@ -125,18 +119,35 @@ GROUP BY 1, 2
ORDER BY 1, 2;
-- 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
FROM check_results_1d
WHERE org_id = $1
WHERE org_id = $1 AND monitor_id = $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
-- 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.
SELECT monitor_id, region, min(time)::timestamptz AS first
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;
-- name: ResultsByChecker :many
+4 -4
View File
@@ -84,18 +84,18 @@ SELECT * FROM notification_channels ORDER BY name;
DELETE FROM notification_channels WHERE id = $1;
-- 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
SELECT * FROM incidents
WHERE monitor_id = ANY (sqlc.arg(ids)::uuid[]) AND (resolved_at IS NULL OR resolved_at > sqlc.arg(since))
WHERE org_id = sqlc.arg(org_id) AND monitor_id = ANY (sqlc.arg(ids)::uuid[]) AND (resolved_at IS NULL OR resolved_at > sqlc.arg(since))
ORDER BY started_at DESC
LIMIT 50;
-- 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
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
SELECT i.*, m.name AS monitor_name, m.group_id AS monitor_group_id
+33
View File
@@ -0,0 +1,33 @@
-- latest_results holds the newest check result per monitor and region
-- (see migration 00055) and has row-level security.
-- name: LatestOK :many
-- Whether the newest result of each region of the monitors ids succeeded.
SELECT monitor_id, region, ok FROM latest_results WHERE monitor_id = ANY (sqlc.arg(ids)::uuid[]);
-- name: UpsertLatestResults :many
-- Keeps the newest of results, a JSON array, per monitor and
-- region; results arriving late do not replace newer ones. It returns the
-- rows it wrote.
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(results)::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
RETURNING monitor_id, region, org_id, ok;
-- 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';
+3 -2
View File
@@ -16,13 +16,14 @@ DELETE FROM monitors WHERE id = $1;
SELECT * FROM monitors WHERE id = $1;
-- 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
SELECT region_id FROM monitor_regions WHERE monitor_id = $1 ORDER BY region_id;
-- 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
DELETE FROM monitor_regions WHERE monitor_id = $1;
+1 -1
View File
@@ -146,7 +146,7 @@ WHERE published AND suspended_at IS NULL
-- System scope: the published pages a status page server serves, those
-- of agent_org for an organization's server; the platform's leave the
-- pages of organizations serving their own.
SELECT p.slug, COALESCE(CASE WHEN p.domain_verified_at IS NOT NULL THEN p.custom_domain END, '')::text AS host
SELECT p.slug, COALESCE(CASE WHEN p.domain_verified_at IS NOT NULL THEN p.custom_domain END, '')::text AS host, p.org_id
FROM status_pages p
JOIN orgs o ON o.id = p.org_id
WHERE p.published AND p.suspended_at IS NULL AND o.suspended_at IS NULL
+5 -4
View File
@@ -470,7 +470,7 @@ func (q *Queries) ReparentStatusPageGroupMonitors(ctx context.Context, arg Repar
}
const servablePages = `-- name: ServablePages :many
SELECT p.slug, COALESCE(CASE WHEN p.domain_verified_at IS NOT NULL THEN p.custom_domain END, '')::text AS host
SELECT p.slug, COALESCE(CASE WHEN p.domain_verified_at IS NOT NULL THEN p.custom_domain END, '')::text AS host, p.org_id
FROM status_pages p
JOIN orgs o ON o.id = p.org_id
WHERE p.published AND p.suspended_at IS NULL AND o.suspended_at IS NULL
@@ -482,8 +482,9 @@ ORDER BY p.slug
`
type ServablePagesRow struct {
Slug string
Host string
Slug string
Host string
OrgID uuid.UUID
}
// System scope: the published pages a status page server serves, those
@@ -498,7 +499,7 @@ func (q *Queries) ServablePages(ctx context.Context, agentOrg *uuid.UUID) ([]Ser
items := []ServablePagesRow{}
for rows.Next() {
var i ServablePagesRow
if err := rows.Scan(&i.Slug, &i.Host); err != nil {
if err := rows.Scan(&i.Slug, &i.Host, &i.OrgID); err != nil {
return nil, err
}
items = append(items, i)
+27 -1
View File
@@ -235,12 +235,15 @@
await saveOrder(item.closest("[data-sortable]"));
return;
}
// Ticks or clears every checkbox named by data-check-all in its form.
// 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;
}
@@ -326,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.
document.addEventListener("change", (ev) => {
const sel = ev.target.closest("[data-type-select]");
+30 -11
View File
@@ -283,7 +283,13 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
<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 {
<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 }/>
@@ -294,16 +300,11 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
}
</span>
<input type="hidden" data-field="monitor_id" value={ m.ID }/>
<span></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>
// Organizations may have thousands of monitors: only those on
// the page carry their fields, the others get them when ticked.
if m.Included {
@pageMonitorFields(e, m)
}
</li>
}
</ul>
@@ -379,3 +380,21 @@ templ dnsRecordList(kind, name, value 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>
}
// 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>
}
+403 -323
View File
@@ -1532,187 +1532,139 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 127, "<ul class=\"mb-4 divide-y divide-rule border-y border-rule text-sm\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, m := range e.Monitors {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 128, "<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\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if m.Included {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 129, " checked")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 130, " class=\"accent-ink\" aria-label=\"")
if len(e.Monitors) > monitorFilterFrom {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 127, "<input type=\"search\" data-filter-rows=\"#page-monitors\" placeholder=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var79 string
templ_7745c5c3_Var79, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Name).Resolve(ctx)
templ_7745c5c3_Var79, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "pages.monitors_filter")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 289, Col: 115}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 287, Col: 112}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var79)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 131, "\"> <span class=\"flex flex-wrap items-baseline gap-x-2\"><span>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 128, "\" aria-label=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var80 string
templ_7745c5c3_Var80, templ_7745c5c3_Err = templ.JoinStringErrs(m.Name)
templ_7745c5c3_Var80, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "pages.monitors_filter")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 291, Col: 24}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 287, Col: 164}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var80))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var80)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 132, "</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if m.MonitorGroupPath != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 133, "<span class=\"font-mono text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var81 string
templ_7745c5c3_Var81, templ_7745c5c3_Err = templ.JoinStringErrs(m.MonitorGroupPath)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 293, Col: 74}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var81))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 134, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 135, "</span> <input type=\"hidden\" data-field=\"monitor_id\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var82 string
templ_7745c5c3_Var82, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.ID).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 296, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var82)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 136, "\"> <span></span> <span class=\"flex gap-2\"><select data-field=\"group_id\" data-nullable aria-label=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var83 string
templ_7745c5c3_Var83, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "pages.group")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 299, Col: 93}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var83)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 137, "\" class=\"w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink\"><option value=\"\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var84 string
templ_7745c5c3_Var84, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.no_group"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 300, Col: 59}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var84))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 138, "</option> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, opt := range e.Groups {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 139, "<option value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var85 string
templ_7745c5c3_Var85, templ_7745c5c3_Err = templruntime.NewAttributeExpression(opt.ID).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 302, Col: 34}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var85)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 140, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if opt.ID == m.GroupID {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 141, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 142, ">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var86 string
templ_7745c5c3_Var86, templ_7745c5c3_Err = templ.JoinStringErrs(opt.Label)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 302, Col: 82}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var86))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 143, "</option>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 144, "</select> <input data-field=\"label\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var87 string
templ_7745c5c3_Var87, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Label).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 305, Col: 51}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var87)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 145, "\" placeholder=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var88 string
templ_7745c5c3_Var88, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "pages.label")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 305, Col: 94}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var88)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 146, "\" class=\"w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink\"></span></li>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 129, "\" class=\"mb-2 w-full border border-rule bg-transparent px-2 py-1 text-sm outline-none focus:border-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 147, "</ul>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 130, "<template data-row-fields>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = pageMonitorFields(e, PageMonitorOption{}).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 131, "</template><ul id=\"page-monitors\" class=\"mb-4 divide-y divide-rule border-y border-rule text-sm\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, m := range e.Monitors {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 132, "<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\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if m.Included {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 133, " checked")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 134, " class=\"accent-ink\" aria-label=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var81 string
templ_7745c5c3_Var81, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Name).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 295, Col: 115}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var81)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 135, "\"> <span class=\"flex flex-wrap items-baseline gap-x-2\"><span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var82 string
templ_7745c5c3_Var82, templ_7745c5c3_Err = templ.JoinStringErrs(m.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 297, Col: 24}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var82))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 136, "</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if m.MonitorGroupPath != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 137, "<span class=\"font-mono text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var83 string
templ_7745c5c3_Var83, templ_7745c5c3_Err = templ.JoinStringErrs(m.MonitorGroupPath)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 299, Col: 74}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var83))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 138, "</span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 139, "</span> <input type=\"hidden\" data-field=\"monitor_id\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var84 string
templ_7745c5c3_Var84, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.ID).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 302, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var84)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 140, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if m.Included {
templ_7745c5c3_Err = pageMonitorFields(e, m).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 141, "</li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 142, "</ul>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -1720,7 +1672,7 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 148, "</form></section><section>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 143, "</form></section><section>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -1728,46 +1680,46 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 149, "<p class=\"mb-4 text-sm text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 144, "<p class=\"mb-4 text-sm text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var89 string
templ_7745c5c3_Var89, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_intro"))
var templ_7745c5c3_Var85 string
templ_7745c5c3_Var85, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_intro"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 315, Col: 75}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 316, Col: 75}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var89))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var85))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 150, "</p><form data-api=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 145, "</p><form data-api=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var90 string
templ_7745c5c3_Var90, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/statuspages/" + e.ID + "/domain").Resolve(ctx)
var templ_7745c5c3_Var86 string
templ_7745c5c3_Var86, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/statuspages/" + e.ID + "/domain").Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 316, Col: 60}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 317, Col: 60}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var90)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var86)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 151, "\" data-method=\"put\" data-next=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 146, "\" data-method=\"put\" data-next=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var91 string
templ_7745c5c3_Var91, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/statuspages/" + e.ID).Resolve(ctx)
var templ_7745c5c3_Var87 string
templ_7745c5c3_Var87, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/statuspages/" + e.ID).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 316, Col: 115}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 317, Col: 115}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var91)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var87)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 152, "\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 147, "\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -1783,108 +1735,108 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 153, "</form>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 148, "</form>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if e.Domain != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 154, "<div class=\"mt-6 space-y-4 border border-rule p-4 text-sm\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 149, "<div class=\"mt-6 space-y-4 border border-rule p-4 text-sm\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if e.DomainVerified {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 155, "<p><span class=\"text-up\">●</span> ")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 150, "<p><span class=\"text-up\">●</span> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
switch e.VerifiedBy {
case "cname":
var templ_7745c5c3_Var92 string
templ_7745c5c3_Var92, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_verified_by_cname"))
var templ_7745c5c3_Var88 string
templ_7745c5c3_Var88, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_verified_by_cname"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 328, Col: 58}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 329, Col: 58}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var88))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
case "txt":
var templ_7745c5c3_Var89 string
templ_7745c5c3_Var89, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_verified_by_txt"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 331, Col: 56}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var89))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
default:
var templ_7745c5c3_Var90 string
templ_7745c5c3_Var90, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_verified"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 333, Col: 54}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var90))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 151, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if e.MissingSince != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 152, "<p class=\"border-l-2 border-down pl-3\" role=\"alert\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var91 string
templ_7745c5c3_Var91, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_missing", "Since", e.MissingSince, "Date", e.SwitchOffAt))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 337, Col: 146}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var91))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 153, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else if e.VerifiedBy != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 154, "<p class=\"text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var92 string
templ_7745c5c3_Var92, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_keep"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 339, Col: 73}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var92))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
case "txt":
var templ_7745c5c3_Var93 string
templ_7745c5c3_Var93, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_verified_by_txt"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 330, Col: 56}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var93))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
default:
var templ_7745c5c3_Var94 string
templ_7745c5c3_Var94, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_verified"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 332, Col: 54}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var94))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 156, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if e.MissingSince != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 157, "<p class=\"border-l-2 border-down pl-3\" role=\"alert\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var95 string
templ_7745c5c3_Var95, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_missing", "Since", e.MissingSince, "Date", e.SwitchOffAt))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 336, Col: 146}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var95))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 158, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else if e.VerifiedBy != "" {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 159, "<p class=\"text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var96 string
templ_7745c5c3_Var96, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_keep"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 338, Col: 73}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var96))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 160, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 155, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
} else if e.CNAMEValue != "" && !e.OwnServers {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 161, "<p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 156, "<p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var97 string
templ_7745c5c3_Var97, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_cname_step"))
var templ_7745c5c3_Var93 string
templ_7745c5c3_Var93, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_cname_step"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 341, Col: 51}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 342, Col: 51}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var97))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var93))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 162, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 157, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -1896,33 +1848,33 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 163, "<details><summary class=\"cursor-pointer text-xs text-muted hover:text-ink\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 158, "<details><summary class=\"cursor-pointer text-xs text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var98 string
templ_7745c5c3_Var98, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_alt_summary"))
var templ_7745c5c3_Var94 string
templ_7745c5c3_Var94, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_alt_summary"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 345, Col: 116}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 346, Col: 116}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var98))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var94))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 164, "</summary><p class=\"mb-3 mt-3 text-xs\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 159, "</summary><p class=\"mb-3 mt-3 text-xs\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var99 string
templ_7745c5c3_Var99, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_alt", "Target", e.CNAMEValue))
var templ_7745c5c3_Var95 string
templ_7745c5c3_Var95, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_alt", "Target", e.CNAMEValue))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 346, Col: 95}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 347, Col: 95}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var99))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var95))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 165, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 160, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -1934,25 +1886,25 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 166, "</details>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 161, "</details>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 167, "<p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 162, "<p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var100 string
templ_7745c5c3_Var100, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_verify"))
var templ_7745c5c3_Var96 string
templ_7745c5c3_Var96, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_verify"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 351, Col: 52}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 352, Col: 52}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var100))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var96))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 168, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 163, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -1965,79 +1917,79 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
return templ_7745c5c3_Err
}
if e.OwnServers {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 169, "<p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 164, "<p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var101 string
templ_7745c5c3_Var101, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_cname_own"))
var templ_7745c5c3_Var97 string
templ_7745c5c3_Var97, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_cname_own"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 355, Col: 56}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 356, Col: 56}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var101))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var97))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 170, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 165, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 171, "<p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 166, "<p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var102 string
templ_7745c5c3_Var102, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_cname_unknown"))
var templ_7745c5c3_Var98 string
templ_7745c5c3_Var98, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_cname_unknown"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 357, Col: 60}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 358, Col: 60}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var102))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var98))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 172, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 167, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 173, " <p class=\"text-xs text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 168, " <p class=\"text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var103 string
templ_7745c5c3_Var103, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_apex"))
var templ_7745c5c3_Var99 string
templ_7745c5c3_Var99, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_apex"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 359, Col: 72}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 360, Col: 72}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var103))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var99))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 174, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 169, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 175, "<p class=\"text-xs text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 170, "<p class=\"text-xs text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var104 string
templ_7745c5c3_Var104, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_tls", "Count", e.DomainChangesPerDay))
var templ_7745c5c3_Var100 string
templ_7745c5c3_Var100, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_tls", "Count", e.DomainChangesPerDay))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 361, Col: 107}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 362, Col: 107}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var104))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var100))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 176, "</p></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 171, "</p></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 177, "</section></div></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 172, "</section></div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -2068,59 +2020,59 @@ func dnsRecordList(kind, name, value string) templ.Component {
}
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 178, "<dl class=\"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1 font-mono text-xs\"><dt class=\"text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 173, "<dl class=\"grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1 font-mono text-xs\"><dt class=\"text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var106 string
templ_7745c5c3_Var106, templ_7745c5c3_Err = templ.JoinStringErrs(kind)
var templ_7745c5c3_Var102 string
templ_7745c5c3_Var102, templ_7745c5c3_Err = templ.JoinStringErrs(kind)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 372, Col: 31}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 373, Col: 31}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var106))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var102))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 179, "</dt><dd class=\"break-all\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 174, "</dt><dd class=\"break-all\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var107 string
templ_7745c5c3_Var107, templ_7745c5c3_Err = templ.JoinStringErrs(name)
var templ_7745c5c3_Var103 string
templ_7745c5c3_Var103, templ_7745c5c3_Err = templ.JoinStringErrs(name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 373, Col: 30}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 374, Col: 30}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var107))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var103))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 180, "</dd><dt class=\"text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 175, "</dd><dt class=\"text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var108 string
templ_7745c5c3_Var108, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.value"))
var templ_7745c5c3_Var104 string
templ_7745c5c3_Var104, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.value"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 374, Col: 53}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 375, Col: 53}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var108))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var104))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 181, "</dt><dd class=\"break-all\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 176, "</dt><dd class=\"break-all\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var109 string
templ_7745c5c3_Var109, templ_7745c5c3_Err = templ.JoinStringErrs(value)
var templ_7745c5c3_Var105 string
templ_7745c5c3_Var105, templ_7745c5c3_Err = templ.JoinStringErrs(value)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 375, Col: 31}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 376, Col: 31}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var109))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var105))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 182, "</dd></dl>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 177, "</dd></dl>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -2145,46 +2097,174 @@ func verifyButton(pageID, label string) templ.Component {
}
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 183, "<button type=\"button\" data-post=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 178, "<button type=\"button\" data-post=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var107 string
templ_7745c5c3_Var107, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/statuspages/" + pageID + "/domain/verify").Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 381, Col: 82}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var107)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 179, "\" data-ok=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var108 string
templ_7745c5c3_Var108, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "pages.domain_verified")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 381, Col: 131}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var108)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 180, "\" data-reload class=\"mt-3 border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var109 string
templ_7745c5c3_Var109, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, label))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 381, Col: 247}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var109))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 181, "</button>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
// 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.
func pageMonitorFields(e PageEditor, m PageMonitorOption) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 182, "<span data-row-extra></span> <span class=\"flex gap-2\"><select data-field=\"group_id\" data-nullable aria-label=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var111 string
templ_7745c5c3_Var111, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/statuspages/" + pageID + "/domain/verify").Resolve(ctx)
templ_7745c5c3_Var111, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "pages.group")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 380, Col: 82}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 392, Col: 85}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var111)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 184, "\" data-ok=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 183, "\" class=\"w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink\"><option value=\"\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var112 string
templ_7745c5c3_Var112, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "pages.domain_verified")).Resolve(ctx)
templ_7745c5c3_Var112, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.no_group"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 380, Col: 131}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 393, Col: 51}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var112)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var112))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 185, "\" data-reload class=\"mt-3 border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 184, "</option> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var113 string
templ_7745c5c3_Var113, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, label))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 380, Col: 247}
for _, opt := range e.Groups {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 185, "<option value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var113 string
templ_7745c5c3_Var113, templ_7745c5c3_Err = templruntime.NewAttributeExpression(opt.ID).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 395, Col: 26}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var113)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 186, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if opt.ID == m.GroupID {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 187, " selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 188, ">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var114 string
templ_7745c5c3_Var114, templ_7745c5c3_Err = templ.JoinStringErrs(opt.Label)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 395, Col: 74}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var114))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 189, "</option>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var113))
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 190, "</select> <input data-field=\"label\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 186, "</button>")
var templ_7745c5c3_Var115 string
templ_7745c5c3_Var115, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Label).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 398, Col: 43}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var115)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 191, "\" placeholder=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var116 string
templ_7745c5c3_Var116, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "pages.label")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 398, Col: 86}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var116)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 192, "\" class=\"w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink\"></span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}