Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df39b765cb | ||
|
|
26e7275dd3 | ||
|
|
538c43b563 | ||
|
|
27338f0557 | ||
|
|
1138d555aa | ||
|
|
2a440b9c5e | ||
|
|
b88ed4bfd2 | ||
|
|
1dcb1531d0 | ||
|
|
87918eff80 | ||
|
|
963c677e1c | ||
|
|
a6bc50b39d |
No files matched your search
@@ -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
|
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:
|
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
|
```sh
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ func run(log *slog.Logger, level *slog.LevelVar, args []string) error {
|
|||||||
health.Register(r)
|
health.Register(r)
|
||||||
r.StaticFS("/static", web.Static())
|
r.StaticFS("/static", web.Static())
|
||||||
srv.Mount(r)
|
srv.Mount(r)
|
||||||
|
srv.EndLongPollsOn(health.Draining())
|
||||||
go srv.RunScheduler(ctx)
|
go srv.RunScheduler(ctx)
|
||||||
go srv.RunNotifier(ctx)
|
go srv.RunNotifier(ctx)
|
||||||
go srv.RunHousekeeping(ctx)
|
go srv.RunHousekeeping(ctx)
|
||||||
|
|||||||
@@ -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 = log.With("region", hello.Region, "agent", hello.Name, "instance", instance)
|
||||||
log.Info("connected to api")
|
log.Info("connected to api")
|
||||||
|
|
||||||
|
client.UseStream(ctx, agentapi.StreamOptions{Log: log})
|
||||||
runner := checker.New(client, cfg.Concurrency, log)
|
runner := checker.New(client, cfg.Concurrency, log)
|
||||||
health := platform.NewHealth(map[string]platform.Probe{"api": runner.Healthy})
|
health := platform.NewHealth(map[string]platform.Probe{"api": runner.Healthy})
|
||||||
r := platform.NewRouter(log)
|
r := platform.NewRouter(log)
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ func run(log *slog.Logger, level *slog.LevelVar) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 }
|
apiProbe := func(ctx context.Context) error { _, err := client.Hello(ctx); return err }
|
||||||
health := platform.NewHealth(map[string]platform.Probe{
|
health := platform.NewHealth(map[string]platform.Probe{
|
||||||
"pages": func(ctx context.Context) error { return pages.Ready(ctx, apiProbe) },
|
"pages": func(ctx context.Context) error { return pages.Ready(ctx, apiProbe) },
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ metadata:
|
|||||||
app.kubernetes.io/component: api
|
app.kubernetes.io/component: api
|
||||||
spec:
|
spec:
|
||||||
replicas: {{ .Values.api.replicas }}
|
replicas: {{ .Values.api.replicas }}
|
||||||
|
# Roll one pod at a time without ever having fewer ready than wanted;
|
||||||
|
# a new pod serves a few seconds before an old one goes, so the ingress
|
||||||
|
# has picked it up.
|
||||||
|
strategy:
|
||||||
|
type: RollingUpdate
|
||||||
|
rollingUpdate:
|
||||||
|
maxUnavailable: 0
|
||||||
|
maxSurge: 1
|
||||||
|
minReadySeconds: 5
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
{{- include "uptimesebi.selector" (list . "api") | nindent 6 }}
|
{{- include "uptimesebi.selector" (list . "api") | nindent 6 }}
|
||||||
|
|||||||
@@ -9,6 +9,15 @@ metadata:
|
|||||||
app.kubernetes.io/component: statuspage
|
app.kubernetes.io/component: statuspage
|
||||||
spec:
|
spec:
|
||||||
replicas: {{ .Values.statuspage.replicas }}
|
replicas: {{ .Values.statuspage.replicas }}
|
||||||
|
# Roll one pod at a time without ever having fewer ready than wanted;
|
||||||
|
# a new pod serves a few seconds before an old one goes, so the ingress
|
||||||
|
# has picked it up.
|
||||||
|
strategy:
|
||||||
|
type: RollingUpdate
|
||||||
|
rollingUpdate:
|
||||||
|
maxUnavailable: 0
|
||||||
|
maxSurge: 1
|
||||||
|
minReadySeconds: 5
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
{{- include "uptimesebi.selector" (list . "statuspage") | nindent 6 }}
|
{{- include "uptimesebi.selector" (list . "statuspage") | nindent 6 }}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ require (
|
|||||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20261123165210-6c21c5864259
|
golang.org/x/crypto/x509roots/fallback v0.0.0-20261123165210-6c21c5864259
|
||||||
golang.org/x/net v0.63.0
|
golang.org/x/net v0.63.0
|
||||||
golang.org/x/oauth2 v0.38.0
|
golang.org/x/oauth2 v0.38.0
|
||||||
|
golang.org/x/sync v0.25.0
|
||||||
golang.org/x/text v0.44.0
|
golang.org/x/text v0.44.0
|
||||||
google.golang.org/grpc v1.85.0
|
google.golang.org/grpc v1.85.0
|
||||||
layeh.com/radius v0.0.0-20231213012653-1006025d24f8
|
layeh.com/radius v0.0.0-20231213012653-1006025d24f8
|
||||||
@@ -116,7 +117,6 @@ require (
|
|||||||
golang.org/x/arch v0.22.0 // indirect
|
golang.org/x/arch v0.22.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20261109185158-a52e3aef5920 // indirect
|
golang.org/x/exp v0.0.0-20261109185158-a52e3aef5920 // indirect
|
||||||
golang.org/x/mod v0.43.0 // 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/sys v0.50.0 // indirect
|
||||||
golang.org/x/tools v0.52.1-0.20261106145633-d407941a339a // indirect
|
golang.org/x/tools v0.52.1-0.20261106145633-d407941a339a // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20261110000943-09e21b237f2c // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20261110000943-09e21b237f2c // indirect
|
||||||
|
|||||||
@@ -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):
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
-6
@@ -32,13 +32,16 @@ const (
|
|||||||
ctxAgent = "api.agent"
|
ctxAgent = "api.agent"
|
||||||
ctxInstance = "api.instance"
|
ctxInstance = "api.instance"
|
||||||
maxJobWait = 25 * time.Second
|
maxJobWait = 25 * time.Second
|
||||||
maxJobBatch = 200
|
// drainingPollHold is how long a draining instance still holds a poll.
|
||||||
|
drainingPollHold = time.Second
|
||||||
|
maxJobBatch = 200
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) mountAgentAPI(r gin.IRouter) {
|
func (s *Server) mountAgentAPI(r gin.IRouter) {
|
||||||
g := r.Group("/agent/v1", s.agentAuth())
|
g := r.Group(agentapi.Prefix, s.agentAuth())
|
||||||
g.GET("/hello", s.agentHello)
|
g.GET("/hello", s.agentHello)
|
||||||
g.GET("/update", s.agentUpdate)
|
g.GET("/update", s.agentUpdate)
|
||||||
|
g.GET(agentapi.StreamPath, s.agentStream)
|
||||||
sp := g.Group("", requireAgentKind("statuspage"))
|
sp := g.Group("", requireAgentKind("statuspage"))
|
||||||
sp.GET("/pages", s.agentPage)
|
sp.GET("/pages", s.agentPage)
|
||||||
sp.GET("/pages/index", s.agentPageIndex)
|
sp.GET("/pages/index", s.agentPageIndex)
|
||||||
@@ -197,8 +200,27 @@ func (s *Server) agentJobs(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
wait := min(time.Duration(req.WaitMS)*time.Millisecond, maxJobWait)
|
wait := min(time.Duration(req.WaitMS)*time.Millisecond, maxJobWait)
|
||||||
entries, err := s.sched.Take(ctx, instance, min(req.Max, maxJobBatch), wait)
|
// A draining instance ends long polls within a second or so, empty, so
|
||||||
if err != nil && ctx.Err() == nil {
|
// the shutdown is not held up and the checker's next poll reaches
|
||||||
|
// another instance. It still holds them that second, so checkers that
|
||||||
|
// poll again at once do not spin against it.
|
||||||
|
pollCtx, stop := context.WithCancel(ctx)
|
||||||
|
defer stop()
|
||||||
|
if s.draining != nil {
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-s.draining:
|
||||||
|
select {
|
||||||
|
case <-time.After(drainingPollHold):
|
||||||
|
case <-pollCtx.Done():
|
||||||
|
}
|
||||||
|
stop()
|
||||||
|
case <-pollCtx.Done():
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
entries, err := s.sched.Take(pollCtx, instance, min(req.Max, maxJobBatch), wait)
|
||||||
|
if err != nil && pollCtx.Err() == nil {
|
||||||
internalError(c, err)
|
internalError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -280,7 +302,10 @@ func (s *Server) agentResults(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
monitors := map[uuid.UUID]store.MonitorsForResultsRow{}
|
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 {
|
err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||||
a := agentOf(c)
|
a := agentOf(c)
|
||||||
rows, err := q.MonitorsForResults(ctx, store.MonitorsForResultsParams{RegionID: deref(a.RegionID), Ids: ids, AgentOrg: a.OrgID})
|
rows, err := q.MonitorsForResults(ctx, store.MonitorsForResultsParams{RegionID: deref(a.RegionID), Ids: ids, AgentOrg: a.OrgID})
|
||||||
@@ -316,7 +341,7 @@ func (s *Server) agentResults(c *gin.Context) {
|
|||||||
if len(params) == 0 {
|
if len(params) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_, err = q.InsertCheckResults(ctx, params)
|
changed, err = insertResults(ctx, q, params)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -325,6 +350,7 @@ func (s *Server) agentResults(c *gin.Context) {
|
|||||||
internalError(c, err)
|
internalError(c, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.pagesChanged(ctx, changed...)
|
||||||
s.evaluateResults(ctx, region, accepted, monitors)
|
s.evaluateResults(ctx, region, accepted, monitors)
|
||||||
s.storeEvidence(ctx, region, instance, accepted, monitors)
|
s.storeEvidence(ctx, region, instance, accepted, monitors)
|
||||||
s.finishRunning(ctx, instance, accepted)
|
s.finishRunning(ctx, instance, accepted)
|
||||||
|
|||||||
@@ -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,
|
Interval: time.Duration(m.IntervalSeconds) * time.Second, Confirmations: int(m.Confirmations), Regions: m.Regions,
|
||||||
})
|
})
|
||||||
if err == nil && t != evaluate.None {
|
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 {
|
if err != nil {
|
||||||
// The next result re-evaluates; a missed transition only delays
|
// The next result re-evaluates; a missed transition only delays
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ func (e *env) startChecker(t *testing.T, token string) (uuid.UUID, func()) {
|
|||||||
id := uuid.New()
|
id := uuid.New()
|
||||||
client := agentapi.NewClient(e.srv.URL, token, id, "test").WithHTTPClient(e.srv.Client())
|
client := agentapi.NewClient(e.srv.URL, token, id, "test").WithHTTPClient(e.srv.Client())
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
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{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
defer close(done)
|
defer close(done)
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ func (s *Server) loadCheckerActivity(ctx context.Context, p *principal, instance
|
|||||||
a.Siblings = append(a.Siblings, sb.ID)
|
a.Siblings = append(a.Siblings, sb.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
monitors, err := q.ListMonitors(ctx)
|
monitors, err := q.ListMonitors(ctx, p.Org.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+139
-53
@@ -84,12 +84,19 @@ func (s *Server) dashboard(c *gin.Context) {
|
|||||||
if !s.dashboardPage(c, &v, data) {
|
if !s.dashboardPage(c, &v, data) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err := s.dashboardBars(c.Request.Context(), p, &v, &data); err != nil {
|
||||||
|
internalError(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
v.Range = data.rng.Key
|
v.Range = data.rng.Key
|
||||||
var earliest time.Time
|
var earliest time.Time
|
||||||
for _, m := range data.byID {
|
if err := s.db.Tx(c.Request.Context(), p.scope(), func(q *store.Queries) error {
|
||||||
if f, ok := data.first[m.ID]; ok && (earliest.IsZero() || f.Before(earliest)) {
|
var err error
|
||||||
earliest = f
|
earliest, err = earliestData(c.Request.Context(), q, p.Org.ID, data.now)
|
||||||
}
|
return err
|
||||||
|
}); err != nil {
|
||||||
|
internalError(c, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
v.Ranges = rangeOptions(c, data.rng, earliest, data.now)
|
v.Ranges = rangeOptions(c, data.rng, earliest, data.now)
|
||||||
for _, m := range data.rows {
|
for _, m := range data.rows {
|
||||||
@@ -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))
|
web.Render(c, http.StatusOK, web.Dashboard(s.pageFor(c, "console.monitors.title"), me, v))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dashboardBars loads the bars of the monitors v shows, and only those.
|
||||||
|
func (s *Server) dashboardBars(ctx context.Context, p *principal, v *web.DashboardView, data *monitorData) error {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
walk := func(rows []web.MonitorRow, set bool) {
|
||||||
|
for i := range rows {
|
||||||
|
id, err := uuid.Parse(rows[i].ID)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if set {
|
||||||
|
rows[i].Bars = data.bars(id)
|
||||||
|
} else {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var tree func(n *web.GroupNode, set bool)
|
||||||
|
tree = func(n *web.GroupNode, set bool) {
|
||||||
|
walk(n.Monitors, set)
|
||||||
|
for i := range n.Children {
|
||||||
|
tree(&n.Children[i], set)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A search or filter lists Results instead of the tree.
|
||||||
|
listing := v.Search != "" || v.Filter != ""
|
||||||
|
if listing {
|
||||||
|
walk(v.Results, false)
|
||||||
|
} else {
|
||||||
|
tree(&v.Root, false)
|
||||||
|
}
|
||||||
|
if err := s.loadBars(ctx, p, data, ids); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if listing {
|
||||||
|
walk(v.Results, true)
|
||||||
|
} else {
|
||||||
|
tree(&v.Root, true)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// groupMonitorsShown is how many of its own monitors a group shows on the
|
// groupMonitorsShown is how many of its own monitors a group shows on the
|
||||||
// dashboard before linking to all of them.
|
// dashboard before linking to all of them.
|
||||||
const groupMonitorsShown = 50
|
const groupMonitorsShown = 50
|
||||||
@@ -324,80 +372,96 @@ type monitorData struct {
|
|||||||
maint map[uuid.UUID][]store.MaintenanceWindow
|
maint map[uuid.UUID][]store.MaintenanceWindow
|
||||||
rows []web.MonitorRow
|
rows []web.MonitorRow
|
||||||
byID map[uuid.UUID]store.Monitor
|
byID map[uuid.UUID]store.Monitor
|
||||||
// buckets cover the selected range at its resolution.
|
// buckets cover the selected range at its resolution, for the
|
||||||
|
// monitors loadBars was asked for.
|
||||||
buckets map[uuid.UUID][]web.Bucket
|
buckets map[uuid.UUID][]web.Bucket
|
||||||
down map[uuid.UUID][]web.Span
|
down map[uuid.UUID][]web.Span
|
||||||
regionOf map[uuid.UUID]store.Region
|
regionOf map[uuid.UUID]store.Region
|
||||||
rng web.TimeRange
|
rng web.TimeRange
|
||||||
now time.Time
|
now time.Time
|
||||||
// first is when each monitor first reported, from any region;
|
// first is when the monitor of a detail page first reported, from
|
||||||
// firstRegion the same per region.
|
// any region; firstRegion the same per region.
|
||||||
first map[uuid.UUID]time.Time
|
first time.Time
|
||||||
firstRegion map[uuid.UUID]map[string]time.Time
|
firstRegion map[string]time.Time
|
||||||
// statuses are the organization's own incident statuses.
|
// statuses are the organization's own incident statuses.
|
||||||
statuses customStatuses
|
statuses customStatuses
|
||||||
// usedRegions are the regions the enabled monitors are checked from.
|
// usedRegions are the regions the enabled monitors are checked from.
|
||||||
usedRegions []uuid.UUID
|
usedRegions []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadFirstData finds when monitors and their regions first reported. The
|
// loadFirstData finds when monitor and its regions first reported. The
|
||||||
// daily aggregate answers to the day, which is precise enough for anything
|
// daily aggregate answers to the day, which is precise enough for anything
|
||||||
// older than two days; younger data is looked up in the raw results.
|
// older than two days; younger data is looked up exactly.
|
||||||
func loadFirstData(ctx context.Context, q *store.Queries, org uuid.UUID, now time.Time) (map[uuid.UUID]time.Time, map[uuid.UUID]map[string]time.Time, error) {
|
func loadFirstData(ctx context.Context, q *store.Queries, org, monitor uuid.UUID, now time.Time) (time.Time, map[string]time.Time, error) {
|
||||||
first := map[uuid.UUID]time.Time{}
|
var first time.Time
|
||||||
perRegion := map[uuid.UUID]map[string]time.Time{}
|
perRegion := map[string]time.Time{}
|
||||||
note := func(m uuid.UUID, region string, t time.Time) {
|
note := func(region string, t time.Time) {
|
||||||
if perRegion[m] == nil {
|
if cur, ok := perRegion[region]; !ok || t.Before(cur) {
|
||||||
perRegion[m] = map[string]time.Time{}
|
perRegion[region] = t
|
||||||
}
|
}
|
||||||
if cur, ok := perRegion[m][region]; !ok || t.Before(cur) {
|
if first.IsZero() || t.Before(first) {
|
||||||
perRegion[m][region] = t
|
first = t
|
||||||
}
|
|
||||||
if cur, ok := first[m]; !ok || t.Before(cur) {
|
|
||||||
first[m] = t
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recentSince := now.Add(-2 * 24 * time.Hour)
|
recentSince := now.Add(-2 * 24 * time.Hour)
|
||||||
daily, err := q.FirstDataDaily(ctx, org)
|
daily, err := q.FirstDataDaily(ctx, store.FirstDataDailyParams{OrgID: org, MonitorID: monitor})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return first, nil, err
|
||||||
}
|
}
|
||||||
for _, r := range daily {
|
for _, r := range daily {
|
||||||
if r.First.Before(recentSince) {
|
if r.First.Before(recentSince) {
|
||||||
note(r.MonitorID, r.Region, r.First)
|
note(r.Region, r.First)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recent, err := q.FirstDataRecent(ctx, store.FirstDataRecentParams{OrgID: org, Time: recentSince})
|
recent, err := q.FirstDataRecent(ctx, store.FirstDataRecentParams{OrgID: org, MonitorID: monitor, Time: recentSince})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return first, nil, err
|
||||||
}
|
}
|
||||||
for _, r := range recent {
|
for _, r := range recent {
|
||||||
note(r.MonitorID, r.Region, r.First)
|
note(r.Region, r.First)
|
||||||
}
|
}
|
||||||
return first, perRegion, nil
|
return first, perRegion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// rangeBuckets loads the selected range for all monitors, or one if
|
// earliestData finds when any monitor of org first reported, for the
|
||||||
// monitor is set.
|
// ranges the monitor list offers: to the day if that was over two days
|
||||||
func rangeBuckets(ctx context.Context, q *store.Queries, org uuid.UUID, monitor *uuid.UUID, rng web.TimeRange, now time.Time) (map[uuid.UUID][]web.Bucket, error) {
|
// ago, otherwise exactly.
|
||||||
|
func earliestData(ctx context.Context, q *store.Queries, org uuid.UUID, now time.Time) (time.Time, error) {
|
||||||
|
none := func(t time.Time, err error) (time.Time, bool, error) {
|
||||||
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
return time.Time{}, false, nil
|
||||||
|
}
|
||||||
|
return t, err == nil, err
|
||||||
|
}
|
||||||
|
recentSince := now.Add(-2 * 24 * time.Hour)
|
||||||
|
daily, ok, err := none(q.EarliestDataDaily(ctx, org))
|
||||||
|
if err != nil || (ok && daily.Before(recentSince)) {
|
||||||
|
return daily, err
|
||||||
|
}
|
||||||
|
exact, _, err := none(q.EarliestDataRecent(ctx, store.EarliestDataRecentParams{OrgID: org, Time: recentSince}))
|
||||||
|
return exact, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// rangeBuckets loads the selected range for the monitors ids.
|
||||||
|
func rangeBuckets(ctx context.Context, q *store.Queries, org uuid.UUID, ids []uuid.UUID, rng web.TimeRange, now time.Time) (map[uuid.UUID][]web.Bucket, error) {
|
||||||
out := map[uuid.UUID][]web.Bucket{}
|
out := map[uuid.UUID][]web.Bucket{}
|
||||||
since := now.Add(-rng.Window).Truncate(rng.Bucket)
|
since := now.Add(-rng.Window).Truncate(rng.Bucket)
|
||||||
width := fmt.Sprintf("%d seconds", int(rng.Bucket.Seconds()))
|
width := fmt.Sprintf("%d seconds", int(rng.Bucket.Seconds()))
|
||||||
switch rng.Source {
|
switch rng.Source {
|
||||||
case web.SourceHourly:
|
case web.SourceHourly:
|
||||||
rows, err := q.RangeBucketsHourly(ctx, store.RangeBucketsHourlyParams{OrgID: org, Width: width, Since: since, MonitorID: monitor})
|
rows, err := q.RangeBucketsHourly(ctx, store.RangeBucketsHourlyParams{OrgID: org, Width: width, Since: since, Ids: ids})
|
||||||
for _, r := range rows {
|
for _, r := range rows {
|
||||||
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
||||||
}
|
}
|
||||||
return out, err
|
return out, err
|
||||||
case web.SourceDaily:
|
case web.SourceDaily:
|
||||||
rows, err := q.RangeBucketsDaily(ctx, store.RangeBucketsDailyParams{OrgID: org, Width: width, Since: since, MonitorID: monitor})
|
rows, err := q.RangeBucketsDaily(ctx, store.RangeBucketsDailyParams{OrgID: org, Width: width, Since: since, Ids: ids})
|
||||||
for _, r := range rows {
|
for _, r := range rows {
|
||||||
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
||||||
}
|
}
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
rows, err := q.RangeBuckets(ctx, store.RangeBucketsParams{OrgID: org, Width: width, Since: since, MonitorID: monitor})
|
rows, err := q.RangeBuckets(ctx, store.RangeBucketsParams{OrgID: org, Width: width, Since: since, Ids: ids})
|
||||||
for _, r := range rows {
|
for _, r := range rows {
|
||||||
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
out[r.MonitorID] = append(out[r.MonitorID], web.Bucket{Start: r.Bucket, Total: r.Total, OK: r.OkCount, Latency: r.AvgLatencyMs})
|
||||||
}
|
}
|
||||||
@@ -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)
|
return web.SLA(d.down[m.ID], from, d.now)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadMonitorData assembles everything the monitor list shows.
|
// loadMonitorData assembles the status of every monitor for rng.
|
||||||
// loadMonitorData assembles everything the monitor list shows for rng.
|
// Incidents are loaded far enough back for every SLA window. The bars of
|
||||||
// Incidents are loaded far enough back for every SLA window.
|
// rng are left to loadBars, for the monitors shown: an organization may
|
||||||
|
// have thousands.
|
||||||
func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.TimeRange) (monitorData, error) {
|
func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.TimeRange) (monitorData, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
d := monitorData{
|
d := monitorData{
|
||||||
@@ -438,10 +503,10 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
if groups, err = q.ListGroups(ctx); err != nil {
|
if groups, err = q.ListGroups(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if monitors, err = q.ListMonitors(ctx); err != nil {
|
if monitors, err = q.ListMonitors(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if assigned, err = q.AllMonitorRegions(ctx); err != nil {
|
if assigned, err = q.AllMonitorRegions(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if regions, err = q.ListVisibleRegions(ctx); err != nil {
|
if regions, err = q.ListVisibleRegions(ctx); err != nil {
|
||||||
@@ -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 {
|
if latest, err = q.LatestResults(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if open, err = q.OpenIncidents(ctx); err != nil {
|
if open, err = q.OpenIncidents(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if spans, err = q.IncidentsSince(ctx, ptr(now.Add(-web.SLAWindows[len(web.SLAWindows)-1].Window))); err != nil {
|
if spans, err = q.IncidentsSince(ctx, store.IncidentsSinceParams{OrgID: p.Org.ID, ResolvedAt: ptr(now.Add(-web.SLAWindows[len(web.SLAWindows)-1].Window))}); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
if d.first, d.firstRegion, err = loadFirstData(ctx, q, p.Org.ID, now); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if d.statuses, err = loadCustomStatuses(ctx, q); err != nil {
|
if d.statuses, err = loadCustomStatuses(ctx, q); err != nil {
|
||||||
@@ -466,10 +528,7 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
for i, m := range monitors {
|
for i, m := range monitors {
|
||||||
ids[i] = m.ID
|
ids[i] = m.ID
|
||||||
}
|
}
|
||||||
if d.maint, err = maintenanceFor(ctx, q, ids); err != nil {
|
d.maint, err = maintenanceFor(ctx, q, ids)
|
||||||
return err
|
|
||||||
}
|
|
||||||
d.buckets, err = rangeBuckets(ctx, q, p.Org.ID, nil, rng, now)
|
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -581,7 +640,6 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
}
|
}
|
||||||
row.Ratio = d.slaFor(m, rng.Window)
|
row.Ratio = d.slaFor(m, rng.Window)
|
||||||
row.Uptime = web.SLAText(row.Ratio)
|
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)
|
d.rows = append(d.rows, row)
|
||||||
}
|
}
|
||||||
// Problems first, then by name.
|
// Problems first, then by name.
|
||||||
@@ -589,6 +647,23 @@ func (s *Server) loadMonitorData(ctx context.Context, p *principal, rng web.Time
|
|||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loadBars loads the bars of the selected range for the monitors ids.
|
||||||
|
func (s *Server) loadBars(ctx context.Context, p *principal, d *monitorData, ids []uuid.UUID) error {
|
||||||
|
if len(ids) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||||
|
var err error
|
||||||
|
d.buckets, err = rangeBuckets(ctx, q, p.Org.ID, ids, d.rng, d.now)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// bars are the monitor's bars of the selected range, from loadBars.
|
||||||
|
func (d monitorData) bars(id uuid.UUID) []web.Bar {
|
||||||
|
return web.UptimeBars(d.buckets[id], d.now, d.rng.Bucket, d.rng.Bars(), d.rng.Layout)
|
||||||
|
}
|
||||||
|
|
||||||
func (d monitorData) regionName(id uuid.UUID) string {
|
func (d monitorData) regionName(id uuid.UUID) string {
|
||||||
if r, ok := d.regionOf[id]; ok {
|
if r, ok := d.regionOf[id]; ok {
|
||||||
return r.Name
|
return r.Name
|
||||||
@@ -611,6 +686,16 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
|
|||||||
if !ok {
|
if !ok {
|
||||||
return notFoundPage(c)
|
return notFoundPage(c)
|
||||||
}
|
}
|
||||||
|
if err := s.loadBars(ctx, p, &d, []uuid.UUID{id}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||||
|
var err error
|
||||||
|
d.first, d.firstRegion, err = loadFirstData(ctx, q, p.Org.ID, id, d.now)
|
||||||
|
return err
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
v := web.MonitorDetailView{
|
v := web.MonitorDetailView{
|
||||||
Interval: (time.Duration(m.IntervalSeconds) * time.Second).String(),
|
Interval: (time.Duration(m.IntervalSeconds) * time.Second).String(),
|
||||||
PingURL: s.detailPingURL(p, d, m),
|
PingURL: s.detailPingURL(p, d, m),
|
||||||
@@ -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),
|
Latency: web.Latency(d.buckets[id], d.now.Add(-d.rng.Window).Truncate(d.rng.Bucket), d.now, 480, 96),
|
||||||
Maintenance: maintenanceItems(d.maint[id], d.now),
|
Maintenance: maintenanceItems(d.maint[id], d.now),
|
||||||
Range: d.rng.Key,
|
Range: d.rng.Key,
|
||||||
Ranges: rangeOptions(c, d.rng, d.first[id], d.now),
|
Ranges: rangeOptions(c, d.rng, d.first, d.now),
|
||||||
Uptime90: "–",
|
Uptime90: "–",
|
||||||
}
|
}
|
||||||
for _, r := range d.rows {
|
for _, r := range d.rows {
|
||||||
@@ -626,6 +711,7 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
|
|||||||
v.Row = r
|
v.Row = r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
v.Row.Bars = d.bars(id)
|
||||||
var (
|
var (
|
||||||
daily []store.DailyBucketsRow
|
daily []store.DailyBucketsRow
|
||||||
recent []store.ListResultsRow
|
recent []store.ListResultsRow
|
||||||
@@ -654,7 +740,7 @@ func (s *Server) monitorDetail(c *gin.Context, p *principal, page web.Page, me w
|
|||||||
for _, w := range web.SLAWindows {
|
for _, w := range web.SLAWindows {
|
||||||
v.SLAs = append(v.SLAs, web.SLAEntry{
|
v.SLAs = append(v.SLAs, web.SLAEntry{
|
||||||
Label: w.Key, Value: web.SLAText(d.slaFor(m, w.Window)),
|
Label: w.Key, Value: web.SLAText(d.slaFor(m, w.Window)),
|
||||||
Partial: !web.HasEnoughData(d.first[id], d.now, w.Window),
|
Partial: !web.HasEnoughData(d.first, d.now, w.Window),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
regions, err := s.regionHistory(ctx, p, d, m)
|
regions, err := s.regionHistory(ctx, p, d, m)
|
||||||
@@ -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 {
|
if orgGroups, err = q.ListGroups(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if monitors, err = q.ListMonitors(ctx); err != nil {
|
if monitors, err = q.ListMonitors(ctx, p.Org.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
own, err = q.OrgServesOwnPages(ctx, &p.Org.ID)
|
own, err = q.OrgServesOwnPages(ctx, &p.Org.ID)
|
||||||
@@ -1479,7 +1565,7 @@ func (s *Server) regionHistory(ctx context.Context, p *principal, d monitorData,
|
|||||||
Name: d.regionNameString(r),
|
Name: d.regionNameString(r),
|
||||||
Bars: web.UptimeBars(byRegion[r], d.now, rng.Bucket, rng.Bars(), rng.Layout),
|
Bars: web.UptimeBars(byRegion[r], d.now, rng.Bucket, rng.Bars(), rng.Layout),
|
||||||
Uptime: "–",
|
Uptime: "–",
|
||||||
Enough: web.HasEnoughData(d.firstRegion[m.ID][r], d.now, rng.Window),
|
Enough: web.HasEnoughData(d.firstRegion[r], d.now, rng.Window),
|
||||||
}
|
}
|
||||||
if u := web.Uptime(byRegion[r]); u >= 0 {
|
if u := web.Uptime(byRegion[r]); u >= 0 {
|
||||||
h.Uptime = web.PercentPrecise(u)
|
h.Uptime = web.PercentPrecise(u)
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ func TestPageEditorOffersAddAndRemoveAll(t *testing.T) {
|
|||||||
_, region := e.platformChecker(t, uniq("eu-"))
|
_, region := e.platformChecker(t, uniq("eu-"))
|
||||||
owner := e.browser(t)
|
owner := e.browser(t)
|
||||||
owner.signup("o@"+uniq("pa")+".test", uniq("pa-"))
|
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"})
|
_, p := owner.do("POST", "/api/v1/org/statuspages", map[string]any{"slug": uniq("pa-"), "title": "Status"})
|
||||||
_, _, html := owner.page("/statuspages/" + p["id"].(string))
|
_, _, html := owner.page("/statuspages/" + p["id"].(string))
|
||||||
for _, want := range []string{`data-check-all="on"`, `data-check-all="off"`, "Add all", "Remove all"} {
|
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)
|
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) {
|
func TestMonitorOrder(t *testing.T) {
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package api_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLongPollsEndWhenDraining(t *testing.T) {
|
||||||
|
e := newEnv(t)
|
||||||
|
tok, _ := e.platformChecker(t, uniq("eu-"))
|
||||||
|
drain := make(chan struct{})
|
||||||
|
e.api.EndLongPollsOn(drain)
|
||||||
|
client := agentapi.NewClient(e.srv.URL, tok, uuid.New(), "test").WithHTTPClient(e.srv.Client())
|
||||||
|
|
||||||
|
go func() { time.Sleep(300 * time.Millisecond); close(drain) }()
|
||||||
|
start := time.Now()
|
||||||
|
jobs, err := client.Jobs(context.Background(), 10, 20*time.Second)
|
||||||
|
if err != nil || len(jobs) != 0 {
|
||||||
|
t.Fatalf("Jobs() while draining = %v, %v; want no jobs and no error", jobs, err)
|
||||||
|
}
|
||||||
|
if took := time.Since(start); took > 3*time.Second {
|
||||||
|
t.Errorf("a long poll ran %v after draining began, want it to end within about a second", took)
|
||||||
|
}
|
||||||
|
// Once draining, polls answer at once.
|
||||||
|
start = time.Now()
|
||||||
|
if _, err := client.Jobs(context.Background(), 10, 20*time.Second); err != nil || time.Since(start) > 2*time.Second {
|
||||||
|
t.Errorf("a poll on a draining instance took %v (%v)", time.Since(start), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -472,7 +472,7 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
|
|||||||
for _, a := range alertAssignments {
|
for _, a := range alertAssignments {
|
||||||
alertGroupsByMonitor[a.MonitorID] = append(alertGroupsByMonitor[a.MonitorID], a.GroupID)
|
alertGroupsByMonitor[a.MonitorID] = append(alertGroupsByMonitor[a.MonitorID], a.GroupID)
|
||||||
}
|
}
|
||||||
regionRows, err := q.AllMonitorRegions(ctx)
|
regionRows, err := q.AllMonitorRegions(ctx, p.Org.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -480,7 +480,7 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
|
|||||||
for _, r := range regionRows {
|
for _, r := range regionRows {
|
||||||
regions[r.MonitorID] = append(regions[r.MonitorID], r.RegionID)
|
regions[r.MonitorID] = append(regions[r.MonitorID], r.RegionID)
|
||||||
}
|
}
|
||||||
monitors, err := q.ListMonitors(ctx)
|
monitors, err := q.ListMonitors(ctx, p.Org.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,13 +92,16 @@ func (s *Server) recordPassive(ctx context.Context, region string, id, org uuid.
|
|||||||
if msg != "" {
|
if msg != "" {
|
||||||
row.Error = ptr(truncateValid(msg, 500))
|
row.Error = ptr(truncateValid(msg, 500))
|
||||||
}
|
}
|
||||||
|
var changed []uuid.UUID
|
||||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||||
_, err := q.InsertCheckResults(ctx, []store.InsertCheckResultsParams{row})
|
var err error
|
||||||
|
changed, err = insertResults(ctx, q, []store.InsertCheckResultsParams{row})
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
s.pagesChanged(ctx, changed...)
|
||||||
s.evaluateResults(ctx, region,
|
s.evaluateResults(ctx, region,
|
||||||
[]agentapi.Result{{MonitorID: id, ScheduledAt: at, StartedAt: at, OK: ok}},
|
[]agentapi.Result{{MonitorID: id, ScheduledAt: at, StartedAt: at, OK: ok}},
|
||||||
map[uuid.UUID]store.MonitorsForResultsRow{id: {
|
map[uuid.UUID]store.MonitorsForResultsRow{id: {
|
||||||
|
|||||||
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -234,7 +234,7 @@ func (s *Server) loadMaintenanceScope(ctx context.Context, p *principal) (mainte
|
|||||||
return ms, err
|
return ms, err
|
||||||
}
|
}
|
||||||
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
||||||
rows, err := q.ListMonitors(ctx)
|
rows, err := q.ListMonitors(ctx, p.Org.ID)
|
||||||
for _, m := range rows {
|
for _, m := range rows {
|
||||||
ms.monitors[m.ID] = m
|
ms.monitors[m.ID] = m
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ func (s *Server) listMonitors(c *gin.Context) {
|
|||||||
for _, a := range assignments {
|
for _, a := range assignments {
|
||||||
alertGroups[a.MonitorID] = append(alertGroups[a.MonitorID], a.GroupID)
|
alertGroups[a.MonitorID] = append(alertGroups[a.MonitorID], a.GroupID)
|
||||||
}
|
}
|
||||||
regions, err := q.AllMonitorRegions(ctx)
|
regions, err := q.AllMonitorRegions(ctx, p.Org.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,13 @@ func TestUncheckedMonitorsAndRegionsWithoutChecker(t *testing.T) {
|
|||||||
if _, err := tx.Exec(ctx, `UPDATE monitors SET created_at = now() - interval '1 hour' WHERE id = $1`, id); err != nil {
|
if _, err := tx.Exec(ctx, `UPDATE monitors SET created_at = now() - interval '1 hour' WHERE id = $1`, id); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err := tx.Exec(ctx, `INSERT INTO check_results (time, org_id, monitor_id, region, checker_id, ok, latency_ms) VALUES (now() - interval '10 minutes', $1, $2, $3, $4, true, 10)`,
|
if _, err := tx.Exec(ctx, `INSERT INTO check_results (time, org_id, monitor_id, region, checker_id, ok, latency_ms) VALUES (now() - interval '10 minutes', $1, $2, $3, $4, true, 10)`,
|
||||||
org, id, region, uuid.New())
|
org, id, region, uuid.New()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// As the API keeps it when the result arrives.
|
||||||
|
_, err := tx.Exec(ctx, `INSERT INTO latest_results (time, org_id, monitor_id, region, ok, latency_ms) VALUES (now() - interval '10 minutes', $1, $2, $3, true, 10)`,
|
||||||
|
org, id, region)
|
||||||
return err
|
return err
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -0,0 +1,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
|
||||||
|
}
|
||||||
+17
-2
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/redis/go-redis/v9"
|
"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/agentapi"
|
||||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
|
||||||
@@ -55,6 +56,13 @@ type Server struct {
|
|||||||
limits *versioned[Limits]
|
limits *versioned[Limits]
|
||||||
// support caches how the platform runs support tickets.
|
// support caches how the platform runs support tickets.
|
||||||
support *versioned[supportSettings]
|
support *versioned[supportSettings]
|
||||||
|
// draining, once closed, ends the long polls of checkers.
|
||||||
|
draining <-chan struct{}
|
||||||
|
// 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.
|
// Deps are the external resources a Server needs.
|
||||||
@@ -94,9 +102,16 @@ func New(cfg config.API, d Deps) *Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EndLongPollsOn makes the checkers' long polls return as soon as ch is
|
||||||
|
// closed, as when the instance starts draining for a shutdown.
|
||||||
|
func (s *Server) EndLongPollsOn(ch <-chan struct{}) { s.draining = ch }
|
||||||
|
|
||||||
// Mount installs session loading, locale resolution and CSRF protection and
|
// Mount installs session loading, locale resolution and CSRF protection and
|
||||||
// registers the JSON API and the console pages below them.
|
// registers the JSON API and the console pages below them.
|
||||||
func (s *Server) Mount(r gin.IRouter) {
|
func (s *Server) Mount(r gin.IRouter) {
|
||||||
|
if h, ok := r.(http.Handler); ok {
|
||||||
|
s.handler = h
|
||||||
|
}
|
||||||
// Agents authenticate with tokens and never carry cookies, so they skip
|
// Agents authenticate with tokens and never carry cookies, so they skip
|
||||||
// the session and CSRF middleware.
|
// the session and CSRF middleware.
|
||||||
s.mountAgentAPI(r)
|
s.mountAgentAPI(r)
|
||||||
@@ -145,7 +160,7 @@ func (s *Server) Mount(r gin.IRouter) {
|
|||||||
v1.POST("/invitations/:token/accept", auth.Require(), s.acceptInvitation)
|
v1.POST("/invitations/:token/accept", auth.Require(), s.acceptInvitation)
|
||||||
v1.POST("/invitations/:token/signup", s.inviteSignup)
|
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.PUT("/policy", sessionOnly(), can(authz.OrgManage), s.updatePolicy)
|
||||||
org.GET("/export", sessionOnly(), can(authz.OrgManage), s.exportOrg)
|
org.GET("/export", sessionOnly(), can(authz.OrgManage), s.exportOrg)
|
||||||
org.GET("/legal", can(authz.OrgManage), s.orgListLegal)
|
org.GET("/legal", can(authz.OrgManage), s.orgListLegal)
|
||||||
@@ -187,7 +202,7 @@ func (s *Server) Mount(r gin.IRouter) {
|
|||||||
org.PATCH("/agents/:id", sessionOnly(), can(authz.OrgManage), s.updateOrgAgent)
|
org.PATCH("/agents/:id", sessionOnly(), can(authz.OrgManage), s.updateOrgAgent)
|
||||||
org.DELETE("/agents/:id", sessionOnly(), can(authz.OrgManage), s.deleteOrgAgent)
|
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("/audit", s.listPlatformAudit)
|
||||||
admin.GET("/check-types", s.adminListCheckTypes)
|
admin.GET("/check-types", s.adminListCheckTypes)
|
||||||
admin.PUT("/check-types", s.adminSetCheckTypes)
|
admin.PUT("/check-types", s.adminSetCheckTypes)
|
||||||
|
|||||||
@@ -84,10 +84,15 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
|||||||
for i, m := range listed {
|
for i, m := range listed {
|
||||||
ids[i] = m.MonitorID
|
ids[i] = m.MonitorID
|
||||||
}
|
}
|
||||||
if latest, err = q.LatestResults(ctx, page.OrgID); err != nil {
|
rows, err := q.LatestResultsForMonitors(ctx, store.LatestResultsForMonitorsParams{OrgID: page.OrgID, Ids: ids})
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if open, err = q.OpenIncidents(ctx); err != nil {
|
latest = make([]store.LatestResultsRow, len(rows))
|
||||||
|
for i, r := range rows {
|
||||||
|
latest[i] = store.LatestResultsRow(r)
|
||||||
|
}
|
||||||
|
if open, err = q.OpenIncidents(ctx, page.OrgID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if daily, err = q.DailyBucketsForMonitors(ctx, store.DailyBucketsForMonitorsParams{
|
if daily, err = q.DailyBucketsForMonitors(ctx, store.DailyBucketsForMonitorsParams{
|
||||||
@@ -97,7 +102,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
|||||||
}
|
}
|
||||||
if page.ShowComponentDetails {
|
if page.ShowComponentDetails {
|
||||||
if hourly, err = q.HourlyBuckets(ctx, store.HourlyBucketsParams{
|
if hourly, err = q.HourlyBuckets(ctx, store.HourlyBucketsParams{
|
||||||
OrgID: page.OrgID, Bucket: now.UTC().Add(-24 * time.Hour),
|
OrgID: page.OrgID, Bucket: now.UTC().Add(-24 * time.Hour), Ids: ids,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -105,7 +110,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
|||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
incidentIDs := make([]uuid.UUID, len(incidents))
|
incidentIDs := make([]uuid.UUID, len(incidents))
|
||||||
@@ -371,7 +376,7 @@ func (s *Server) agentPage(c *gin.Context) {
|
|||||||
fail(c, http.StatusNotFound, "not_found")
|
fail(c, http.StatusNotFound, "not_found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
snap, err := s.buildSnapshot(ctx, page)
|
snap, err := s.sharedSnapshot(ctx, page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
internalError(c, err)
|
internalError(c, err)
|
||||||
return
|
return
|
||||||
@@ -387,6 +392,30 @@ func (s *Server) agentPage(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, snap)
|
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
|
// agentServes finds the published page a status page agent serves at host
|
||||||
// or slug. The platform's servers leave the pages of organizations that
|
// 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
|
// serve them on their own servers to those, which receive only their own
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -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() })
|
||||||
|
}
|
||||||
@@ -26,7 +26,9 @@ type API interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
pollWait = 20 * time.Second
|
pollWait = 20 * time.Second
|
||||||
|
// quickPoll is a long poll answered empty faster than any wait would.
|
||||||
|
quickPoll = 200 * time.Millisecond
|
||||||
flushInterval = 2 * time.Second
|
flushInterval = 2 * time.Second
|
||||||
// maxPending bounds results kept while the API is unreachable.
|
// maxPending bounds results kept while the API is unreachable.
|
||||||
maxPending = 50_000
|
maxPending = 50_000
|
||||||
@@ -127,6 +129,12 @@ func (r *Runner) Run(ctx context.Context, drain time.Duration) error {
|
|||||||
|
|
||||||
func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
||||||
backoff := time.Second
|
backoff := time.Second
|
||||||
|
// failing and failures track an outage, so its end is logged too: a log
|
||||||
|
// whose last line is an error otherwise reads as a checker stuck.
|
||||||
|
var (
|
||||||
|
failing time.Time
|
||||||
|
failures int
|
||||||
|
)
|
||||||
for ctx.Err() == nil {
|
for ctx.Err() == nil {
|
||||||
free := cap(r.slots) - len(r.slots)
|
free := cap(r.slots) - len(r.slots)
|
||||||
wait := pollWait
|
wait := pollWait
|
||||||
@@ -134,6 +142,7 @@ func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
|||||||
// Still poll as a heartbeat, but do not take work.
|
// Still poll as a heartbeat, but do not take work.
|
||||||
wait = 0
|
wait = 0
|
||||||
}
|
}
|
||||||
|
asked := time.Now()
|
||||||
jobs, err := r.api.Jobs(ctx, free, wait)
|
jobs, err := r.api.Jobs(ctx, free, wait)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, agentapi.ErrUnauthorized):
|
case errors.Is(err, agentapi.ErrUnauthorized):
|
||||||
@@ -143,11 +152,19 @@ func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
r.log.Warn("polling for jobs failed", "error", err, "retry_in", backoff)
|
r.log.Warn("polling for jobs failed", "error", err, "retry_in", backoff)
|
||||||
|
if failing.IsZero() {
|
||||||
|
failing = time.Now()
|
||||||
|
}
|
||||||
|
failures++
|
||||||
sleep(ctx, backoff)
|
sleep(ctx, backoff)
|
||||||
backoff = min(backoff*2, 30*time.Second)
|
backoff = min(backoff*2, 30*time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
backoff = time.Second
|
backoff = time.Second
|
||||||
|
if !failing.IsZero() {
|
||||||
|
r.log.Info("polling for jobs works again", "failed_for", time.Since(failing).Round(time.Second).String(), "failures", failures)
|
||||||
|
failing, failures = time.Time{}, 0
|
||||||
|
}
|
||||||
r.lastPoll.Store(time.Now().UnixMilli())
|
r.lastPoll.Store(time.Now().UnixMilli())
|
||||||
for _, j := range jobs {
|
for _, j := range jobs {
|
||||||
r.slots <- struct{}{}
|
r.slots <- struct{}{}
|
||||||
@@ -157,7 +174,9 @@ func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
|||||||
r.results <- r.execute(ctx, j)
|
r.results <- r.execute(ctx, j)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if free == 0 {
|
// A long poll answered empty at once, as by an instance shutting
|
||||||
|
// down, is not repeated at once either.
|
||||||
|
if free == 0 || (len(jobs) == 0 && wait > 0 && time.Since(asked) < quickPoll) {
|
||||||
sleep(ctx, time.Second)
|
sleep(ctx, time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,15 +207,27 @@ func (r *Runner) execute(ctx context.Context, j agentapi.Job) agentapi.Result {
|
|||||||
func (r *Runner) report(ctx context.Context) {
|
func (r *Runner) report(ctx context.Context) {
|
||||||
tick := time.NewTicker(flushInterval)
|
tick := time.NewTicker(flushInterval)
|
||||||
defer tick.Stop()
|
defer tick.Stop()
|
||||||
var pending []agentapi.Result
|
var (
|
||||||
|
pending []agentapi.Result
|
||||||
|
// failing is when reporting started to fail, zero while it works.
|
||||||
|
failing time.Time
|
||||||
|
)
|
||||||
flush := func(ctx context.Context) {
|
flush := func(ctx context.Context) {
|
||||||
|
sent := 0
|
||||||
for len(pending) > 0 {
|
for len(pending) > 0 {
|
||||||
n := min(len(pending), agentapi.MaxResults)
|
n := min(len(pending), agentapi.MaxResults)
|
||||||
if err := r.api.Report(ctx, pending[:n]); err != nil {
|
if err := r.api.Report(ctx, pending[:n]); err != nil {
|
||||||
r.log.Warn("reporting results failed", "error", err, "pending", len(pending))
|
r.log.Warn("reporting results failed", "error", err, "pending", len(pending))
|
||||||
|
if failing.IsZero() {
|
||||||
|
failing = time.Now()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pending = pending[n:]
|
pending, sent = pending[n:], sent+n
|
||||||
|
}
|
||||||
|
if !failing.IsZero() {
|
||||||
|
r.log.Info("reporting results works again", "failed_for", time.Since(failing).Round(time.Second).String(), "sent", sent)
|
||||||
|
failing = time.Time{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package checker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"log/slog"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||||
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/check"
|
||||||
|
)
|
||||||
|
|
||||||
|
// flakyAPI fails its first calls, like an API being rolled out.
|
||||||
|
type flakyAPI struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
jobFails int
|
||||||
|
reportFails int
|
||||||
|
gave bool
|
||||||
|
reported int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *flakyAPI) Jobs(ctx context.Context, _ int, wait time.Duration) ([]agentapi.Job, error) {
|
||||||
|
f.mu.Lock()
|
||||||
|
if f.jobFails > 0 {
|
||||||
|
f.jobFails--
|
||||||
|
f.mu.Unlock()
|
||||||
|
return nil, errors.New("504 Gateway Timeout")
|
||||||
|
}
|
||||||
|
if !f.gave {
|
||||||
|
f.gave = true
|
||||||
|
f.mu.Unlock()
|
||||||
|
return []agentapi.Job{{MonitorID: uuid.New(), Type: "tcp", Target: "x:1"}}, nil
|
||||||
|
}
|
||||||
|
f.mu.Unlock()
|
||||||
|
select {
|
||||||
|
case <-time.After(min(wait, 50*time.Millisecond)):
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *flakyAPI) Report(_ context.Context, rs []agentapi.Result) error {
|
||||||
|
f.mu.Lock()
|
||||||
|
defer f.mu.Unlock()
|
||||||
|
if f.reportFails > 0 {
|
||||||
|
f.reportFails--
|
||||||
|
return errors.New("context deadline exceeded")
|
||||||
|
}
|
||||||
|
f.reported += len(rs)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *flakyAPI) Release(context.Context) error { return nil }
|
||||||
|
|
||||||
|
type syncBuffer struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
b bytes.Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *syncBuffer) Write(p []byte) (int, error) {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
return s.b.Write(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *syncBuffer) String() string {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
return s.b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRecoveryIsLogged(t *testing.T) {
|
||||||
|
api := &flakyAPI{jobFails: 1, reportFails: 1}
|
||||||
|
var logs syncBuffer
|
||||||
|
r := New(api, 2, slog.New(slog.NewJSONHandler(&logs, nil)))
|
||||||
|
r.run = func(context.Context, check.Spec) check.Outcome { return check.Outcome{OK: true} }
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
done := make(chan error, 1)
|
||||||
|
go func() { done <- r.Run(ctx, time.Second) }()
|
||||||
|
|
||||||
|
deadline := time.Now().Add(10 * time.Second)
|
||||||
|
for time.Now().Before(deadline) {
|
||||||
|
out := logs.String()
|
||||||
|
if strings.Contains(out, "polling for jobs works again") && strings.Contains(out, "reporting results works again") {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
}
|
||||||
|
cancel()
|
||||||
|
if err := <-done; err != nil {
|
||||||
|
t.Errorf("Run() = %v", err)
|
||||||
|
}
|
||||||
|
out := logs.String()
|
||||||
|
for _, want := range []string{`"msg":"polling for jobs works again"`, `"failures":1`, `"msg":"reporting results works again"`, `"sent":1`} {
|
||||||
|
if !strings.Contains(out, want) {
|
||||||
|
t.Errorf("log lacks %s:\n%s", want, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if n := strings.Count(out, "works again"); n != 2 {
|
||||||
|
t.Errorf("recovery logged %d times, want once each", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1305,6 +1305,7 @@
|
|||||||
"pages.label": "Öffentlicher Name",
|
"pages.label": "Öffentlicher Name",
|
||||||
"pages.logo": "Logo-URL (https)",
|
"pages.logo": "Logo-URL (https)",
|
||||||
"pages.monitor_limit": "Diese Seite darf höchstens {{.Max}} Monitore zeigen.",
|
"pages.monitor_limit": "Diese Seite darf höchstens {{.Max}} Monitore zeigen.",
|
||||||
|
"pages.monitors_filter": "Monitore filtern",
|
||||||
"pages.monitors_all": "Alle hinzufügen",
|
"pages.monitors_all": "Alle hinzufügen",
|
||||||
"pages.monitors_none": "Alle entfernen",
|
"pages.monitors_none": "Alle entfernen",
|
||||||
"pages.no_group": "Ohne Gruppe",
|
"pages.no_group": "Ohne Gruppe",
|
||||||
|
|||||||
@@ -1305,6 +1305,7 @@
|
|||||||
"pages.label": "Public name",
|
"pages.label": "Public name",
|
||||||
"pages.logo": "Logo URL (https)",
|
"pages.logo": "Logo URL (https)",
|
||||||
"pages.monitor_limit": "This page may show at most {{.Max}} monitors.",
|
"pages.monitor_limit": "This page may show at most {{.Max}} monitors.",
|
||||||
|
"pages.monitors_filter": "Filter monitors",
|
||||||
"pages.monitors_all": "Add all",
|
"pages.monitors_all": "Add all",
|
||||||
"pages.monitors_none": "Remove all",
|
"pages.monitors_none": "Remove all",
|
||||||
"pages.no_group": "No group",
|
"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;
|
||||||
@@ -3,6 +3,7 @@ package platform
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -17,15 +18,24 @@ type Probe func(context.Context) error
|
|||||||
type Health struct {
|
type Health struct {
|
||||||
probes map[string]Probe
|
probes map[string]Probe
|
||||||
draining atomic.Bool
|
draining atomic.Bool
|
||||||
|
drained chan struct{}
|
||||||
|
once sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHealth returns a Health that is ready while all probes pass.
|
// NewHealth returns a Health that is ready while all probes pass.
|
||||||
func NewHealth(probes map[string]Probe) *Health {
|
func NewHealth(probes map[string]Probe) *Health {
|
||||||
return &Health{probes: probes}
|
return &Health{probes: probes, drained: make(chan struct{})}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drain makes /readyz fail permanently. Call it before shutdown.
|
// Drain makes /readyz fail permanently. Call it before shutdown.
|
||||||
func (h *Health) Drain() { h.draining.Store(true) }
|
func (h *Health) Drain() {
|
||||||
|
h.draining.Store(true)
|
||||||
|
h.once.Do(func() { close(h.drained) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draining is closed once Drain is called, so long-running requests can
|
||||||
|
// end early instead of holding up the shutdown.
|
||||||
|
func (h *Health) Draining() <-chan struct{} { return h.drained }
|
||||||
|
|
||||||
// Register mounts /healthz (liveness) and /readyz (readiness).
|
// Register mounts /healthz (liveness) and /readyz (readiness).
|
||||||
func (h *Health) Register(r gin.IRoutes) {
|
func (h *Health) Register(r gin.IRoutes) {
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ const (
|
|||||||
// without asking the API again.
|
// without asking the API again.
|
||||||
missFor = time.Minute
|
missFor = time.Minute
|
||||||
maxMissing = 10_000
|
maxMissing = 10_000
|
||||||
|
// refreshTimeout bounds fetching one page.
|
||||||
|
refreshTimeout = 30 * time.Second
|
||||||
// unknownPerSecond bounds the lookups of hosts and slugs that are
|
// unknownPerSecond bounds the lookups of hosts and slugs that are
|
||||||
// neither cached nor known to be missing, so a flood of made-up names
|
// 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
|
// 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
|
mu sync.Mutex
|
||||||
cache map[string]entry
|
cache map[string]entry
|
||||||
refreshing map[string]bool
|
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 holds when each cached page was last visited.
|
||||||
visited map[string]time.Time
|
visited map[string]time.Time
|
||||||
// missing holds when a key was last found to have no page.
|
// 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) {
|
func New(src Source, catalog *i18n.Catalog, log *slog.Logger, o Options) (*Server, error) {
|
||||||
s := &Server{
|
s := &Server{
|
||||||
src: src, catalog: catalog, log: log, ownHosts: map[string]bool{}, dir: o.CacheDir,
|
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{},
|
missing: map[string]time.Time{},
|
||||||
}
|
}
|
||||||
for _, h := range o.Hosts {
|
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
|
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) {
|
func (s *Server) refresh(ctx context.Context, key, host, slug string) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
if s.refreshing[key] {
|
if s.refreshing[key] {
|
||||||
@@ -428,14 +434,50 @@ func (s *Server) refresh(ctx context.Context, key, host, slug string) {
|
|||||||
}
|
}
|
||||||
s.refreshing[key] = true
|
s.refreshing[key] = true
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
defer func() {
|
for {
|
||||||
|
fctx, cancel := context.WithTimeout(ctx, refreshTimeout)
|
||||||
|
s.fetch(fctx, key, host, slug)
|
||||||
|
cancel()
|
||||||
s.mu.Lock()
|
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()
|
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.
|
// Wait returns once the background refreshes started by visits are done.
|
||||||
|
|||||||
@@ -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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -124,22 +124,65 @@ func (q *Queries) DailyBucketsForMonitors(ctx context.Context, arg DailyBucketsF
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const earliestDataDaily = `-- name: EarliestDataDaily :one
|
||||||
|
SELECT bucket::timestamptz AS first FROM check_results_1d WHERE org_id = $1 ORDER BY bucket LIMIT 1
|
||||||
|
`
|
||||||
|
|
||||||
|
// The day the organization's monitors first reported, if any did.
|
||||||
|
func (q *Queries) EarliestDataDaily(ctx context.Context, orgID uuid.UUID) (time.Time, error) {
|
||||||
|
row := q.db.QueryRow(ctx, earliestDataDaily, orgID)
|
||||||
|
var first time.Time
|
||||||
|
err := row.Scan(&first)
|
||||||
|
return first, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const earliestDataRecent = `-- name: EarliestDataRecent :one
|
||||||
|
SELECT f.time FROM monitors m
|
||||||
|
CROSS JOIN LATERAL (
|
||||||
|
SELECT c.time FROM check_results c
|
||||||
|
WHERE c.org_id = $1 AND c.monitor_id = m.id AND c.time >= $2
|
||||||
|
ORDER BY c.time LIMIT 1
|
||||||
|
) f
|
||||||
|
WHERE m.org_id = $1
|
||||||
|
ORDER BY f.time LIMIT 1
|
||||||
|
`
|
||||||
|
|
||||||
|
type EarliestDataRecentParams struct {
|
||||||
|
OrgID uuid.UUID
|
||||||
|
Time time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// When the organization's monitors first reported since $2, exactly: the
|
||||||
|
// first result of each monitor is found through its index, so the cost
|
||||||
|
// does not grow with the days of results.
|
||||||
|
func (q *Queries) EarliestDataRecent(ctx context.Context, arg EarliestDataRecentParams) (time.Time, error) {
|
||||||
|
row := q.db.QueryRow(ctx, earliestDataRecent, arg.OrgID, arg.Time)
|
||||||
|
var time time.Time
|
||||||
|
err := row.Scan(&time)
|
||||||
|
return time, err
|
||||||
|
}
|
||||||
|
|
||||||
const firstDataDaily = `-- name: FirstDataDaily :many
|
const firstDataDaily = `-- name: FirstDataDaily :many
|
||||||
SELECT monitor_id, region, min(bucket)::timestamptz AS first
|
SELECT monitor_id, region, min(bucket)::timestamptz AS first
|
||||||
FROM check_results_1d
|
FROM check_results_1d
|
||||||
WHERE org_id = $1
|
WHERE org_id = $1 AND monitor_id = $2
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
|
type FirstDataDailyParams struct {
|
||||||
|
OrgID uuid.UUID
|
||||||
|
MonitorID uuid.UUID
|
||||||
|
}
|
||||||
|
|
||||||
type FirstDataDailyRow struct {
|
type FirstDataDailyRow struct {
|
||||||
MonitorID uuid.UUID
|
MonitorID uuid.UUID
|
||||||
Region string
|
Region string
|
||||||
First time.Time
|
First time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// When each monitor and region first reported, to the day.
|
// When each region of a monitor first reported, to the day.
|
||||||
func (q *Queries) FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstDataDailyRow, error) {
|
func (q *Queries) FirstDataDaily(ctx context.Context, arg FirstDataDailyParams) ([]FirstDataDailyRow, error) {
|
||||||
rows, err := q.db.Query(ctx, firstDataDaily, orgID)
|
rows, err := q.db.Query(ctx, firstDataDaily, arg.OrgID, arg.MonitorID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -161,13 +204,14 @@ func (q *Queries) FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstD
|
|||||||
const firstDataRecent = `-- name: FirstDataRecent :many
|
const firstDataRecent = `-- name: FirstDataRecent :many
|
||||||
SELECT monitor_id, region, min(time)::timestamptz AS first
|
SELECT monitor_id, region, min(time)::timestamptz AS first
|
||||||
FROM check_results
|
FROM check_results
|
||||||
WHERE org_id = $1 AND time >= $2
|
WHERE org_id = $1 AND monitor_id = $2 AND time >= $3
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
type FirstDataRecentParams struct {
|
type FirstDataRecentParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Time time.Time
|
MonitorID uuid.UUID
|
||||||
|
Time time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type FirstDataRecentRow struct {
|
type FirstDataRecentRow struct {
|
||||||
@@ -176,10 +220,10 @@ type FirstDataRecentRow struct {
|
|||||||
First time.Time
|
First time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// When each monitor and region first reported since $2, exactly. Used for
|
// When each region of a monitor first reported since $3, exactly. Used for
|
||||||
// data younger than the daily aggregate's resolution.
|
// data younger than the daily aggregate's resolution.
|
||||||
func (q *Queries) FirstDataRecent(ctx context.Context, arg FirstDataRecentParams) ([]FirstDataRecentRow, error) {
|
func (q *Queries) FirstDataRecent(ctx context.Context, arg FirstDataRecentParams) ([]FirstDataRecentRow, error) {
|
||||||
rows, err := q.db.Query(ctx, firstDataRecent, arg.OrgID, arg.Time)
|
rows, err := q.db.Query(ctx, firstDataRecent, arg.OrgID, arg.MonitorID, arg.Time)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -203,6 +247,7 @@ SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, s
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1h
|
FROM check_results_1h
|
||||||
WHERE org_id = $1 AND bucket >= $2
|
WHERE org_id = $1 AND bucket >= $2
|
||||||
|
AND ($3::uuid[] IS NULL OR monitor_id = ANY ($3::uuid[]))
|
||||||
GROUP BY monitor_id, bucket
|
GROUP BY monitor_id, bucket
|
||||||
ORDER BY monitor_id, bucket
|
ORDER BY monitor_id, bucket
|
||||||
`
|
`
|
||||||
@@ -210,6 +255,7 @@ ORDER BY monitor_id, bucket
|
|||||||
type HourlyBucketsParams struct {
|
type HourlyBucketsParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Bucket interface{}
|
Bucket interface{}
|
||||||
|
Ids []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type HourlyBucketsRow struct {
|
type HourlyBucketsRow struct {
|
||||||
@@ -222,7 +268,7 @@ type HourlyBucketsRow struct {
|
|||||||
|
|
||||||
// Per monitor and hour since $2, across all regions.
|
// Per monitor and hour since $2, across all regions.
|
||||||
func (q *Queries) HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error) {
|
func (q *Queries) HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error) {
|
||||||
rows, err := q.db.Query(ctx, hourlyBuckets, arg.OrgID, arg.Bucket)
|
rows, err := q.db.Query(ctx, hourlyBuckets, arg.OrgID, arg.Bucket, arg.Ids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -259,52 +305,6 @@ type InsertCheckResultsParams struct {
|
|||||||
Error *string
|
Error *string
|
||||||
}
|
}
|
||||||
|
|
||||||
const latestResults = `-- name: LatestResults :many
|
|
||||||
SELECT DISTINCT ON (monitor_id, region) monitor_id, region, time, ok, latency_ms, status_code, error
|
|
||||||
FROM check_results
|
|
||||||
WHERE org_id = $1 AND time > now() - interval '1 day'
|
|
||||||
ORDER BY monitor_id, region, time DESC
|
|
||||||
`
|
|
||||||
|
|
||||||
type LatestResultsRow struct {
|
|
||||||
MonitorID uuid.UUID
|
|
||||||
Region string
|
|
||||||
Time time.Time
|
|
||||||
Ok bool
|
|
||||||
LatencyMs *int32
|
|
||||||
StatusCode *int32
|
|
||||||
Error *string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Newest result per monitor and region in the org.
|
|
||||||
func (q *Queries) LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error) {
|
|
||||||
rows, err := q.db.Query(ctx, latestResults, orgID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
items := []LatestResultsRow{}
|
|
||||||
for rows.Next() {
|
|
||||||
var i LatestResultsRow
|
|
||||||
if err := rows.Scan(
|
|
||||||
&i.MonitorID,
|
|
||||||
&i.Region,
|
|
||||||
&i.Time,
|
|
||||||
&i.Ok,
|
|
||||||
&i.LatencyMs,
|
|
||||||
&i.StatusCode,
|
|
||||||
&i.Error,
|
|
||||||
); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
items = append(items, i)
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return items, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const latestResultsForMonitor = `-- name: LatestResultsForMonitor :many
|
const latestResultsForMonitor = `-- name: LatestResultsForMonitor :many
|
||||||
SELECT DISTINCT ON (region) region, ok, error
|
SELECT DISTINCT ON (region) region, ok, error
|
||||||
FROM check_results
|
FROM check_results
|
||||||
@@ -425,16 +425,16 @@ SELECT monitor_id, time_bucket($2::text::interval, time)::timestamptz AS bucket,
|
|||||||
coalesce(avg(latency_ms), 0)::real AS avg_latency_ms
|
coalesce(avg(latency_ms), 0)::real AS avg_latency_ms
|
||||||
FROM check_results
|
FROM check_results
|
||||||
WHERE org_id = $1 AND time >= $3
|
WHERE org_id = $1 AND time >= $3
|
||||||
AND ($4::uuid IS NULL OR monitor_id = $4)
|
AND monitor_id = ANY ($4::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2
|
ORDER BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
type RangeBucketsParams struct {
|
type RangeBucketsParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Width string
|
Width string
|
||||||
Since time.Time
|
Since time.Time
|
||||||
MonitorID *uuid.UUID
|
Ids []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type RangeBucketsRow struct {
|
type RangeBucketsRow struct {
|
||||||
@@ -451,7 +451,7 @@ func (q *Queries) RangeBuckets(ctx context.Context, arg RangeBucketsParams) ([]R
|
|||||||
arg.OrgID,
|
arg.OrgID,
|
||||||
arg.Width,
|
arg.Width,
|
||||||
arg.Since,
|
arg.Since,
|
||||||
arg.MonitorID,
|
arg.Ids,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -483,16 +483,16 @@ SELECT monitor_id, time_bucket($2::text::interval, bucket)::timestamptz AS bucke
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1d
|
FROM check_results_1d
|
||||||
WHERE org_id = $1 AND bucket >= $3
|
WHERE org_id = $1 AND bucket >= $3
|
||||||
AND ($4::uuid IS NULL OR monitor_id = $4)
|
AND monitor_id = ANY ($4::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2
|
ORDER BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
type RangeBucketsDailyParams struct {
|
type RangeBucketsDailyParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Width string
|
Width string
|
||||||
Since interface{}
|
Since interface{}
|
||||||
MonitorID *uuid.UUID
|
Ids []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type RangeBucketsDailyRow struct {
|
type RangeBucketsDailyRow struct {
|
||||||
@@ -509,7 +509,7 @@ func (q *Queries) RangeBucketsDaily(ctx context.Context, arg RangeBucketsDailyPa
|
|||||||
arg.OrgID,
|
arg.OrgID,
|
||||||
arg.Width,
|
arg.Width,
|
||||||
arg.Since,
|
arg.Since,
|
||||||
arg.MonitorID,
|
arg.Ids,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -541,16 +541,16 @@ SELECT monitor_id, time_bucket($2::text::interval, bucket)::timestamptz AS bucke
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1h
|
FROM check_results_1h
|
||||||
WHERE org_id = $1 AND bucket >= $3
|
WHERE org_id = $1 AND bucket >= $3
|
||||||
AND ($4::uuid IS NULL OR monitor_id = $4)
|
AND monitor_id = ANY ($4::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2
|
ORDER BY 1, 2
|
||||||
`
|
`
|
||||||
|
|
||||||
type RangeBucketsHourlyParams struct {
|
type RangeBucketsHourlyParams struct {
|
||||||
OrgID uuid.UUID
|
OrgID uuid.UUID
|
||||||
Width string
|
Width string
|
||||||
Since interface{}
|
Since interface{}
|
||||||
MonitorID *uuid.UUID
|
Ids []uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
type RangeBucketsHourlyRow struct {
|
type RangeBucketsHourlyRow struct {
|
||||||
@@ -567,7 +567,7 @@ func (q *Queries) RangeBucketsHourly(ctx context.Context, arg RangeBucketsHourly
|
|||||||
arg.OrgID,
|
arg.OrgID,
|
||||||
arg.Width,
|
arg.Width,
|
||||||
arg.Since,
|
arg.Since,
|
||||||
arg.MonitorID,
|
arg.Ids,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -271,18 +271,19 @@ func (q *Queries) GetIncident(ctx context.Context, id uuid.UUID) (GetIncidentRow
|
|||||||
|
|
||||||
const incidentsForMonitors = `-- name: IncidentsForMonitors :many
|
const incidentsForMonitors = `-- name: IncidentsForMonitors :many
|
||||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id FROM incidents
|
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
|
ORDER BY started_at DESC
|
||||||
LIMIT 50
|
LIMIT 50
|
||||||
`
|
`
|
||||||
|
|
||||||
type IncidentsForMonitorsParams struct {
|
type IncidentsForMonitorsParams struct {
|
||||||
|
OrgID uuid.UUID
|
||||||
Ids []uuid.UUID
|
Ids []uuid.UUID
|
||||||
Since *time.Time
|
Since *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) IncidentsForMonitors(ctx context.Context, arg IncidentsForMonitorsParams) ([]Incident, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -313,18 +314,23 @@ func (q *Queries) IncidentsForMonitors(ctx context.Context, arg IncidentsForMoni
|
|||||||
|
|
||||||
const incidentsSince = `-- name: IncidentsSince :many
|
const incidentsSince = `-- name: IncidentsSince :many
|
||||||
SELECT monitor_id, started_at, resolved_at FROM incidents
|
SELECT monitor_id, started_at, resolved_at FROM incidents
|
||||||
WHERE resolved_at IS NULL OR resolved_at > $1
|
WHERE org_id = $1 AND (resolved_at IS NULL OR resolved_at > $2)
|
||||||
`
|
`
|
||||||
|
|
||||||
|
type IncidentsSinceParams struct {
|
||||||
|
OrgID uuid.UUID
|
||||||
|
ResolvedAt *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type IncidentsSinceRow struct {
|
type IncidentsSinceRow struct {
|
||||||
MonitorID uuid.UUID
|
MonitorID uuid.UUID
|
||||||
StartedAt time.Time
|
StartedAt time.Time
|
||||||
ResolvedAt *time.Time
|
ResolvedAt *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incidents overlapping the time since $1, for SLA calculation.
|
// Incidents overlapping the time since $2, for SLA calculation.
|
||||||
func (q *Queries) IncidentsSince(ctx context.Context, resolvedAt *time.Time) ([]IncidentsSinceRow, error) {
|
func (q *Queries) IncidentsSince(ctx context.Context, arg IncidentsSinceParams) ([]IncidentsSinceRow, error) {
|
||||||
rows, err := q.db.Query(ctx, incidentsSince, resolvedAt)
|
rows, err := q.db.Query(ctx, incidentsSince, arg.OrgID, arg.ResolvedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -672,11 +678,11 @@ func (q *Queries) OpenIncident(ctx context.Context, arg OpenIncidentParams) (Inc
|
|||||||
}
|
}
|
||||||
|
|
||||||
const openIncidents = `-- name: OpenIncidents :many
|
const openIncidents = `-- name: OpenIncidents :many
|
||||||
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id FROM incidents WHERE resolved_at IS NULL
|
SELECT id, org_id, monitor_id, started_at, resolved_at, cause, title, status, status_id FROM incidents WHERE org_id = $1 AND resolved_at IS NULL
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) OpenIncidents(ctx context.Context) ([]Incident, error) {
|
func (q *Queries) OpenIncidents(ctx context.Context, orgID uuid.UUID) ([]Incident, error) {
|
||||||
rows, err := q.db.Query(ctx, openIncidents)
|
rows, err := q.db.Query(ctx, openIncidents, orgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,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
|
||||||
|
}
|
||||||
@@ -197,6 +197,17 @@ type Invitation struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LatestResult struct {
|
||||||
|
MonitorID uuid.UUID
|
||||||
|
Region string
|
||||||
|
OrgID uuid.UUID
|
||||||
|
Time time.Time
|
||||||
|
Ok bool
|
||||||
|
LatencyMs *int32
|
||||||
|
StatusCode *int32
|
||||||
|
Error *string
|
||||||
|
}
|
||||||
|
|
||||||
type LegalAcceptance struct {
|
type LegalAcceptance struct {
|
||||||
UserID uuid.UUID
|
UserID uuid.UUID
|
||||||
Kind string
|
Kind string
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (q *Queries) AddMonitorRegion(ctx context.Context, arg AddMonitorRegionPara
|
|||||||
}
|
}
|
||||||
|
|
||||||
const allMonitorRegions = `-- name: AllMonitorRegions :many
|
const allMonitorRegions = `-- name: AllMonitorRegions :many
|
||||||
SELECT monitor_id, region_id FROM monitor_regions
|
SELECT monitor_id, region_id FROM monitor_regions WHERE org_id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
type AllMonitorRegionsRow struct {
|
type AllMonitorRegionsRow struct {
|
||||||
@@ -35,8 +35,8 @@ type AllMonitorRegionsRow struct {
|
|||||||
RegionID uuid.UUID
|
RegionID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow, error) {
|
func (q *Queries) AllMonitorRegions(ctx context.Context, orgID uuid.UUID) ([]AllMonitorRegionsRow, error) {
|
||||||
rows, err := q.db.Query(ctx, allMonitorRegions)
|
rows, err := q.db.Query(ctx, allMonitorRegions, orgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -192,11 +192,12 @@ func (q *Queries) ListEnabledMonitorsForSchedule(ctx context.Context) ([]ListEna
|
|||||||
}
|
}
|
||||||
|
|
||||||
const listMonitors = `-- name: ListMonitors :many
|
const listMonitors = `-- name: ListMonitors :many
|
||||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id, 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) {
|
// The org filter, though row security implies it, lets the index be used.
|
||||||
rows, err := q.db.Query(ctx, listMonitors)
|
func (q *Queries) ListMonitors(ctx context.Context, orgID uuid.UUID) ([]Monitor, error) {
|
||||||
|
rows, err := q.db.Query(ctx, listMonitors, orgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ type Querier interface {
|
|||||||
// System scope: the receiver a webhook token belongs to.
|
// System scope: the receiver a webhook token belongs to.
|
||||||
AlertmanagerReceiverByHash(ctx context.Context, tokenHash []byte) (AlertmanagerReceiverByHashRow, error)
|
AlertmanagerReceiverByHash(ctx context.Context, tokenHash []byte) (AlertmanagerReceiverByHashRow, error)
|
||||||
AllMonitorAlertGroups(ctx context.Context) ([]MonitorAlertGroup, error)
|
AllMonitorAlertGroups(ctx context.Context) ([]MonitorAlertGroup, error)
|
||||||
AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow, error)
|
AllMonitorRegions(ctx context.Context, orgID uuid.UUID) ([]AllMonitorRegionsRow, error)
|
||||||
AnyUserExists(ctx context.Context) (bool, error)
|
AnyUserExists(ctx context.Context) (bool, error)
|
||||||
// How much one instance checked for the organization in the last hour.
|
// How much one instance checked for the organization in the last hour.
|
||||||
CheckerStats(ctx context.Context, arg CheckerStatsParams) (CheckerStatsRow, error)
|
CheckerStats(ctx context.Context, arg CheckerStatsParams) (CheckerStatsRow, error)
|
||||||
@@ -124,6 +124,12 @@ type Querier interface {
|
|||||||
// for two days, after which only the verify button tries again. A verified
|
// for two days, after which only the verify button tries again. A verified
|
||||||
// one is checked daily, hourly once its record went missing.
|
// one is checked daily, hourly once its record went missing.
|
||||||
DomainsToCheck(ctx context.Context, arg DomainsToCheckParams) ([]DomainsToCheckRow, error)
|
DomainsToCheck(ctx context.Context, arg DomainsToCheckParams) ([]DomainsToCheckRow, error)
|
||||||
|
// The day the organization's monitors first reported, if any did.
|
||||||
|
EarliestDataDaily(ctx context.Context, orgID uuid.UUID) (time.Time, error)
|
||||||
|
// When the organization's monitors first reported since $2, exactly: the
|
||||||
|
// first result of each monitor is found through its index, so the cost
|
||||||
|
// does not grow with the days of results.
|
||||||
|
EarliestDataRecent(ctx context.Context, arg EarliestDataRecentParams) (time.Time, error)
|
||||||
EmailKeyTaken(ctx context.Context, emailKey *string) (bool, error)
|
EmailKeyTaken(ctx context.Context, emailKey *string) (bool, error)
|
||||||
EnableTOTP(ctx context.Context, arg EnableTOTPParams) error
|
EnableTOTP(ctx context.Context, arg EnableTOTPParams) error
|
||||||
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
|
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
|
||||||
@@ -139,9 +145,9 @@ type Querier interface {
|
|||||||
// FiringAlerts newest first, a page from a keyset cursor (see paging.go)
|
// FiringAlerts newest first, a page from a keyset cursor (see paging.go)
|
||||||
// whose string key is the fingerprint.
|
// whose string key is the fingerprint.
|
||||||
FiringAlertsPage(ctx context.Context, arg FiringAlertsPageParams) ([]FiringAlertsPageRow, error)
|
FiringAlertsPage(ctx context.Context, arg FiringAlertsPageParams) ([]FiringAlertsPageRow, error)
|
||||||
// When each monitor and region first reported, to the day.
|
// When each region of a monitor first reported, to the day.
|
||||||
FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstDataDailyRow, error)
|
FirstDataDaily(ctx context.Context, arg FirstDataDailyParams) ([]FirstDataDailyRow, error)
|
||||||
// When each monitor and region first reported since $2, exactly. Used for
|
// When each region of a monitor first reported since $3, exactly. Used for
|
||||||
// data younger than the daily aggregate's resolution.
|
// data younger than the daily aggregate's resolution.
|
||||||
FirstDataRecent(ctx context.Context, arg FirstDataRecentParams) ([]FirstDataRecentRow, error)
|
FirstDataRecent(ctx context.Context, arg FirstDataRecentParams) ([]FirstDataRecentRow, error)
|
||||||
// Keeps organization and platform entries readable as "deleted user" but
|
// Keeps organization and platform entries readable as "deleted user" but
|
||||||
@@ -184,8 +190,8 @@ type Querier interface {
|
|||||||
// Per monitor and hour since $2, across all regions.
|
// Per monitor and hour since $2, across all regions.
|
||||||
HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error)
|
HourlyBuckets(ctx context.Context, arg HourlyBucketsParams) ([]HourlyBucketsRow, error)
|
||||||
IncidentsForMonitors(ctx context.Context, arg IncidentsForMonitorsParams) ([]Incident, error)
|
IncidentsForMonitors(ctx context.Context, arg IncidentsForMonitorsParams) ([]Incident, error)
|
||||||
// Incidents overlapping the time since $1, for SLA calculation.
|
// Incidents overlapping the time since $2, for SLA calculation.
|
||||||
IncidentsSince(ctx context.Context, resolvedAt *time.Time) ([]IncidentsSinceRow, error)
|
IncidentsSince(ctx context.Context, arg IncidentsSinceParams) ([]IncidentsSinceRow, error)
|
||||||
InsertAuditEvent(ctx context.Context, arg InsertAuditEventParams) error
|
InsertAuditEvent(ctx context.Context, arg InsertAuditEventParams) error
|
||||||
// check_results and its aggregates have no row-level security (see
|
// check_results and its aggregates have no row-level security (see
|
||||||
// migration 00013). Every query here must filter by org_id.
|
// migration 00013). Every query here must filter by org_id.
|
||||||
@@ -195,10 +201,16 @@ type Querier interface {
|
|||||||
InvitationOrg(ctx context.Context, hash []byte) (uuid.UUID, error)
|
InvitationOrg(ctx context.Context, hash []byte) (uuid.UUID, error)
|
||||||
IsMember(ctx context.Context, arg IsMemberParams) (bool, error)
|
IsMember(ctx context.Context, arg IsMemberParams) (bool, error)
|
||||||
LastFailureEvidence(ctx context.Context, arg LastFailureEvidenceParams) (LastFailureEvidenceRow, error)
|
LastFailureEvidence(ctx context.Context, arg LastFailureEvidenceParams) (LastFailureEvidenceRow, error)
|
||||||
|
// 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)
|
LatestResultForMonitor(ctx context.Context, arg LatestResultForMonitorParams) (LatestResultForMonitorRow, error)
|
||||||
// Newest result per monitor and region in the org.
|
// Newest result per monitor and region in the org, of the last day.
|
||||||
LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error)
|
LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestResultsRow, error)
|
||||||
LatestResultsForMonitor(ctx context.Context, arg LatestResultsForMonitorParams) ([]LatestResultsForMonitorRow, error)
|
LatestResultsForMonitor(ctx context.Context, arg LatestResultsForMonitorParams) ([]LatestResultsForMonitorRow, error)
|
||||||
|
// LatestResults limited to the monitors ids.
|
||||||
|
LatestResultsForMonitors(ctx context.Context, arg LatestResultsForMonitorsParams) ([]LatestResultsForMonitorsRow, error)
|
||||||
LegalAcceptances(ctx context.Context, userID uuid.UUID) ([]LegalAcceptancesRow, error)
|
LegalAcceptances(ctx context.Context, userID uuid.UUID) ([]LegalAcceptancesRow, error)
|
||||||
// The organization's documents and the platform's, organization first.
|
// The organization's documents and the platform's, organization first.
|
||||||
LegalDocuments(ctx context.Context, orgID *uuid.UUID) ([]LegalDocument, error)
|
LegalDocuments(ctx context.Context, orgID *uuid.UUID) ([]LegalDocument, error)
|
||||||
@@ -229,7 +241,8 @@ type Querier interface {
|
|||||||
// Latest start first, a page from a keyset cursor (see paging.go).
|
// Latest start first, a page from a keyset cursor (see paging.go).
|
||||||
ListMaintenancePage(ctx context.Context, arg ListMaintenancePageParams) ([]MaintenanceWindow, error)
|
ListMaintenancePage(ctx context.Context, arg ListMaintenancePageParams) ([]MaintenanceWindow, error)
|
||||||
ListMaintenanceTargets(ctx context.Context) ([]MaintenanceTarget, error)
|
ListMaintenanceTargets(ctx context.Context) ([]MaintenanceTarget, error)
|
||||||
ListMonitors(ctx context.Context) ([]Monitor, error)
|
// The org filter, though row security implies it, lets the index be used.
|
||||||
|
ListMonitors(ctx context.Context, orgID uuid.UUID) ([]Monitor, error)
|
||||||
// By name, a page from a keyset cursor (see paging.go).
|
// By name, a page from a keyset cursor (see paging.go).
|
||||||
ListMonitorsPage(ctx context.Context, arg ListMonitorsPageParams) ([]Monitor, error)
|
ListMonitorsPage(ctx context.Context, arg ListMonitorsPageParams) ([]Monitor, error)
|
||||||
ListOrgMembers(ctx context.Context, orgID uuid.UUID) ([]ListOrgMembersRow, error)
|
ListOrgMembers(ctx context.Context, orgID uuid.UUID) ([]ListOrgMembersRow, error)
|
||||||
@@ -291,7 +304,7 @@ type Querier interface {
|
|||||||
// System scope.
|
// System scope.
|
||||||
NotificationDetails(ctx context.Context, ids []uuid.UUID) ([]NotificationDetailsRow, error)
|
NotificationDetails(ctx context.Context, ids []uuid.UUID) ([]NotificationDetailsRow, error)
|
||||||
OpenIncident(ctx context.Context, arg OpenIncidentParams) (Incident, error)
|
OpenIncident(ctx context.Context, arg OpenIncidentParams) (Incident, error)
|
||||||
OpenIncidents(ctx context.Context) ([]Incident, error)
|
OpenIncidents(ctx context.Context, orgID uuid.UUID) ([]Incident, error)
|
||||||
OrgAssignmentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgAssignmentsExportRow, error)
|
OrgAssignmentsExport(ctx context.Context, orgID uuid.UUID) ([]OrgAssignmentsExportRow, error)
|
||||||
OrgAuditExport(ctx context.Context, orgID uuid.UUID) ([]OrgAuditExportRow, error)
|
OrgAuditExport(ctx context.Context, orgID uuid.UUID) ([]OrgAuditExportRow, error)
|
||||||
OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDailyStatsRow, error)
|
OrgDailyStats(ctx context.Context, orgID uuid.UUID) ([]OrgDailyStatsRow, error)
|
||||||
@@ -417,6 +430,10 @@ type Querier interface {
|
|||||||
UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error)
|
UpdateStatusPage(ctx context.Context, arg UpdateStatusPageParams) (StatusPage, error)
|
||||||
UpdateStatusPageGroup(ctx context.Context, arg UpdateStatusPageGroupParams) (StatusPageGroup, error)
|
UpdateStatusPageGroup(ctx context.Context, arg UpdateStatusPageGroupParams) (StatusPageGroup, error)
|
||||||
UpsertAlertmanagerAlert(ctx context.Context, arg UpsertAlertmanagerAlertParams) error
|
UpsertAlertmanagerAlert(ctx context.Context, arg UpsertAlertmanagerAlertParams) error
|
||||||
|
// 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
|
// A new version starts when the document is created or when the edit asks
|
||||||
// everyone to accept it again.
|
// everyone to accept it again.
|
||||||
UpsertLegalDocument(ctx context.Context, arg UpsertLegalDocumentParams) error
|
UpsertLegalDocument(ctx context.Context, arg UpsertLegalDocumentParams) error
|
||||||
|
|||||||
@@ -5,13 +5,6 @@
|
|||||||
INSERT INTO check_results (time, org_id, monitor_id, region, checker_id, ok, latency_ms, status_code, error)
|
INSERT INTO check_results (time, org_id, monitor_id, region, checker_id, ok, latency_ms, status_code, error)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
||||||
|
|
||||||
-- name: LatestResults :many
|
|
||||||
-- Newest result per monitor and region in the org.
|
|
||||||
SELECT DISTINCT ON (monitor_id, region) monitor_id, region, time, ok, latency_ms, status_code, error
|
|
||||||
FROM check_results
|
|
||||||
WHERE org_id = $1 AND time > now() - interval '1 day'
|
|
||||||
ORDER BY monitor_id, region, time DESC;
|
|
||||||
|
|
||||||
-- name: ListResults :many
|
-- name: ListResults :many
|
||||||
-- A monitor's results newest first, a page from a keyset cursor (see
|
-- A monitor's results newest first, a page from a keyset cursor (see
|
||||||
-- paging.go) whose string key is region and checker.
|
-- paging.go) whose string key is region and checker.
|
||||||
@@ -49,6 +42,7 @@ SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, s
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1h
|
FROM check_results_1h
|
||||||
WHERE org_id = $1 AND bucket >= $2
|
WHERE org_id = $1 AND bucket >= $2
|
||||||
|
AND (sqlc.narg(ids)::uuid[] IS NULL OR monitor_id = ANY (sqlc.narg(ids)::uuid[]))
|
||||||
GROUP BY monitor_id, bucket
|
GROUP BY monitor_id, bucket
|
||||||
ORDER BY monitor_id, bucket;
|
ORDER BY monitor_id, bucket;
|
||||||
|
|
||||||
@@ -73,7 +67,7 @@ SELECT monitor_id, time_bucket(sqlc.arg(width)::text::interval, time)::timestamp
|
|||||||
coalesce(avg(latency_ms), 0)::real AS avg_latency_ms
|
coalesce(avg(latency_ms), 0)::real AS avg_latency_ms
|
||||||
FROM check_results
|
FROM check_results
|
||||||
WHERE org_id = $1 AND time >= sqlc.arg(since)
|
WHERE org_id = $1 AND time >= sqlc.arg(since)
|
||||||
AND (sqlc.narg(monitor_id)::uuid IS NULL OR monitor_id = sqlc.narg(monitor_id))
|
AND monitor_id = ANY (sqlc.arg(ids)::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2;
|
ORDER BY 1, 2;
|
||||||
|
|
||||||
@@ -84,7 +78,7 @@ SELECT monitor_id, time_bucket(sqlc.arg(width)::text::interval, bucket)::timesta
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1h
|
FROM check_results_1h
|
||||||
WHERE org_id = $1 AND bucket >= sqlc.arg(since)
|
WHERE org_id = $1 AND bucket >= sqlc.arg(since)
|
||||||
AND (sqlc.narg(monitor_id)::uuid IS NULL OR monitor_id = sqlc.narg(monitor_id))
|
AND monitor_id = ANY (sqlc.arg(ids)::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2;
|
ORDER BY 1, 2;
|
||||||
|
|
||||||
@@ -95,7 +89,7 @@ SELECT monitor_id, time_bucket(sqlc.arg(width)::text::interval, bucket)::timesta
|
|||||||
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
coalesce(sum(avg_latency_ms * total) / nullif(sum(total), 0), 0)::real AS avg_latency_ms
|
||||||
FROM check_results_1d
|
FROM check_results_1d
|
||||||
WHERE org_id = $1 AND bucket >= sqlc.arg(since)
|
WHERE org_id = $1 AND bucket >= sqlc.arg(since)
|
||||||
AND (sqlc.narg(monitor_id)::uuid IS NULL OR monitor_id = sqlc.narg(monitor_id))
|
AND monitor_id = ANY (sqlc.arg(ids)::uuid[])
|
||||||
GROUP BY 1, 2
|
GROUP BY 1, 2
|
||||||
ORDER BY 1, 2;
|
ORDER BY 1, 2;
|
||||||
|
|
||||||
@@ -125,18 +119,35 @@ GROUP BY 1, 2
|
|||||||
ORDER BY 1, 2;
|
ORDER BY 1, 2;
|
||||||
|
|
||||||
-- name: FirstDataDaily :many
|
-- name: FirstDataDaily :many
|
||||||
-- When each monitor and region first reported, to the day.
|
-- When each region of a monitor first reported, to the day.
|
||||||
SELECT monitor_id, region, min(bucket)::timestamptz AS first
|
SELECT monitor_id, region, min(bucket)::timestamptz AS first
|
||||||
FROM check_results_1d
|
FROM check_results_1d
|
||||||
WHERE org_id = $1
|
WHERE org_id = $1 AND monitor_id = $2
|
||||||
GROUP BY 1, 2;
|
GROUP BY 1, 2;
|
||||||
|
|
||||||
|
-- name: EarliestDataDaily :one
|
||||||
|
-- The day the organization's monitors first reported, if any did.
|
||||||
|
SELECT bucket::timestamptz AS first FROM check_results_1d WHERE org_id = $1 ORDER BY bucket LIMIT 1;
|
||||||
|
|
||||||
|
-- name: EarliestDataRecent :one
|
||||||
|
-- When the organization's monitors first reported since $2, exactly: the
|
||||||
|
-- first result of each monitor is found through its index, so the cost
|
||||||
|
-- does not grow with the days of results.
|
||||||
|
SELECT f.time FROM monitors m
|
||||||
|
CROSS JOIN LATERAL (
|
||||||
|
SELECT c.time FROM check_results c
|
||||||
|
WHERE c.org_id = $1 AND c.monitor_id = m.id AND c.time >= $2
|
||||||
|
ORDER BY c.time LIMIT 1
|
||||||
|
) f
|
||||||
|
WHERE m.org_id = $1
|
||||||
|
ORDER BY f.time LIMIT 1;
|
||||||
|
|
||||||
-- name: FirstDataRecent :many
|
-- name: FirstDataRecent :many
|
||||||
-- When each monitor and region first reported since $2, exactly. Used for
|
-- When each region of a monitor first reported since $3, exactly. Used for
|
||||||
-- data younger than the daily aggregate's resolution.
|
-- data younger than the daily aggregate's resolution.
|
||||||
SELECT monitor_id, region, min(time)::timestamptz AS first
|
SELECT monitor_id, region, min(time)::timestamptz AS first
|
||||||
FROM check_results
|
FROM check_results
|
||||||
WHERE org_id = $1 AND time >= $2
|
WHERE org_id = $1 AND monitor_id = $2 AND time >= $3
|
||||||
GROUP BY 1, 2;
|
GROUP BY 1, 2;
|
||||||
|
|
||||||
-- name: ResultsByChecker :many
|
-- name: ResultsByChecker :many
|
||||||
|
|||||||
@@ -84,18 +84,18 @@ SELECT * FROM notification_channels ORDER BY name;
|
|||||||
DELETE FROM notification_channels WHERE id = $1;
|
DELETE FROM notification_channels WHERE id = $1;
|
||||||
|
|
||||||
-- name: OpenIncidents :many
|
-- name: OpenIncidents :many
|
||||||
SELECT * FROM incidents WHERE resolved_at IS NULL;
|
SELECT * FROM incidents WHERE org_id = $1 AND resolved_at IS NULL;
|
||||||
|
|
||||||
-- name: IncidentsForMonitors :many
|
-- name: IncidentsForMonitors :many
|
||||||
SELECT * FROM incidents
|
SELECT * FROM incidents
|
||||||
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
|
ORDER BY started_at DESC
|
||||||
LIMIT 50;
|
LIMIT 50;
|
||||||
|
|
||||||
-- name: IncidentsSince :many
|
-- name: IncidentsSince :many
|
||||||
-- Incidents overlapping the time since $1, for SLA calculation.
|
-- Incidents overlapping the time since $2, for SLA calculation.
|
||||||
SELECT monitor_id, started_at, resolved_at FROM incidents
|
SELECT monitor_id, started_at, resolved_at FROM incidents
|
||||||
WHERE resolved_at IS NULL OR resolved_at > $1;
|
WHERE org_id = $1 AND (resolved_at IS NULL OR resolved_at > $2);
|
||||||
|
|
||||||
-- name: GetIncident :one
|
-- name: GetIncident :one
|
||||||
SELECT i.*, m.name AS monitor_name, m.group_id AS monitor_group_id
|
SELECT i.*, m.name AS monitor_name, m.group_id AS monitor_group_id
|
||||||
|
|||||||
@@ -0,0 +1,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';
|
||||||
@@ -16,13 +16,14 @@ DELETE FROM monitors WHERE id = $1;
|
|||||||
SELECT * FROM monitors WHERE id = $1;
|
SELECT * FROM monitors WHERE id = $1;
|
||||||
|
|
||||||
-- name: ListMonitors :many
|
-- name: ListMonitors :many
|
||||||
SELECT * FROM monitors ORDER BY name;
|
-- The org filter, though row security implies it, lets the index be used.
|
||||||
|
SELECT * FROM monitors WHERE org_id = $1 ORDER BY name;
|
||||||
|
|
||||||
-- name: MonitorRegions :many
|
-- name: MonitorRegions :many
|
||||||
SELECT region_id FROM monitor_regions WHERE monitor_id = $1 ORDER BY region_id;
|
SELECT region_id FROM monitor_regions WHERE monitor_id = $1 ORDER BY region_id;
|
||||||
|
|
||||||
-- name: AllMonitorRegions :many
|
-- name: AllMonitorRegions :many
|
||||||
SELECT monitor_id, region_id FROM monitor_regions;
|
SELECT monitor_id, region_id FROM monitor_regions WHERE org_id = $1;
|
||||||
|
|
||||||
-- name: DeleteMonitorRegions :exec
|
-- name: DeleteMonitorRegions :exec
|
||||||
DELETE FROM monitor_regions WHERE monitor_id = $1;
|
DELETE FROM monitor_regions WHERE monitor_id = $1;
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ WHERE published AND suspended_at IS NULL
|
|||||||
-- System scope: the published pages a status page server serves, those
|
-- System scope: the published pages a status page server serves, those
|
||||||
-- of agent_org for an organization's server; the platform's leave the
|
-- of agent_org for an organization's server; the platform's leave the
|
||||||
-- pages of organizations serving their own.
|
-- 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
|
FROM status_pages p
|
||||||
JOIN orgs o ON o.id = p.org_id
|
JOIN orgs o ON o.id = p.org_id
|
||||||
WHERE p.published AND p.suspended_at IS NULL AND o.suspended_at IS NULL
|
WHERE p.published AND p.suspended_at IS NULL AND o.suspended_at IS NULL
|
||||||
|
|||||||
@@ -470,7 +470,7 @@ func (q *Queries) ReparentStatusPageGroupMonitors(ctx context.Context, arg Repar
|
|||||||
}
|
}
|
||||||
|
|
||||||
const servablePages = `-- name: ServablePages :many
|
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
|
FROM status_pages p
|
||||||
JOIN orgs o ON o.id = p.org_id
|
JOIN orgs o ON o.id = p.org_id
|
||||||
WHERE p.published AND p.suspended_at IS NULL AND o.suspended_at IS NULL
|
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 {
|
type ServablePagesRow struct {
|
||||||
Slug string
|
Slug string
|
||||||
Host string
|
Host string
|
||||||
|
OrgID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
// System scope: the published pages a status page server serves, those
|
// 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{}
|
items := []ServablePagesRow{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i ServablePagesRow
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
items = append(items, i)
|
items = append(items, i)
|
||||||
|
|||||||
@@ -235,12 +235,15 @@
|
|||||||
await saveOrder(item.closest("[data-sortable]"));
|
await saveOrder(item.closest("[data-sortable]"));
|
||||||
return;
|
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]");
|
const checkAll = ev.target.closest("[data-check-all]");
|
||||||
if (checkAll) {
|
if (checkAll) {
|
||||||
const on = checkAll.dataset.checkAll === "on";
|
const on = checkAll.dataset.checkAll === "on";
|
||||||
checkAll.closest("form")?.querySelectorAll(checkAll.dataset.checkTarget).forEach((box) => {
|
checkAll.closest("form")?.querySelectorAll(checkAll.dataset.checkTarget).forEach((box) => {
|
||||||
|
if (box.closest("[data-row]")?.hidden) return;
|
||||||
box.checked = on;
|
box.checked = on;
|
||||||
|
if (on) addRowFields(box);
|
||||||
});
|
});
|
||||||
return;
|
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.
|
// Only the settings of the selected check type are shown and submitted.
|
||||||
document.addEventListener("change", (ev) => {
|
document.addEventListener("change", (ev) => {
|
||||||
const sel = ev.target.closest("[data-type-select]");
|
const sel = ev.target.closest("[data-type-select]");
|
||||||
|
|||||||
@@ -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>
|
<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>
|
</p>
|
||||||
}
|
}
|
||||||
<ul class="mb-4 divide-y divide-rule border-y border-rule text-sm">
|
if len(e.Monitors) > monitorFilterFrom {
|
||||||
|
<input type="search" data-filter-rows="#page-monitors" placeholder={ i18n.T(ctx, "pages.monitors_filter") } aria-label={ i18n.T(ctx, "pages.monitors_filter") } class="mb-2 w-full border border-rule bg-transparent px-2 py-1 text-sm outline-none focus:border-ink"/>
|
||||||
|
}
|
||||||
|
<template data-row-fields>
|
||||||
|
@pageMonitorFields(e, PageMonitorOption{})
|
||||||
|
</template>
|
||||||
|
<ul id="page-monitors" class="mb-4 divide-y divide-rule border-y border-rule text-sm">
|
||||||
for _, m := range e.Monitors {
|
for _, m := range e.Monitors {
|
||||||
<li data-row class="grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 py-2">
|
<li data-row class="grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 py-2">
|
||||||
<input type="checkbox" data-field="include" checked?={ m.Included } class="accent-ink" aria-label={ m.Name }/>
|
<input type="checkbox" data-field="include" checked?={ m.Included } class="accent-ink" aria-label={ m.Name }/>
|
||||||
@@ -294,16 +300,11 @@ templ StatusPageEditor(p Page, me Me, e PageEditor) {
|
|||||||
}
|
}
|
||||||
</span>
|
</span>
|
||||||
<input type="hidden" data-field="monitor_id" value={ m.ID }/>
|
<input type="hidden" data-field="monitor_id" value={ m.ID }/>
|
||||||
<span></span>
|
// Organizations may have thousands of monitors: only those on
|
||||||
<span class="flex gap-2">
|
// the page carry their fields, the others get them when ticked.
|
||||||
<select data-field="group_id" data-nullable aria-label={ i18n.T(ctx, "pages.group") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink">
|
if m.Included {
|
||||||
<option value="">{ i18n.T(ctx, "pages.no_group") }</option>
|
@pageMonitorFields(e, m)
|
||||||
for _, opt := range e.Groups {
|
}
|
||||||
<option value={ opt.ID } selected?={ opt.ID == m.GroupID }>{ opt.Label }</option>
|
|
||||||
}
|
|
||||||
</select>
|
|
||||||
<input data-field="label" value={ m.Label } placeholder={ i18n.T(ctx, "pages.label") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
|
|
||||||
</span>
|
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -379,3 +380,21 @@ templ dnsRecordList(kind, name, value string) {
|
|||||||
templ verifyButton(pageID, label string) {
|
templ verifyButton(pageID, label string) {
|
||||||
<button type="button" data-post={ "/org/statuspages/" + pageID + "/domain/verify" } data-ok={ i18n.T(ctx, "pages.domain_verified") } data-reload class="mt-3 border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, label) }</button>
|
<button type="button" data-post={ "/org/statuspages/" + pageID + "/domain/verify" } data-ok={ i18n.T(ctx, "pages.domain_verified") } data-reload class="mt-3 border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, label) }</button>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// monitorFilterFrom is how many monitors the page editor lists before it
|
||||||
|
// offers to filter them.
|
||||||
|
const monitorFilterFrom = 15
|
||||||
|
|
||||||
|
// pageMonitorFields are the group and label of m on the page.
|
||||||
|
templ pageMonitorFields(e PageEditor, m PageMonitorOption) {
|
||||||
|
<span data-row-extra></span>
|
||||||
|
<span class="flex gap-2">
|
||||||
|
<select data-field="group_id" data-nullable aria-label={ i18n.T(ctx, "pages.group") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink">
|
||||||
|
<option value="">{ i18n.T(ctx, "pages.no_group") }</option>
|
||||||
|
for _, opt := range e.Groups {
|
||||||
|
<option value={ opt.ID } selected?={ opt.ID == m.GroupID }>{ opt.Label }</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
<input data-field="label" value={ m.Label } placeholder={ i18n.T(ctx, "pages.label") } class="w-1/2 border border-rule bg-transparent px-2 py-1 text-xs outline-none focus:border-ink"/>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
+403
-323
@@ -1532,187 +1532,139 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
|
|||||||
return templ_7745c5c3_Err
|
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 len(e.Monitors) > monitorFilterFrom {
|
||||||
if templ_7745c5c3_Err != nil {
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 127, "<input type=\"search\" data-filter-rows=\"#page-monitors\" placeholder=\"")
|
||||||
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 templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var79 string
|
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 {
|
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)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var79)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var80 string
|
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 {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 132, "</span> ")
|
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
|
|
||||||
}
|
|
||||||
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>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -1720,7 +1672,7 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 148, "</form></section><section>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 143, "</form></section><section>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -1728,46 +1680,46 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var89 string
|
var templ_7745c5c3_Var85 string
|
||||||
templ_7745c5c3_Var89, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_intro"))
|
templ_7745c5c3_Var85, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_intro"))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var90 string
|
var templ_7745c5c3_Var86 string
|
||||||
templ_7745c5c3_Var90, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/statuspages/" + e.ID + "/domain").Resolve(ctx)
|
templ_7745c5c3_Var86, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/statuspages/" + e.ID + "/domain").Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var91 string
|
var templ_7745c5c3_Var87 string
|
||||||
templ_7745c5c3_Var91, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/statuspages/" + e.ID).Resolve(ctx)
|
templ_7745c5c3_Var87, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/statuspages/" + e.ID).Resolve(ctx)
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -1783,108 +1735,108 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 153, "</form>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 148, "</form>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if e.Domain != "" {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if e.DomainVerified {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
switch e.VerifiedBy {
|
switch e.VerifiedBy {
|
||||||
case "cname":
|
case "cname":
|
||||||
var templ_7745c5c3_Var92 string
|
var templ_7745c5c3_Var88 string
|
||||||
templ_7745c5c3_Var92, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_verified_by_cname"))
|
templ_7745c5c3_Var88, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_verified_by_cname"))
|
||||||
if templ_7745c5c3_Err != nil {
|
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))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var92))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
case "txt":
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 155, "</p>")
|
||||||
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>")
|
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if e.CNAMEValue != "" && !e.OwnServers {
|
} 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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var97 string
|
var templ_7745c5c3_Var93 string
|
||||||
templ_7745c5c3_Var97, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_cname_step"))
|
templ_7745c5c3_Var93, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_cname_step"))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -1896,33 +1848,33 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var98 string
|
var templ_7745c5c3_Var94 string
|
||||||
templ_7745c5c3_Var98, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_alt_summary"))
|
templ_7745c5c3_Var94, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_alt_summary"))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var99 string
|
var templ_7745c5c3_Var95 string
|
||||||
templ_7745c5c3_Var99, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_alt", "Target", e.CNAMEValue))
|
templ_7745c5c3_Var95, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_alt", "Target", e.CNAMEValue))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -1934,25 +1886,25 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
|
|||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 166, "</details>")
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 161, "</details>")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var100 string
|
var templ_7745c5c3_Var96 string
|
||||||
templ_7745c5c3_Var100, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_verify"))
|
templ_7745c5c3_Var96, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_verify"))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -1965,79 +1917,79 @@ func StatusPageEditor(p Page, me Me, e PageEditor) templ.Component {
|
|||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
if e.OwnServers {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var101 string
|
var templ_7745c5c3_Var97 string
|
||||||
templ_7745c5c3_Var101, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_cname_own"))
|
templ_7745c5c3_Var97, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_cname_own"))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var102 string
|
var templ_7745c5c3_Var98 string
|
||||||
templ_7745c5c3_Var102, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_cname_unknown"))
|
templ_7745c5c3_Var98, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_cname_unknown"))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var103 string
|
var templ_7745c5c3_Var99 string
|
||||||
templ_7745c5c3_Var103, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_apex"))
|
templ_7745c5c3_Var99, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_apex"))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var104 string
|
var templ_7745c5c3_Var100 string
|
||||||
templ_7745c5c3_Var104, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_tls", "Count", e.DomainChangesPerDay))
|
templ_7745c5c3_Var100, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.domain_step_tls", "Count", e.DomainChangesPerDay))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -2068,59 +2020,59 @@ func dnsRecordList(kind, name, value string) templ.Component {
|
|||||||
}
|
}
|
||||||
ctx = templ.InitializeContext(ctx)
|
ctx = templ.InitializeContext(ctx)
|
||||||
ctx = templ.ClearChildren(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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var106 string
|
var templ_7745c5c3_Var102 string
|
||||||
templ_7745c5c3_Var106, templ_7745c5c3_Err = templ.JoinStringErrs(kind)
|
templ_7745c5c3_Var102, templ_7745c5c3_Err = templ.JoinStringErrs(kind)
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var107 string
|
var templ_7745c5c3_Var103 string
|
||||||
templ_7745c5c3_Var107, templ_7745c5c3_Err = templ.JoinStringErrs(name)
|
templ_7745c5c3_Var103, templ_7745c5c3_Err = templ.JoinStringErrs(name)
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var108 string
|
var templ_7745c5c3_Var104 string
|
||||||
templ_7745c5c3_Var108, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.value"))
|
templ_7745c5c3_Var104, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.value"))
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var109 string
|
var templ_7745c5c3_Var105 string
|
||||||
templ_7745c5c3_Var109, templ_7745c5c3_Err = templ.JoinStringErrs(value)
|
templ_7745c5c3_Var105, templ_7745c5c3_Err = templ.JoinStringErrs(value)
|
||||||
if templ_7745c5c3_Err != nil {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
@@ -2145,46 +2097,174 @@ func verifyButton(pageID, label string) templ.Component {
|
|||||||
}
|
}
|
||||||
ctx = templ.InitializeContext(ctx)
|
ctx = templ.InitializeContext(ctx)
|
||||||
ctx = templ.ClearChildren(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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var111 string
|
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 {
|
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)
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var111)
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var112 string
|
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 {
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var113 string
|
for _, opt := range e.Groups {
|
||||||
templ_7745c5c3_Var113, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, label))
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 185, "<option value=\"")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/statuspages.templ`, Line: 380, Col: 247}
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
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 {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user