Compare commits
No files matched your search
@@ -24,6 +24,9 @@ UPTIME_SSO_ALLOW_PRIVATE_NETWORKS=auto
|
||||
# Outgoing mail, for email channels and sign-up confirmation.
|
||||
# UPTIME_SMTP_URL=smtp://user:pass@mail.example.com:587?from=uptime@example.com
|
||||
|
||||
# Prometheus metrics of the API, on a listener apart from the console's;
|
||||
# "off" switches them off.
|
||||
# UPTIME_API_METRICS_LISTEN=:9090
|
||||
# Checker and status page reach the API only. Create tokens with:
|
||||
# api agent create --kind checker --region local --name dev
|
||||
# api agent create --kind statuspage --name dev
|
||||
|
||||
@@ -125,6 +125,7 @@ All settings are environment variables; [`.env.example`](.env.example) lists the
|
||||
- `UPTIME_SIGNUP` (`first-user`, `open`, `closed`) decides who may sign up. New accounts confirm their email address before signing in (`UPTIME_SIGNUP_VERIFY`: always in the cloud edition, self-hosted when `UPTIME_SMTP_URL` is set); one account per mailbox, and at most `UPTIME_SIGNUPS_PER_IP` (default 2) a day per client address.
|
||||
- `UPTIME_TRUSTED_PROXIES` must name your reverse proxy, or client addresses in the audit log and rate limits will be the proxy's.
|
||||
- `UPTIME_RETENTION_*` set how long results, aggregates, audit entries and captured responses are kept.
|
||||
- `UPTIME_API_METRICS_LISTEN` (default `:9090`, `off` to disable) serves Prometheus metrics at `/metrics`, apart from the public listener: requests by route, dispatched checks and stored results per region, live checkers and overdue checks per region, notification deliveries, background job runs, platform totals and the database and Redis pools. Platform totals are the same on every API instance; aggregate them with `max()`. Keep the port off the internet.
|
||||
|
||||
### Docker Compose
|
||||
|
||||
@@ -151,7 +152,7 @@ helm install uptime uptimesebi/uptimesebi -n uptime --create-namespace \
|
||||
--set ingress.enabled=true --set ingress.tls.enabled=true
|
||||
```
|
||||
|
||||
Every setting can come from an existing secret instead (`existingSecret`); [`values.yaml`](deploy/helm/uptimesebi/values.yaml) explains them all. Migrations run as a hook before each install and upgrade. To try it out without a database and Redis of your own, `--set database.bundled.enabled=true --set redis.bundled.enabled=true` adds a single TimescaleDB and Redis, without backups or high availability. Pods run unprivileged with a read-only root filesystem; the API pods need amd64 nodes, checkers and status page servers run on ARM too.
|
||||
The API pods serve metrics on port 9090 (`api.metrics`); `--set api.metrics.serviceMonitor.enabled=true` adds a ServiceMonitor for the Prometheus Operator, and `api.metrics.prometheusRule.enabled=true` alert rules for a region whose checks fall behind. Every setting can come from an existing secret instead (`existingSecret`); [`values.yaml`](deploy/helm/uptimesebi/values.yaml) explains them all. Migrations run as a hook before each install and upgrade. To try it out without a database and Redis of your own, `--set database.bundled.enabled=true --set redis.bundled.enabled=true` adds a single TimescaleDB and Redis, without backups or high availability. Pods run unprivileged with a read-only root filesystem; the API pods need amd64 nodes, checkers and status page servers run on ARM too.
|
||||
|
||||
Run as many API, checker and status page instances as you need; they share no local state. The supported setups are:
|
||||
|
||||
|
||||
+28
-1
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/config"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/datapolicy"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/metrics"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/migrations"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/notify"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/platform"
|
||||
@@ -80,12 +82,15 @@ func run(log *slog.Logger, level *slog.LevelVar, args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
srv := api.New(cfg, api.Deps{Log: log, DB: tenant.New(deps.DB), Redis: deps.Redis, Keys: keys, Catalog: catalog})
|
||||
m := metrics.New(string(cfg.Edition))
|
||||
m.Register(metrics.DBPool(deps.DB), metrics.RedisPool(deps.Redis))
|
||||
srv := api.New(cfg, api.Deps{Log: log, DB: tenant.New(deps.DB), Redis: deps.Redis, Keys: keys, Catalog: catalog, Metrics: m})
|
||||
health := platform.NewHealth(deps.Probes())
|
||||
r := platform.NewRouter(log)
|
||||
if err := platform.TrustProxies(r, cfg.TrustedProxies); err != nil {
|
||||
return err
|
||||
}
|
||||
r.Use(m.HTTP(api.StreamingRoutes()...))
|
||||
health.Register(r)
|
||||
r.StaticFS("/static", web.Static())
|
||||
srv.Mount(r)
|
||||
@@ -97,9 +102,31 @@ func run(log *slog.Logger, level *slog.LevelVar, args []string) error {
|
||||
go srv.RunDomainWatch(ctx)
|
||||
go srv.RunHeartbeats(ctx)
|
||||
|
||||
if cfg.MetricsListen != config.MetricsOff {
|
||||
go serveMetrics(ctx, log, cfg.MetricsListen, m)
|
||||
}
|
||||
|
||||
return platform.Serve(ctx, log, platform.NewHTTPServer(cfg.Listen, r), health, 5*time.Second, cfg.ShutdownTimeout)
|
||||
}
|
||||
|
||||
// serveMetrics serves /metrics on addr, apart from the public listener,
|
||||
// until ctx ends. Failing to listen is logged but does not stop the API.
|
||||
func serveMetrics(ctx context.Context, log *slog.Logger, addr string, m *metrics.Metrics) {
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("GET /metrics", m.Handler())
|
||||
srv := platform.NewHTTPServer(addr, mux)
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
sctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_ = srv.Shutdown(sctx)
|
||||
}()
|
||||
log.Info("metrics listening", "addr", addr)
|
||||
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
log.Error("serving metrics failed", "addr", addr, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func migrate(ctx context.Context, log *slog.Logger, cfg config.API, args []string) error {
|
||||
dsn := cfg.DatabaseURL
|
||||
if dsn == "" {
|
||||
|
||||
@@ -63,9 +63,15 @@ spec:
|
||||
args: [serve]
|
||||
env:
|
||||
{{- include "uptimesebi.platformEnv" (list . $secret) | nindent 12 }}
|
||||
- name: UPTIME_API_METRICS_LISTEN
|
||||
value: {{ if .Values.api.metrics.enabled }}{{ printf ":%v" .Values.api.metrics.port | quote }}{{ else }}"off"{{ end }}
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 8080
|
||||
{{- if .Values.api.metrics.enabled }}
|
||||
- name: metrics
|
||||
containerPort: {{ .Values.api.metrics.port }}
|
||||
{{- end }}
|
||||
startupProbe:
|
||||
httpGet: {path: /healthz, port: http}
|
||||
periodSeconds: 2
|
||||
@@ -113,6 +119,11 @@ spec:
|
||||
- name: http
|
||||
port: {{ .Values.api.service.port }}
|
||||
targetPort: http
|
||||
{{- if .Values.api.metrics.enabled }}
|
||||
- name: metrics
|
||||
port: {{ .Values.api.metrics.port }}
|
||||
targetPort: metrics
|
||||
{{- end }}
|
||||
{{- if and .Values.api.podDisruptionBudget.enabled (gt (int .Values.api.replicas) 1) }}
|
||||
---
|
||||
apiVersion: policy/v1
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
{{- if and .Values.api.metrics.enabled .Values.api.metrics.prometheusRule.enabled }}
|
||||
{{- $rule := .Values.api.metrics.prometheusRule }}
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: PrometheusRule
|
||||
metadata:
|
||||
name: {{ include "uptimesebi.fullname" . }}-api
|
||||
labels:
|
||||
{{- include "uptimesebi.labels" . | nindent 4 }}
|
||||
app.kubernetes.io/component: api
|
||||
{{- with $rule.labels }}
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
groups:
|
||||
- name: uptimesebi
|
||||
rules:
|
||||
# Every replica reports the same platform values, hence max().
|
||||
- alert: UptimeSebiRegionBehind
|
||||
expr: max by (region) (uptimesebi_checks_overdue) > 0
|
||||
for: {{ $rule.regionBehindFor }}
|
||||
labels:
|
||||
severity: {{ $rule.severity }}
|
||||
annotations:
|
||||
summary: "Region {{ "{{ $labels.region }}" }} falls behind its checks"
|
||||
description: >-
|
||||
{{ "{{ $value }}" }} checks of region {{ "{{ $labels.region }}" }} are more than
|
||||
10 seconds overdue: no checker of the region is live, or its
|
||||
checkers cannot take the work in time.
|
||||
- alert: UptimeSebiPlatformMetricsFailing
|
||||
expr: max(uptimesebi_platform_metrics_error) > 0
|
||||
for: 10m
|
||||
labels:
|
||||
severity: {{ $rule.severity }}
|
||||
annotations:
|
||||
summary: UptimeSebi cannot read its platform metrics
|
||||
description: >-
|
||||
The API fails to read the database or Redis for its platform
|
||||
metrics, so UptimeSebiRegionBehind sees stale values.
|
||||
{{- end }}
|
||||
@@ -0,0 +1,20 @@
|
||||
{{- if and .Values.api.metrics.enabled .Values.api.metrics.serviceMonitor.enabled }}
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: ServiceMonitor
|
||||
metadata:
|
||||
name: {{ include "uptimesebi.fullname" . }}-api
|
||||
labels:
|
||||
{{- include "uptimesebi.labels" . | nindent 4 }}
|
||||
app.kubernetes.io/component: api
|
||||
{{- with .Values.api.metrics.serviceMonitor.labels }}
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "uptimesebi.selector" (list . "api") | nindent 6 }}
|
||||
endpoints:
|
||||
- port: metrics
|
||||
path: /metrics
|
||||
interval: {{ .Values.api.metrics.serviceMonitor.interval }}
|
||||
{{- end }}
|
||||
@@ -126,6 +126,28 @@ api:
|
||||
service:
|
||||
type: ClusterIP
|
||||
port: 8080
|
||||
# Prometheus metrics on a port of their own, which the ingress never
|
||||
# exposes.
|
||||
metrics:
|
||||
enabled: true
|
||||
port: 9090
|
||||
# A ServiceMonitor for the Prometheus Operator (kube-prometheus-stack).
|
||||
serviceMonitor:
|
||||
enabled: false
|
||||
interval: 30s
|
||||
# Extra labels, for a Prometheus that selects ServiceMonitors by label.
|
||||
labels: {}
|
||||
# Alert rules for the Prometheus Operator: a region whose checks fall
|
||||
# behind, and platform metrics that cannot be read. Needs the
|
||||
# ServiceMonitor or another scrape of the metrics.
|
||||
prometheusRule:
|
||||
enabled: false
|
||||
# How long checks must stay overdue before the alert fires.
|
||||
regionBehindFor: 5m
|
||||
severity: warning
|
||||
# Extra labels, for a Prometheus that selects rules by label, like
|
||||
# release: <name> with kube-prometheus-stack.
|
||||
labels: {}
|
||||
# The API image is built for amd64 only; checkers and status page servers
|
||||
# run on arm64 and 32-bit ARM too. Also used by the migration job.
|
||||
nodeSelector:
|
||||
|
||||
@@ -23,6 +23,7 @@ require (
|
||||
github.com/nicksnyder/go-i18n/v2 v2.7.0
|
||||
github.com/pquerna/otp v1.5.0
|
||||
github.com/pressly/goose/v3 v3.30.1
|
||||
github.com/prometheus/client_golang v1.25.0
|
||||
github.com/rabbitmq/amqp091-go v1.17.0
|
||||
github.com/redis/go-redis/v9 v9.23.0
|
||||
github.com/twmb/franz-go v1.22.3
|
||||
@@ -32,6 +33,7 @@ require (
|
||||
go.uber.org/zap v1.28.0
|
||||
golang.org/x/crypto v0.59.0
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20261123165210-6c21c5864259
|
||||
golang.org/x/image v0.25.0
|
||||
golang.org/x/net v0.63.0
|
||||
golang.org/x/oauth2 v0.38.0
|
||||
golang.org/x/sync v0.25.0
|
||||
@@ -45,6 +47,7 @@ require (
|
||||
github.com/ImVexed/fasturl v0.0.0-20230304231329-4e41488060f3 // indirect
|
||||
github.com/a-h/parse v0.0.42 // indirect
|
||||
github.com/andybalholm/brotli v1.3.0 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
|
||||
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
|
||||
@@ -79,6 +82,7 @@ require (
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.20.4 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.4.0 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/leodido/go-urn v1.5.0 // indirect
|
||||
github.com/libdns/libdns v1.1.1 // indirect
|
||||
github.com/mailru/easyjson v0.9.0 // indirect
|
||||
@@ -89,11 +93,15 @@ require (
|
||||
github.com/miekg/dns v1.1.73 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/natefinch/atomic v1.0.1 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.1.1 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.33 // indirect
|
||||
github.com/prometheus/client_model v0.6.3 // indirect
|
||||
github.com/prometheus/common v0.72.0 // indirect
|
||||
github.com/prometheus/procfs v0.23.0 // indirect
|
||||
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
|
||||
github.com/quic-go/qpack v0.6.0 // indirect
|
||||
github.com/quic-go/quic-go v0.59.0 // indirect
|
||||
|
||||
@@ -25,6 +25,8 @@ github.com/a-h/templ v0.3.1118/go.mod h1:ttKggixbDULrwkJzfEO5fa4IPGTKiRt3qP09zjP
|
||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
||||
github.com/andybalholm/brotli v1.3.0 h1:IdkhjSe/+34U+fP7FSR2Q6Poj1hnHUa2GoWmzXJd6qY=
|
||||
github.com/andybalholm/brotli v1.3.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
|
||||
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
@@ -216,6 +218,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||
github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A=
|
||||
github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM=
|
||||
github.com/nbd-wtf/go-nostr v0.52.3 h1:Xd87pXfJEJRXHpM+fLjQQln8dBNNaoPA10V7BbyP4KI=
|
||||
@@ -248,6 +252,14 @@ github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs=
|
||||
github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
||||
github.com/pressly/goose/v3 v3.30.1 h1:KO28meBdbAUIdMbTP7bl9dp1FYZGXcYWb2O7miT09lE=
|
||||
github.com/pressly/goose/v3 v3.30.1/go.mod h1:CHGwuG2acDerUaXwz2i5T18VSauXpYDiL4WxzDvcOIM=
|
||||
github.com/prometheus/client_golang v1.25.0 h1:cDtW1TcFsMi1RJc8khwCKB4VhzwV04aKqbYtNOXuiK0=
|
||||
github.com/prometheus/client_golang v1.25.0/go.mod h1:j2X/4/kaQHLPnmyEU8zjmkndo1T317VpCIQEml8LTKk=
|
||||
github.com/prometheus/client_model v0.6.3 h1:O0jaTVAYNxTHYInEPFJt5I3+sN8zqBtVMPTB1qyxiEo=
|
||||
github.com/prometheus/client_model v0.6.3/go.mod h1:gpN5P9S7Rr6Yr92PiQ+Ixvhf6JZEkF1dnxsYL2aPBEM=
|
||||
github.com/prometheus/common v0.72.0 h1:tAYsE+sPJxIncDAobm4H5aQjmox9ZxEIIqPbiffa8G4=
|
||||
github.com/prometheus/common v0.72.0/go.mod h1:77NWqAQ2tXT7BIK40qjJdw5Acrsrg1TlHAnsQi3i6mk=
|
||||
github.com/prometheus/procfs v0.23.0 h1:ad+S6FTkzwaMgacKLM5h6bNKExS+DMH0YiUwXItH/o4=
|
||||
github.com/prometheus/procfs v0.23.0/go.mod h1:3AVXO0FqLafyYFU/V/IQRZlC8Rgqz8Dm/x6pKLK+RIk=
|
||||
github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++5Fg=
|
||||
github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
|
||||
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||
@@ -334,6 +346,8 @@ go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
|
||||
go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
|
||||
go.uber.org/zap/exp v0.3.0 h1:6JYzdifzYkGmTdRR59oYH+Ng7k49H9qVpWwNSsGJj3U=
|
||||
go.uber.org/zap/exp v0.3.0/go.mod h1:5I384qq7XGxYyByIhHm6jg5CHkGY0nsTfbDLgDDlgJQ=
|
||||
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
|
||||
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
|
||||
go.yaml.in/yaml/v3 v3.0.6 h1:zcDfvjXEqTQmpjniUBLc91xYJMB2c4QOFxEF/LCEckM=
|
||||
go.yaml.in/yaml/v3 v3.0.6/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
|
||||
golang.org/x/arch v0.22.0 h1:c/Zle32i5ttqRXjdLyyHZESLD/bB90DCU1g9l/0YBDI=
|
||||
@@ -349,6 +363,8 @@ golang.org/x/crypto/x509roots/fallback v0.0.0-20261123165210-6c21c5864259 h1:wXc
|
||||
golang.org/x/crypto/x509roots/fallback v0.0.0-20261123165210-6c21c5864259/go.mod h1:HPze8vhfG6fO06AM+VSvxRm4E3+5Yk375mgrJ5M2z1E=
|
||||
golang.org/x/exp v0.0.0-20261109185158-a52e3aef5920 h1:qr+tk4P56rtbVVAJDyAr5LAOiaD/XhZCoRTr4SfLxAk=
|
||||
golang.org/x/exp v0.0.0-20261109185158-a52e3aef5920/go.mod h1:J3U+E8RzytcGvwz+uJuAP4zULJ2TkAQBnmPZMexpdXs=
|
||||
golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ=
|
||||
golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.43.0 h1:MFuq5J6s35W9D3IjkwyWc9vHh0nENOrt5K8Iof4ofmg=
|
||||
|
||||
@@ -8,6 +8,7 @@ package agentapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -172,7 +173,18 @@ func (c *Client) doWith(ctx context.Context, method, path string, header http.He
|
||||
case out == nil:
|
||||
return nil
|
||||
}
|
||||
return json.NewDecoder(resp.Body).Decode(out)
|
||||
// Asked for explicitly, a compressed answer is not unpacked by the
|
||||
// transport, nor ever over the stream.
|
||||
var r io.Reader = resp.Body
|
||||
if strings.EqualFold(resp.Header.Get("Content-Encoding"), "gzip") {
|
||||
zr, err := gzip.NewReader(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("agentapi: %s %s: %w", method, path, err)
|
||||
}
|
||||
defer func() { _ = zr.Close() }()
|
||||
r = zr
|
||||
}
|
||||
return json.NewDecoder(r).Decode(out)
|
||||
}
|
||||
|
||||
// Hello identifies the agent and checks connectivity.
|
||||
|
||||
@@ -407,9 +407,10 @@ func (c *Client) PageIfChanged(ctx context.Context, host, slug, checksum string)
|
||||
} else {
|
||||
q.Set("slug", slug)
|
||||
}
|
||||
var h http.Header
|
||||
// Pages run to megabytes of JSON that compresses many times over.
|
||||
h := http.Header{"Accept-Encoding": {"gzip"}}
|
||||
if checksum != "" {
|
||||
h = http.Header{"If-None-Match": {`"` + checksum + `"`}}
|
||||
h.Set("If-None-Match", `"`+checksum+`"`)
|
||||
}
|
||||
var p PageSnapshot
|
||||
err := c.doWith(ctx, http.MethodGet, "/pages?"+q.Encode(), h, nil, &p)
|
||||
|
||||
+41
-5
@@ -222,12 +222,31 @@ func (s *Server) agentJobs(c *gin.Context) {
|
||||
}
|
||||
}()
|
||||
}
|
||||
entries, err := s.sched.Take(pollCtx, instance, min(req.Max, maxJobBatch), wait)
|
||||
entries, stale, err := s.sched.Take(pollCtx, instance, min(req.Max, maxJobBatch), wait)
|
||||
s.metrics.Stale(stale)
|
||||
if err != nil && pollCtx.Err() == nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
jobs, orgs, err := s.resolveJobs(ctx, agentOf(c), entries)
|
||||
agent := agentOf(c)
|
||||
if len(entries) > 0 {
|
||||
// The long poll may have waited for a while: settings such as
|
||||
// allow_private apply to the jobs as they are now.
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
agent, err = q.GetAgentByHash(ctx, HashToken(bearerToken(c)))
|
||||
return err
|
||||
})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
fail(c, http.StatusUnauthorized, "unauthenticated")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
jobs, orgs, err := s.resolveJobs(ctx, agent, entries)
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
@@ -298,6 +317,7 @@ func (s *Server) agentResults(c *gin.Context) {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
s.metrics.Rejected("duplicate", len(req.Results)-len(fresh))
|
||||
req.Results = fresh
|
||||
ids := make([]uuid.UUID, len(req.Results))
|
||||
for i, r := range req.Results {
|
||||
@@ -308,6 +328,8 @@ func (s *Server) agentResults(c *gin.Context) {
|
||||
var (
|
||||
accepted []agentapi.Result
|
||||
changed []uuid.UUID
|
||||
unknown int
|
||||
badTime int
|
||||
)
|
||||
err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
a := agentOf(c)
|
||||
@@ -325,7 +347,12 @@ func (s *Server) agentResults(c *gin.Context) {
|
||||
// A checker may only report monitors of its own region, and
|
||||
// timestamps far from now are rejected rather than skewing
|
||||
// history.
|
||||
if !ok || r.StartedAt.After(now.Add(time.Minute)) || r.StartedAt.Before(now.Add(-24*time.Hour)) {
|
||||
switch {
|
||||
case !ok:
|
||||
unknown++
|
||||
continue
|
||||
case r.StartedAt.After(now.Add(time.Minute)) || r.StartedAt.Before(now.Add(-24*time.Hour)):
|
||||
badTime++
|
||||
continue
|
||||
}
|
||||
row := store.InsertCheckResultsParams{
|
||||
@@ -353,6 +380,12 @@ func (s *Server) agentResults(c *gin.Context) {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
s.metrics.Rejected("unknown_monitor", unknown)
|
||||
s.metrics.Rejected("bad_time", badTime)
|
||||
label := regionLabel(agentOf(c))
|
||||
for _, r := range accepted {
|
||||
s.metrics.Result(label, r.OK, now.Sub(r.StartedAt))
|
||||
}
|
||||
s.pagesChanged(ctx, changed...)
|
||||
s.evaluateResults(ctx, region, accepted, monitors)
|
||||
s.storeEvidence(ctx, region, instance, accepted, monitors)
|
||||
@@ -380,8 +413,11 @@ func truncateValid(s string, n int) string {
|
||||
}
|
||||
|
||||
// resultClaimTTL covers the retries of a checker that lost the answer to a
|
||||
// report, which happen within minutes.
|
||||
const resultClaimTTL = 2 * time.Hour
|
||||
// report: the next report, seconds later, or the first after the API is
|
||||
// back. A claim is one Redis key per result, so the TTL sets how much of
|
||||
// Redis they take: at 500 results a second, 10 minutes are 300,000 keys,
|
||||
// about 70 MiB.
|
||||
const resultClaimTTL = 10 * time.Minute
|
||||
|
||||
// claimResults drops results already received. A checker that does not get
|
||||
// the answer to a report, say because the connection broke while the API was
|
||||
|
||||
@@ -128,6 +128,7 @@ func (s *Server) transition(ctx context.Context, m store.MonitorsForResultsRow,
|
||||
}
|
||||
}
|
||||
s.log.InfoContext(ctx, "incident "+event, "monitor", m.ID, "incident", inc.ID, "channels", len(channels))
|
||||
s.metrics.Incident(event)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -167,7 +168,9 @@ func (s *Server) deliverBatch(ctx context.Context) int {
|
||||
return 0
|
||||
}
|
||||
for _, n := range rows {
|
||||
sent := time.Now()
|
||||
sendErr := s.send(ctx, n.ChannelType, n.ChannelConfig, eventOf(n))
|
||||
s.metrics.Notification(n.ChannelType, sendErr, time.Since(sent))
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
if sendErr == nil {
|
||||
return q.MarkNotificationSent(ctx, n.ID)
|
||||
|
||||
@@ -85,7 +85,9 @@ func TestCheckerNetwork(t *testing.T) {
|
||||
}
|
||||
waitResult := func(id string, ok bool, what string) {
|
||||
t.Helper()
|
||||
waitFor(t, 20*time.Second, what, func() bool {
|
||||
// Two runs at most: the one already handed out, then the next on
|
||||
// the monitor's phase, up to one and a half intervals later.
|
||||
waitFor(t, 30*time.Second, what, func() bool {
|
||||
got, msg, seen := latestOf(owner, id)
|
||||
return seen && got == ok && (ok || strings.Contains(msg, "non-public"))
|
||||
})
|
||||
|
||||
@@ -941,6 +941,8 @@ func (s *Server) monitorEditor(c *gin.Context, p *principal, page web.Page, me w
|
||||
checked := slices.Contains(assigned, r.ID) || (idParam == "" && i == 0)
|
||||
f.Regions = append(f.Regions, web.RegionOption{ID: r.ID.String(), Name: r.Name, Own: r.OrgID != nil, Checked: checked, Live: live, Lat: r.Latitude, Lon: r.Longitude})
|
||||
}
|
||||
limits := s.orgLimits(ctx, p.Org)
|
||||
f.RegionLimit, f.OwnRegionsCount = limits.RegionsPerMonitor, limits.OwnRegionsCount
|
||||
t, err := s.loadGroupTree(ctx, p.scope())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -81,7 +81,7 @@ func (s *Server) RunDomainWatch(ctx context.Context) {
|
||||
defer tick.Stop()
|
||||
for {
|
||||
if ok, err := s.rdb.SetNX(ctx, keyDomainWatch, 1, domainWatchEvery-5*time.Second).Result(); err == nil && ok {
|
||||
if err := s.WatchDomains(ctx, time.Now()); err != nil && ctx.Err() == nil {
|
||||
if err := s.metrics.Job("domain_watch", func() error { return s.WatchDomains(ctx, time.Now()) }); err != nil && ctx.Err() == nil {
|
||||
s.log.WarnContext(ctx, "checking custom domains failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
+75
-28
@@ -37,9 +37,15 @@ const (
|
||||
|
||||
// storeEvidence keeps the evidence of accepted results: per monitor and
|
||||
// region the latest success, and failures unless an identical one was kept
|
||||
// within failureEvidenceEvery. Evidence is an aid; failures are logged and
|
||||
// never fail the report.
|
||||
// within failureEvidenceEvery. All of a report's evidence is written in one
|
||||
// transaction, so a report full of it stays quick and the checker can go
|
||||
// on. Evidence is an aid; failures are logged and never fail the report.
|
||||
func (s *Server) storeEvidence(ctx context.Context, region string, checker uuid.UUID, results []agentapi.Result, monitors map[uuid.UUID]store.MonitorsForResultsRow) {
|
||||
var (
|
||||
successes = map[uuid.UUID]agentapi.Result{}
|
||||
failures []agentapi.Result
|
||||
failed []uuid.UUID
|
||||
)
|
||||
for _, r := range results {
|
||||
m, ok := monitors[r.MonitorID]
|
||||
if len(r.Evidence) == 0 || !ok {
|
||||
@@ -49,34 +55,75 @@ func (s *Server) storeEvidence(ctx context.Context, region string, checker uuid.
|
||||
s.log.WarnContext(ctx, "dropping malformed evidence", "monitor", m.ID, "bytes", len(r.Evidence))
|
||||
continue
|
||||
}
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
if r.OK {
|
||||
if err := q.DeleteSuccessEvidence(ctx, store.DeleteSuccessEvidenceParams{MonitorID: m.ID, Region: region}); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
last, err := q.LastFailureEvidence(ctx, store.LastFailureEvidenceParams{MonitorID: m.ID, Region: region})
|
||||
if err == nil && last.Error == r.Error && r.StartedAt.Sub(last.Time) < failureEvidenceEvery {
|
||||
return nil
|
||||
}
|
||||
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
|
||||
return err
|
||||
}
|
||||
if r.OK {
|
||||
// Only the latest success is kept anyway.
|
||||
if prev, seen := successes[r.MonitorID]; !seen || r.StartedAt.After(prev.StartedAt) {
|
||||
successes[r.MonitorID] = r
|
||||
}
|
||||
row := store.InsertEvidenceParams{
|
||||
OrgID: m.OrgID, MonitorID: m.ID, Region: region, CheckerID: checker, Time: r.StartedAt, Ok: r.OK, Evidence: r.Evidence,
|
||||
}
|
||||
if r.StatusCode > 0 {
|
||||
row.StatusCode = ptr(int32(r.StatusCode))
|
||||
}
|
||||
if r.Error != "" {
|
||||
row.Error = ptr(truncateValid(r.Error, 500))
|
||||
}
|
||||
return q.InsertEvidence(ctx, row)
|
||||
})
|
||||
if err != nil {
|
||||
s.log.WarnContext(ctx, "storing evidence failed", "monitor", m.ID, "error", err)
|
||||
continue
|
||||
}
|
||||
failures = append(failures, r)
|
||||
if !slices.Contains(failed, r.MonitorID) {
|
||||
failed = append(failed, r.MonitorID)
|
||||
}
|
||||
}
|
||||
if len(successes) == 0 && len(failures) == 0 {
|
||||
return
|
||||
}
|
||||
slices.SortFunc(failures, func(a, b agentapi.Result) int { return a.StartedAt.Compare(b.StartedAt) })
|
||||
insert := func(q *store.Queries, r agentapi.Result) error {
|
||||
m := monitors[r.MonitorID]
|
||||
row := store.InsertEvidenceParams{
|
||||
OrgID: m.OrgID, MonitorID: m.ID, Region: region, CheckerID: checker, Time: r.StartedAt, Ok: r.OK, Evidence: r.Evidence,
|
||||
}
|
||||
if r.StatusCode > 0 {
|
||||
row.StatusCode = ptr(int32(r.StatusCode))
|
||||
}
|
||||
if r.Error != "" {
|
||||
row.Error = ptr(truncateValid(r.Error, 500))
|
||||
}
|
||||
return q.InsertEvidence(ctx, row)
|
||||
}
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
if len(successes) > 0 {
|
||||
ids := make([]uuid.UUID, 0, len(successes))
|
||||
for id := range successes {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if err := q.DeleteSuccessEvidence(ctx, store.DeleteSuccessEvidenceParams{Region: region, MonitorIds: ids}); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, r := range successes {
|
||||
if err := insert(q, r); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(failures) == 0 {
|
||||
return nil
|
||||
}
|
||||
rows, err := q.LastFailureEvidence(ctx, store.LastFailureEvidenceParams{Region: region, MonitorIds: failed})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
last := make(map[uuid.UUID]store.LastFailureEvidenceRow, len(rows))
|
||||
for _, l := range rows {
|
||||
last[l.MonitorID] = l
|
||||
}
|
||||
for _, r := range failures {
|
||||
kept := truncateValid(r.Error, 500)
|
||||
if l, ok := last[r.MonitorID]; ok && l.Error == kept && r.StartedAt.Sub(l.Time) < failureEvidenceEvery {
|
||||
continue
|
||||
}
|
||||
if err := insert(q, r); err != nil {
|
||||
return err
|
||||
}
|
||||
last[r.MonitorID] = store.LastFailureEvidenceRow{MonitorID: r.MonitorID, Time: r.StartedAt, Error: kept}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
s.log.WarnContext(ctx, "storing evidence failed", "results", len(successes)+len(failures), "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,17 @@ package api_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
)
|
||||
|
||||
func TestEvidence(t *testing.T) {
|
||||
@@ -103,3 +108,62 @@ func TestEvidence(t *testing.T) {
|
||||
t.Error("the monitor page links evidence for a viewer")
|
||||
}
|
||||
}
|
||||
|
||||
// TestEvidenceBatch stores a report with evidence of several monitors and
|
||||
// runs at once, as a checker sends after a backlog.
|
||||
func TestEvidenceBatch(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
tok, region := e.platformChecker(t, uniq("ev-batch-"))
|
||||
owner := e.browser(t)
|
||||
owner.signup("o@"+uniq("evb")+".test", uniq("evb-"))
|
||||
monitor := func() uuid.UUID {
|
||||
_, m := owner.do("POST", "/api/v1/org/monitors", map[string]any{
|
||||
"name": "m", "type": "tcp", "target": "example.com:443", "interval_seconds": 3600, "regions": []string{region},
|
||||
})
|
||||
return uuid.MustParse(m["id"].(string))
|
||||
}
|
||||
up, down := monitor(), monitor()
|
||||
client := agentapi.NewClient(e.srv.URL, tok, uuid.New(), "test").WithHTTPClient(e.srv.Client())
|
||||
ev := json.RawMessage(`{"steps":[]}`)
|
||||
at := time.Now().Add(-time.Minute).Truncate(time.Millisecond)
|
||||
run := func(m uuid.UUID, after time.Duration, ok bool, msg string) agentapi.Result {
|
||||
return agentapi.Result{MonitorID: m, ScheduledAt: at.Add(after), StartedAt: at.Add(after), OK: ok, Error: msg, Evidence: ev}
|
||||
}
|
||||
if err := client.Report(context.Background(), []agentapi.Result{
|
||||
run(up, 0, true, ""),
|
||||
run(up, time.Second, true, ""),
|
||||
run(down, 0, false, "boom"),
|
||||
run(down, time.Second, false, "boom"),
|
||||
run(down, 2*time.Second, false, "other"),
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The latest success only; failures unless the same one was just kept.
|
||||
if n := e.count(t, `SELECT count(*) FROM check_evidence WHERE monitor_id = $1 AND ok AND time = $2`, up, at.Add(time.Second)); n != 1 {
|
||||
t.Errorf("success evidence of the latest run = %d rows, want 1", n)
|
||||
}
|
||||
if n := e.count(t, `SELECT count(*) FROM check_evidence WHERE monitor_id = $1`, up); n != 1 {
|
||||
t.Errorf("success evidence rows = %d, want 1", n)
|
||||
}
|
||||
if n := e.count(t, `SELECT count(*) FROM check_evidence WHERE monitor_id = $1 AND NOT ok`, down); n != 2 {
|
||||
t.Errorf("failure evidence rows = %d, want 2: boom once, then other", n)
|
||||
}
|
||||
|
||||
// The next report replaces the success and thins out the failure
|
||||
// already kept.
|
||||
if err := client.Report(context.Background(), []agentapi.Result{
|
||||
run(up, 5*time.Second, true, ""),
|
||||
run(down, 10*time.Second, false, "other"),
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n := e.count(t, `SELECT count(*) FROM check_evidence WHERE monitor_id = $1 AND ok AND time = $2`, up, at.Add(5*time.Second)); n != 1 {
|
||||
t.Errorf("success evidence after the next report: latest run kept %d times, want 1", n)
|
||||
}
|
||||
if n := e.count(t, `SELECT count(*) FROM check_evidence WHERE monitor_id = $1`, up); n != 1 {
|
||||
t.Errorf("success evidence rows after the next report = %d, want 1", n)
|
||||
}
|
||||
if n := e.count(t, `SELECT count(*) FROM check_evidence WHERE monitor_id = $1 AND NOT ok`, down); n != 2 {
|
||||
t.Errorf("failure evidence rows after the next report = %d, want still 2", n)
|
||||
}
|
||||
}
|
||||
@@ -129,10 +129,12 @@ func (s *Server) RunHeartbeats(ctx context.Context) {
|
||||
if err != nil || !got {
|
||||
continue
|
||||
}
|
||||
if err := s.CheckHeartbeats(ctx, time.Now()); err != nil && ctx.Err() == nil {
|
||||
if err := s.metrics.Job("heartbeats", func() error { return s.CheckHeartbeats(ctx, time.Now()) }); err != nil && ctx.Err() == nil {
|
||||
s.log.ErrorContext(ctx, "checking heartbeats failed", "error", err)
|
||||
}
|
||||
if err := s.CheckAlertmanagerMonitors(ctx, nil, time.Now(), false); err != nil && ctx.Err() == nil {
|
||||
if err := s.metrics.Job("alertmanager_monitors", func() error {
|
||||
return s.CheckAlertmanagerMonitors(ctx, nil, time.Now(), false)
|
||||
}); err != nil && ctx.Err() == nil {
|
||||
s.log.ErrorContext(ctx, "checking alertmanager monitors failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (s *Server) RunHousekeeping(ctx context.Context) {
|
||||
tick := time.NewTicker(time.Hour)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
if err := s.Housekeep(ctx, time.Now()); err != nil && ctx.Err() == nil {
|
||||
if err := s.metrics.Job("housekeeping", func() error { return s.Housekeep(ctx, time.Now()) }); err != nil && ctx.Err() == nil {
|
||||
s.log.ErrorContext(ctx, "housekeeping failed", "error", err)
|
||||
}
|
||||
select {
|
||||
|
||||
@@ -205,7 +205,9 @@ func (s *Server) legalPage(c *gin.Context) {
|
||||
}
|
||||
me = &m
|
||||
}
|
||||
web.Render(c, http.StatusOK, web.LegalPage(s.pageFor(c, web.LegalTitleID(kind)), me, html))
|
||||
p := s.pageFor(c, web.LegalTitleID(kind))
|
||||
p.Meta = s.publicMeta(c, "/legal/"+kind, web.LegalTitleID(kind))
|
||||
web.Render(c, http.StatusOK, web.LegalPage(p, me, html))
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusNotFound)
|
||||
|
||||
@@ -52,6 +52,22 @@ func TestLimits(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// The monitor form locks regions beyond the limit; own ones do not count.
|
||||
_, _, html := owner.page("/monitors/new")
|
||||
if !strings.Contains(html, `data-region-limit="1"`) {
|
||||
t.Error("monitor form lacks the region limit")
|
||||
}
|
||||
for id, counted := range map[string]bool{p1: true, o1: false} {
|
||||
i := strings.Index(html, `value="`+id+`"`)
|
||||
if i < 0 {
|
||||
t.Fatalf("monitor form lacks region %s", id)
|
||||
}
|
||||
tag := html[i : i+strings.Index(html[i:], ">")]
|
||||
if strings.Contains(tag, "data-counted") != counted {
|
||||
t.Errorf("region %s counted = %v, want %v", id, !counted, counted)
|
||||
}
|
||||
}
|
||||
|
||||
// Monitors, passive ones included.
|
||||
if st, body := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": "hb", "type": "heartbeat", "interval_seconds": 3600}); st != http.StatusCreated {
|
||||
t.Fatalf("heartbeat = %d %v", st, body)
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// Platform metrics are read from the database and Redis when scraped, at
|
||||
// most once per platformMetricsTTL, so scrapes stay cheap. Every replica
|
||||
// reports the same platform totals; dashboards take their max().
|
||||
const (
|
||||
platformMetricsTTL = 15 * time.Second
|
||||
// checksLateAfter leaves the runs alone that the next dispatch, every
|
||||
// second, takes anyway.
|
||||
checksLateAfter = 10 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
descCheckers = prometheus.NewDesc("uptimesebi_checker_instances",
|
||||
"Live checker instances per platform region.", []string{"region"}, nil)
|
||||
descOverdue = prometheus.NewDesc("uptimesebi_checks_overdue",
|
||||
"Checks of a platform region due for more than 10 seconds and not started: undispatched, as when no checker of the region is live, or waiting in the queue of a checker too busy to take them.", []string{"region"}, nil)
|
||||
descRegions = prometheus.NewDesc("uptimesebi_regions",
|
||||
"Platform regions by whether a checker is live.", []string{"online"}, nil)
|
||||
descOrgs = prometheus.NewDesc("uptimesebi_orgs",
|
||||
"Organizations on the platform.", nil, nil)
|
||||
descUsers = prometheus.NewDesc("uptimesebi_users",
|
||||
"User accounts on the platform.", nil, nil)
|
||||
descMonitors = prometheus.NewDesc("uptimesebi_monitors",
|
||||
"Monitors by type and whether they are enabled.", []string{"type", "enabled"}, nil)
|
||||
descPages = prometheus.NewDesc("uptimesebi_status_pages",
|
||||
"Status pages on the platform.", nil, nil)
|
||||
descSubscribers = prometheus.NewDesc("uptimesebi_status_page_subscribers",
|
||||
"Confirmed subscribers of status pages.", nil, nil)
|
||||
descOpenIncidents = prometheus.NewDesc("uptimesebi_incidents_open",
|
||||
"Incidents not resolved yet.", nil, nil)
|
||||
descPending = prometheus.NewDesc("uptimesebi_notifications_pending",
|
||||
"Notifications waiting for delivery, by kind: channel or subscriber.", []string{"kind"}, nil)
|
||||
descScrapeError = prometheus.NewDesc("uptimesebi_platform_metrics_error",
|
||||
"1 if reading the platform metrics failed on the last attempt.", nil, nil)
|
||||
)
|
||||
|
||||
type platformSnapshot struct {
|
||||
counts store.PlatformCountsRow
|
||||
monitors []store.MonitorCountsRow
|
||||
regions []regionLoad
|
||||
}
|
||||
|
||||
type regionLoad struct {
|
||||
key string
|
||||
checkers int64
|
||||
overdue int64
|
||||
}
|
||||
|
||||
// platformCollector reports the platform's totals, checkers and backlog.
|
||||
type platformCollector struct {
|
||||
s *Server
|
||||
mu sync.Mutex
|
||||
last platformSnapshot
|
||||
err error
|
||||
expires time.Time
|
||||
}
|
||||
|
||||
// Describe implements prometheus.Collector.
|
||||
func (p *platformCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
for _, d := range []*prometheus.Desc{
|
||||
descCheckers, descOverdue, descRegions, descOrgs, descUsers, descMonitors,
|
||||
descPages, descSubscribers, descOpenIncidents, descPending, descScrapeError,
|
||||
} {
|
||||
ch <- d
|
||||
}
|
||||
}
|
||||
|
||||
// Collect implements prometheus.Collector. It reads the database and
|
||||
// Redis at most once per platformMetricsTTL.
|
||||
func (p *platformCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
p.mu.Lock()
|
||||
if time.Now().After(p.expires) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
snap, err := p.s.platformSnapshot(ctx)
|
||||
cancel()
|
||||
// A failed read keeps the last good values, flagged.
|
||||
if err == nil {
|
||||
p.last = snap
|
||||
} else {
|
||||
p.s.log.Warn("reading platform metrics failed", "error", err)
|
||||
}
|
||||
p.err, p.expires = err, time.Now().Add(platformMetricsTTL)
|
||||
}
|
||||
snap, failed := p.last, p.err != nil
|
||||
p.mu.Unlock()
|
||||
|
||||
gauge := func(d *prometheus.Desc, v int64, labels ...string) {
|
||||
ch <- prometheus.MustNewConstMetric(d, prometheus.GaugeValue, float64(v), labels...)
|
||||
}
|
||||
var online, offline int64
|
||||
for _, r := range snap.regions {
|
||||
gauge(descCheckers, r.checkers, r.key)
|
||||
gauge(descOverdue, r.overdue, r.key)
|
||||
if r.checkers > 0 {
|
||||
online++
|
||||
} else {
|
||||
offline++
|
||||
}
|
||||
}
|
||||
gauge(descRegions, online, "true")
|
||||
gauge(descRegions, offline, "false")
|
||||
c := snap.counts
|
||||
gauge(descOrgs, c.Orgs)
|
||||
gauge(descUsers, c.Users)
|
||||
gauge(descPages, c.StatusPages)
|
||||
gauge(descSubscribers, c.Subscribers)
|
||||
gauge(descOpenIncidents, c.OpenIncidents)
|
||||
gauge(descPending, c.PendingNotifications, "channel")
|
||||
gauge(descPending, c.PendingSubscriberNotifications, "subscriber")
|
||||
for _, m := range snap.monitors {
|
||||
enabled := "false"
|
||||
if m.Enabled {
|
||||
enabled = "true"
|
||||
}
|
||||
gauge(descMonitors, m.Monitors, m.Type, enabled)
|
||||
}
|
||||
var flag int64
|
||||
if failed {
|
||||
flag = 1
|
||||
}
|
||||
gauge(descScrapeError, flag)
|
||||
}
|
||||
|
||||
func (s *Server) platformSnapshot(ctx context.Context) (platformSnapshot, error) {
|
||||
var (
|
||||
snap platformSnapshot
|
||||
regions []store.Region
|
||||
)
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
if snap.counts, err = q.PlatformCounts(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if snap.monitors, err = q.MonitorCounts(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
regions, err = q.ListPlatformRegions(ctx)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return snap, err
|
||||
}
|
||||
for _, r := range regions {
|
||||
n, err := s.sched.Instances(ctx, r.ID.String())
|
||||
if err != nil {
|
||||
return snap, err
|
||||
}
|
||||
late, err := s.sched.Overdue(ctx, r.ID.String(), checksLateAfter)
|
||||
if err != nil {
|
||||
return snap, err
|
||||
}
|
||||
snap.regions = append(snap.regions, regionLoad{key: r.Key, checkers: n, overdue: late})
|
||||
}
|
||||
return snap, nil
|
||||
}
|
||||
|
||||
// regionLabel names a checker's region in metrics: the key of a platform
|
||||
// region, or "own" for organizations' checkers, whose regions are many and
|
||||
// not the operator's.
|
||||
func regionLabel(a store.GetAgentByHashRow) string {
|
||||
if a.OrgID != nil {
|
||||
return "own"
|
||||
}
|
||||
if a.RegionKey != nil {
|
||||
return *a.RegionKey
|
||||
}
|
||||
return "none"
|
||||
}
|
||||
|
||||
// StreamingRoutes stay open on purpose: the agents' streams and the
|
||||
// checkers' long polls. Request metrics count them but do not time them.
|
||||
func StreamingRoutes() []string {
|
||||
return []string{agentapi.Prefix + agentapi.StreamPath, agentapi.Prefix + "/jobs"}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
)
|
||||
|
||||
// scrape returns the value of every series of the API's metrics, keyed by
|
||||
// name and labels as the text format prints them.
|
||||
func (e *env) scrape(t *testing.T) map[string]float64 {
|
||||
t.Helper()
|
||||
rec := httptest.NewRecorder()
|
||||
e.metrics.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/metrics", nil))
|
||||
if rec.Code != http.StatusOK || !strings.HasPrefix(rec.Header().Get("Content-Type"), "text/plain") {
|
||||
t.Fatalf("metrics answered %d %q", rec.Code, rec.Header().Get("Content-Type"))
|
||||
}
|
||||
body, _ := io.ReadAll(rec.Body)
|
||||
out := map[string]float64{}
|
||||
for _, line := range strings.Split(string(body), "\n") {
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
i := strings.LastIndexByte(line, ' ')
|
||||
v, err := strconv.ParseFloat(line[i+1:], 64)
|
||||
if err != nil {
|
||||
t.Fatalf("bad metric line %q", line)
|
||||
}
|
||||
out[line[:i]] = v
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestMetrics(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
key := uniq("metrics-")
|
||||
tok, region := e.platformChecker(t, key)
|
||||
owner := e.browser(t)
|
||||
owner.signup("o@"+uniq("id")+".test", uniq("id-"))
|
||||
_, m := owner.do("POST", "/api/v1/org/monitors", map[string]any{
|
||||
"name": "m", "type": "tcp", "target": "example.com:443", "interval_seconds": 3600, "regions": []string{region},
|
||||
})
|
||||
monitor := uuid.MustParse(m["id"].(string))
|
||||
client := agentapi.NewClient(e.srv.URL, tok, uuid.New(), "test").WithHTTPClient(e.srv.Client())
|
||||
at := time.Now().Truncate(time.Millisecond)
|
||||
batch := []agentapi.Result{
|
||||
{MonitorID: monitor, ScheduledAt: at, StartedAt: at, OK: true},
|
||||
{MonitorID: monitor, ScheduledAt: at.Add(time.Second), StartedAt: at.Add(time.Second), OK: false},
|
||||
{MonitorID: uuid.New(), ScheduledAt: at, StartedAt: at, OK: true},
|
||||
}
|
||||
for range 2 {
|
||||
if err := client.Report(context.Background(), batch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
got := e.scrape(t)
|
||||
for series, want := range map[string]float64{
|
||||
`uptimesebi_check_results_total{ok="true",region="` + key + `"}`: 1,
|
||||
`uptimesebi_check_results_total{ok="false",region="` + key + `"}`: 1,
|
||||
`uptimesebi_check_results_rejected_total{reason="duplicate"}`: 3,
|
||||
`uptimesebi_check_results_rejected_total{reason="unknown_monitor"}`: 1,
|
||||
`uptimesebi_checker_instances{region="` + key + `"}`: 0,
|
||||
`uptimesebi_platform_metrics_error`: 0,
|
||||
} {
|
||||
if v, ok := got[series]; !ok || v != want {
|
||||
t.Errorf("%s = %v (present %v), want %v", series, v, ok, want)
|
||||
}
|
||||
}
|
||||
// Other tests share the database, so totals are at least ours.
|
||||
for series, least := range map[string]float64{
|
||||
`uptimesebi_orgs`: 1,
|
||||
`uptimesebi_users`: 1,
|
||||
`uptimesebi_monitors{enabled="true",type="tcp"}`: 1,
|
||||
`uptimesebi_regions{online="false"}`: 1,
|
||||
} {
|
||||
if got[series] < least {
|
||||
t.Errorf("%s = %v, want at least %v", series, got[series], least)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -534,6 +534,7 @@ func (s *Server) RunScheduler(ctx context.Context) {
|
||||
return
|
||||
case <-dispatch.C:
|
||||
n, err := s.sched.Dispatch(ctx)
|
||||
s.metrics.Dispatched(n)
|
||||
if err != nil && ctx.Err() == nil {
|
||||
s.log.WarnContext(ctx, "dispatch failed", "error", err)
|
||||
}
|
||||
@@ -555,19 +556,22 @@ func (s *Server) reconcile(ctx context.Context) {
|
||||
// Taken before reading the database: monitors upserted later survive.
|
||||
start := time.Now()
|
||||
defer func() { s.log.DebugContext(ctx, "schedule reconciled", "took", time.Since(start)) }()
|
||||
var rows []store.ListEnabledMonitorsForScheduleRow
|
||||
err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
rows, err = q.ListEnabledMonitorsForSchedule(ctx)
|
||||
return err
|
||||
})
|
||||
if err == nil {
|
||||
err = s.metrics.Job("reconcile", func() error {
|
||||
var rows []store.ListEnabledMonitorsForScheduleRow
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
rows, err = q.ListEnabledMonitorsForSchedule(ctx)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
want := make([]schedule.Monitor, len(rows))
|
||||
for i, r := range rows {
|
||||
want[i] = schedule.Monitor{ID: r.ID, Interval: time.Duration(r.IntervalSeconds) * time.Second, Regions: r.Regions}
|
||||
}
|
||||
err = s.sched.Reconcile(ctx, want, start)
|
||||
}
|
||||
return s.sched.Reconcile(ctx, want, start)
|
||||
})
|
||||
if err != nil && ctx.Err() == nil {
|
||||
s.log.WarnContext(ctx, "schedule reconciliation failed", "error", err)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (s *Server) runOrgPurges(ctx context.Context) {
|
||||
tick := time.NewTicker(orgPurgeEvery)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
if err := s.PurgeDeletedOrgs(ctx); err != nil && ctx.Err() == nil {
|
||||
if err := s.metrics.Job("org_purge", func() error { return s.PurgeDeletedOrgs(ctx) }); err != nil && ctx.Err() == nil {
|
||||
s.log.ErrorContext(ctx, "purging deleted organizations failed", "error", err)
|
||||
}
|
||||
select {
|
||||
|
||||
@@ -104,7 +104,9 @@ func (s *Server) loginPage(c *gin.Context) {
|
||||
}
|
||||
allowed := email || len(signupProviders) > 0
|
||||
providers := s.platformButtons(c.Request.Context(), false)
|
||||
web.Render(c, http.StatusOK, web.Login(s.pageFor(c, "auth.login.title"), allowed, next, providers, c.Query("mfa") == "1"))
|
||||
p := s.pageFor(c, "auth.login.title")
|
||||
p.Meta = s.publicMeta(c, "/login", "auth.login.title")
|
||||
web.Render(c, http.StatusOK, web.Login(p, allowed, next, providers, c.Query("mfa") == "1"))
|
||||
}
|
||||
|
||||
// signupOptions tells whether people may sign up with email, and which
|
||||
@@ -141,7 +143,9 @@ func (s *Server) signupPage(c *gin.Context) {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
web.Render(c, http.StatusOK, web.Signup(s.pageFor(c, "auth.signup.title"), providers, email, consent))
|
||||
p := s.pageFor(c, "auth.signup.title")
|
||||
p.Meta = s.publicMeta(c, "/signup", "auth.signup.title")
|
||||
web.Render(c, http.StatusOK, web.Signup(p, providers, email, consent))
|
||||
}
|
||||
|
||||
func (s *Server) signupSentPage(c *gin.Context) {
|
||||
|
||||
@@ -39,7 +39,7 @@ func (s *Server) RunRegionWatch(ctx context.Context) {
|
||||
tick := time.NewTicker(regionWatchEvery)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
if err := s.WatchRegions(ctx, time.Now()); err != nil && ctx.Err() == nil {
|
||||
if err := s.metrics.Job("region_watch", func() error { return s.WatchRegions(ctx, time.Now()) }); err != nil && ctx.Err() == nil {
|
||||
s.log.WarnContext(ctx, "watching regions failed", "error", err)
|
||||
}
|
||||
select {
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/ogimage"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
|
||||
)
|
||||
|
||||
// indexable reports whether search engines may list the public pages.
|
||||
// Self-hosted installations keep their sign-in out of search results.
|
||||
func (s *Server) indexable() bool { return s.cloud() }
|
||||
|
||||
// publicMeta describes a public page at path, such as the sign-in, for
|
||||
// search engines and link previews; nil where pages are not indexed.
|
||||
func (s *Server) publicMeta(c *gin.Context, path, titleID string) *web.PageMeta {
|
||||
if !s.indexable() {
|
||||
return nil
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
lang := i18n.Lang(ctx)
|
||||
chosen := s.catalog.IsSupported(c.Query("lang"))
|
||||
title := i18n.T(ctx, titleID) + " · UptimeSebi"
|
||||
image := web.LangURL(s.cfg.PublicURL+"/og.png", lang)
|
||||
return web.NewPageMeta(title, i18n.T(ctx, "meta.app_description"), s.cfg.PublicURL+path, image, "UptimeSebi", lang, chosen, s.catalog.Supported())
|
||||
}
|
||||
|
||||
// appImages keeps the app's preview image per language.
|
||||
type appImages struct {
|
||||
mu sync.Mutex
|
||||
images map[string][]byte
|
||||
}
|
||||
|
||||
// appOGImage serves the preview image of the app's public pages.
|
||||
func (s *Server) appOGImage(c *gin.Context) {
|
||||
l := s.catalog.Match(c.Query("lang"), c.GetHeader("Accept-Language"))
|
||||
ctx := i18n.NewContext(c.Request.Context(), l)
|
||||
s.ogImages.mu.Lock()
|
||||
defer s.ogImages.mu.Unlock()
|
||||
png, ok := s.ogImages.images[l.Lang()]
|
||||
if !ok {
|
||||
host := s.cfg.PublicURL
|
||||
if u, err := url.Parse(host); err == nil {
|
||||
host = u.Host
|
||||
}
|
||||
var err error
|
||||
png, err = ogimage.Render(ogimage.Card{
|
||||
Title: i18n.T(ctx, "meta.app_card_title"),
|
||||
Subtitle: i18n.T(ctx, "meta.app_card_subtitle"),
|
||||
Footer: host,
|
||||
Accent: ogimage.Up,
|
||||
})
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
if s.ogImages.images == nil {
|
||||
s.ogImages.images = map[string][]byte{}
|
||||
}
|
||||
s.ogImages.images[l.Lang()] = png
|
||||
}
|
||||
c.Header("Cache-Control", "public, max-age=86400")
|
||||
c.Data(http.StatusOK, "image/png", png)
|
||||
}
|
||||
|
||||
// robotsTxt lets crawlers read the sign-in, sign-up and legal pages and
|
||||
// nothing else; self-hosted installations turn them away entirely.
|
||||
func (s *Server) robotsTxt(c *gin.Context) {
|
||||
var b strings.Builder
|
||||
b.WriteString("User-agent: *\n")
|
||||
if s.indexable() {
|
||||
for _, p := range []string{"/login", "/signup", "/legal/", "/og.png", "/static/"} {
|
||||
b.WriteString("Allow: " + p + "\n")
|
||||
}
|
||||
}
|
||||
b.WriteString("Disallow: /\n")
|
||||
if s.indexable() {
|
||||
b.WriteString("\nSitemap: " + s.cfg.PublicURL + "/sitemap.xml\n")
|
||||
}
|
||||
c.Header("Cache-Control", "public, max-age=3600")
|
||||
c.Data(http.StatusOK, "text/plain; charset=utf-8", []byte(b.String()))
|
||||
}
|
||||
|
||||
// sitemapXML lists the public pages with their language versions.
|
||||
func (s *Server) sitemapXML(c *gin.Context) {
|
||||
if !s.indexable() {
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
paths := []string{"/login"}
|
||||
if email, providers, err := s.signupOptions(ctx); err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
} else if email || len(providers) > 0 {
|
||||
paths = append(paths, "/signup")
|
||||
}
|
||||
for _, d := range s.platformLegalDocs(ctx) {
|
||||
if d.URL == "" {
|
||||
paths = append(paths, "/legal/"+d.Kind)
|
||||
}
|
||||
}
|
||||
var urls []string
|
||||
for _, p := range paths {
|
||||
urls = append(urls, s.cfg.PublicURL+p)
|
||||
}
|
||||
body, err := web.Sitemap(urls, s.catalog.Supported(), time.Time{})
|
||||
if err != nil {
|
||||
internalError(c, err)
|
||||
return
|
||||
}
|
||||
c.Header("Cache-Control", "public, max-age=3600")
|
||||
c.Data(http.StatusOK, "application/xml; charset=utf-8", body)
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/config"
|
||||
)
|
||||
|
||||
func (b *browser) raw(path string) (int, http.Header, []byte) {
|
||||
b.t.Helper()
|
||||
resp, err := b.hc.Get(b.base + path)
|
||||
if err != nil {
|
||||
b.t.Fatalf("GET %s failed: %v", path, err)
|
||||
}
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return resp.StatusCode, resp.Header, body
|
||||
}
|
||||
|
||||
func TestPublicPagesForSearchEngines(t *testing.T) {
|
||||
const publicURL = "https://app.example.test"
|
||||
cloud := newEnvWith(t, func(c *config.API) {
|
||||
c.Edition, c.SignupVerify, c.PublicURL = config.EditionCloud, "off", publicURL
|
||||
})
|
||||
b := cloud.browser(t)
|
||||
|
||||
_, _, html := b.page("/login?next=/monitors&lang=de")
|
||||
for _, want := range []string{
|
||||
`<link rel="canonical" href="` + publicURL + `/login?lang=de">`,
|
||||
`<link rel="alternate" hreflang="en" href="` + publicURL + `/login?lang=en">`,
|
||||
`<link rel="alternate" hreflang="x-default" href="` + publicURL + `/login">`,
|
||||
`<meta property="og:image" content="` + publicURL + `/og.png?lang=de">`,
|
||||
`<meta name="description" content="UptimeSebi überwacht`,
|
||||
`<html lang="de">`,
|
||||
} {
|
||||
if !strings.Contains(html, want) {
|
||||
t.Errorf("login page lacks %s", want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(html, "noindex") {
|
||||
t.Errorf("login page is noindex in the cloud edition")
|
||||
}
|
||||
if _, _, html := b.page("/signup"); !strings.Contains(html, `<link rel="canonical" href="`+publicURL+`/signup">`) {
|
||||
t.Errorf("signup page lacks its canonical address")
|
||||
}
|
||||
|
||||
_, _, robots := b.raw("/robots.txt")
|
||||
if !strings.Contains(string(robots), "Allow: /login\n") || !strings.Contains(string(robots), "Disallow: /\n") || !strings.Contains(string(robots), "Sitemap: "+publicURL+"/sitemap.xml") {
|
||||
t.Errorf("robots.txt = %q", robots)
|
||||
}
|
||||
code, _, sm := b.raw("/sitemap.xml")
|
||||
if code != http.StatusOK || !strings.Contains(string(sm), "<loc>"+publicURL+"/signup</loc>") || !strings.Contains(string(sm), `hreflang="de" href="`+publicURL+`/login?lang=de"`) {
|
||||
t.Errorf("sitemap = %d %s", code, sm)
|
||||
}
|
||||
code, h, png := b.raw("/og.png?lang=en")
|
||||
if code != http.StatusOK || h.Get("Content-Type") != "image/png" || !bytes.HasPrefix(png, []byte("\x89PNG")) {
|
||||
t.Errorf("preview image = %d %s", code, h.Get("Content-Type"))
|
||||
}
|
||||
|
||||
// Signed in, the console stays out of search engines.
|
||||
b.signup("seo@"+uniq("seo")+".test", uniq("seo-"))
|
||||
if _, _, html := b.page("/"); !strings.Contains(html, `<meta name="robots" content="noindex, nofollow">`) || strings.Contains(html, "og:title") {
|
||||
t.Errorf("console page is indexable")
|
||||
}
|
||||
|
||||
// Self-hosted installations keep everything out.
|
||||
self := newEnv(t).browser(t)
|
||||
if _, _, html := self.page("/login"); !strings.Contains(html, "noindex") || strings.Contains(html, "canonical") {
|
||||
t.Errorf("self-hosted login page is indexable")
|
||||
}
|
||||
if _, _, robots := self.raw("/robots.txt"); string(robots) != "User-agent: *\nDisallow: /\n" {
|
||||
t.Errorf("self-hosted robots.txt = %q", robots)
|
||||
}
|
||||
if code, _, _ := self.raw("/sitemap.xml"); code != http.StatusNotFound {
|
||||
t.Errorf("self-hosted sitemap = %d, want 404", code)
|
||||
}
|
||||
}
|
||||
+21
-2
@@ -18,6 +18,7 @@ import (
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/config"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/evaluate"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/metrics"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/notify"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/requestid"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/schedule"
|
||||
@@ -70,6 +71,10 @@ type Server struct {
|
||||
|
||||
// publicRegions caches the answer of the public region list.
|
||||
publicRegions publicRegionsCache
|
||||
// ogImages keeps the preview image of the public pages.
|
||||
ogImages appImages
|
||||
// metrics counts what the instance does, for Prometheus.
|
||||
metrics *metrics.Metrics
|
||||
}
|
||||
|
||||
// Deps are the external resources a Server needs.
|
||||
@@ -79,6 +84,8 @@ type Deps struct {
|
||||
Redis redis.UniversalClient
|
||||
Keys *sealed.Keyring
|
||||
Catalog *i18n.Catalog
|
||||
// Metrics, if nil, are created for the Server alone.
|
||||
Metrics *metrics.Metrics
|
||||
}
|
||||
|
||||
// New returns a Server. It does not register any routes; see Mount.
|
||||
@@ -86,7 +93,12 @@ type Deps struct {
|
||||
func New(cfg config.API, d Deps) *Server {
|
||||
allowPrivate := cfg.SSOAllowPrivate()
|
||||
mail, _ := notify.ParseSMTP(cfg.SMTPURL)
|
||||
return &Server{
|
||||
m := d.Metrics
|
||||
if m == nil {
|
||||
m = metrics.New(string(cfg.Edition))
|
||||
}
|
||||
s := &Server{
|
||||
metrics: m,
|
||||
orgPurges: make(chan struct{}, 1),
|
||||
eval: evaluate.New(d.Redis),
|
||||
smtp: mail,
|
||||
@@ -109,6 +121,8 @@ func New(cfg config.API, d Deps) *Server {
|
||||
support: newVersioned[supportSettings]("support"),
|
||||
pageHome: newVersioned[string]("statuspage-home"),
|
||||
}
|
||||
m.Register(&platformCollector{s: s})
|
||||
return s
|
||||
}
|
||||
|
||||
// EndLongPollsOn makes the checkers' long polls return as soon as ch is
|
||||
@@ -132,6 +146,9 @@ func (s *Server) Mount(r gin.IRouter) {
|
||||
r.GET("/api/openapi.json", s.openAPIJSON)
|
||||
// Public data for websites: no session, no CSRF.
|
||||
r.GET("/api/v1/public/regions", s.listPublicRegions)
|
||||
r.GET("/robots.txt", s.robotsTxt)
|
||||
r.GET("/sitemap.xml", s.sitemapXML)
|
||||
r.GET("/og.png", s.appOGImage)
|
||||
r.GET("/install.sh", s.installScript)
|
||||
g.GET("/api/docs", s.apiDocsPage)
|
||||
|
||||
@@ -336,7 +353,9 @@ func (s *Server) localize() gin.HandlerFunc {
|
||||
pref = sess.Locale
|
||||
}
|
||||
cookie, _ := c.Cookie(localeCookie)
|
||||
l := s.catalog.Match(pref, cookie, c.GetHeader("Accept-Language"))
|
||||
// ?lang= shows a page in that language, so each language of the
|
||||
// public pages has an address of its own.
|
||||
l := s.catalog.Match(c.Query("lang"), pref, cookie, c.GetHeader("Accept-Language"))
|
||||
c.Request = c.Request.WithContext(i18n.NewContext(c.Request.Context(), l))
|
||||
c.Header("Content-Language", l.Lang())
|
||||
c.Header("Vary", "Accept-Language, Cookie")
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/api"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/config"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/metrics"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/migrations"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/platform"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/sealed"
|
||||
@@ -37,6 +38,8 @@ type env struct {
|
||||
dbPool *pgxpool.Pool
|
||||
rdb *redis.Client
|
||||
api *api.Server
|
||||
// metrics are the API's own, as cmd/api serves them.
|
||||
metrics *metrics.Metrics
|
||||
}
|
||||
|
||||
func newEnv(t *testing.T) *env {
|
||||
@@ -104,7 +107,8 @@ func newEnvWith(t *testing.T, adjust func(*config.API)) *env {
|
||||
if adjust != nil {
|
||||
adjust(&cfg)
|
||||
}
|
||||
e.api = api.New(cfg, api.Deps{Log: log, DB: tenant.New(pool), Redis: rdb, Keys: keys, Catalog: catalog})
|
||||
e.metrics = metrics.New(string(cfg.Edition))
|
||||
e.api = api.New(cfg, api.Deps{Log: log, DB: tenant.New(pool), Redis: rdb, Keys: keys, Catalog: catalog, Metrics: e.metrics})
|
||||
e.api.Mount(r)
|
||||
return e
|
||||
}
|
||||
|
||||
+69
-19
@@ -1,6 +1,8 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
@@ -24,6 +26,7 @@ import (
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/check"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/evaluate"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/platform"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
|
||||
@@ -190,7 +193,7 @@ func (s *Server) buildSnapshot(ctx context.Context, page store.StatusPage) (agen
|
||||
comp := agentapi.Component{
|
||||
ID: m.MonitorID.String(),
|
||||
Name: name,
|
||||
Uptime: uptime90,
|
||||
Uptime: roundRatio(uptime90),
|
||||
Days: dayHistory(days[m.MonitorID], now),
|
||||
}
|
||||
switch {
|
||||
@@ -308,7 +311,7 @@ func buildComponentDetails(
|
||||
ts := endHour.Add(-time.Duration(23-i) * time.Hour)
|
||||
hours[i] = agentapi.HourBucket{Time: ts, Uptime: -1}
|
||||
if b, ok := byHour[ts.Unix()]; ok && b.Total > 0 {
|
||||
hours[i].Uptime = float64(b.OK) / float64(b.Total)
|
||||
hours[i].Uptime = roundRatio(float64(b.OK) / float64(b.Total))
|
||||
hours[i].AvgLatencyMS = int(math.Round(float64(b.Latency)))
|
||||
}
|
||||
}
|
||||
@@ -330,10 +333,10 @@ func buildComponentDetails(
|
||||
}
|
||||
slices.SortFunc(regs, func(a, b agentapi.ComponentRegion) int { return strings.Compare(a.Name, b.Name) })
|
||||
return &agentapi.ComponentDetails{
|
||||
SLA24h: web.Uptime(hourly),
|
||||
SLA7d: web.Uptime(d7),
|
||||
SLA30d: web.Uptime(d30),
|
||||
SLA90d: uptime90,
|
||||
SLA24h: roundRatio(web.Uptime(hourly)),
|
||||
SLA7d: roundRatio(web.Uptime(d7)),
|
||||
SLA30d: roundRatio(web.Uptime(d30)),
|
||||
SLA90d: roundRatio(uptime90),
|
||||
Hours: hours,
|
||||
Regions: regs,
|
||||
}
|
||||
@@ -350,12 +353,24 @@ func dayHistory(buckets []web.Bucket, now time.Time) []agentapi.Day {
|
||||
d := start.AddDate(0, 0, i).Format(time.DateOnly)
|
||||
out[i] = agentapi.Day{Date: d, Uptime: -1}
|
||||
if b, ok := byDay[d]; ok && b.Total > 0 {
|
||||
out[i].Uptime = float64(b.OK) / float64(b.Total)
|
||||
out[i].Uptime = roundRatio(float64(b.OK) / float64(b.Total))
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// roundRatio rounds an uptime ratio to six decimals, finer than any page
|
||||
// shows it. Unrounded, a ratio takes up to 18 characters, and a large page
|
||||
// holds 90 of them for every component. A ratio below 1 stays below 1, so
|
||||
// a page never shows 100% for a component that failed.
|
||||
func roundRatio(r float64) float64 {
|
||||
v := math.Round(r*1e6) / 1e6
|
||||
if v >= 1 && r < 1 {
|
||||
return 0.999999
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// agentPage serves a page snapshot to status page servers. Org-owned
|
||||
// servers only receive their own org's pages.
|
||||
func (s *Server) agentPage(c *gin.Context) {
|
||||
@@ -385,36 +400,71 @@ func (s *Server) agentPage(c *gin.Context) {
|
||||
}
|
||||
// The server sends the checksum of its copy; an unchanged page is not
|
||||
// sent again.
|
||||
etag := `"` + snap.Checksum() + `"`
|
||||
c.Header("ETag", etag)
|
||||
if c.GetHeader("If-None-Match") == etag {
|
||||
c.Header("ETag", snap.etag)
|
||||
if c.GetHeader("If-None-Match") == snap.etag {
|
||||
c.Status(http.StatusNotModified)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, snap)
|
||||
// The encoded page is shared by everyone asking for it at once; large
|
||||
// pages run to megabytes, encoding them per request ran the API out of
|
||||
// memory.
|
||||
body := snap.json
|
||||
if platform.AcceptsGzip(c.GetHeader("Accept-Encoding")) {
|
||||
c.Header("Content-Encoding", "gzip")
|
||||
body = snap.gzip
|
||||
}
|
||||
c.Data(http.StatusOK, "application/json; charset=utf-8", body)
|
||||
}
|
||||
|
||||
// encodedSnapshot is a page snapshot as sent to status page servers.
|
||||
type encodedSnapshot struct {
|
||||
etag string
|
||||
json []byte
|
||||
gzip []byte
|
||||
}
|
||||
|
||||
// encodeSnapshot encodes snap once, as JSON and gzipped JSON.
|
||||
func encodeSnapshot(snap agentapi.PageSnapshot) (encodedSnapshot, error) {
|
||||
raw, err := json.Marshal(snap)
|
||||
if err != nil {
|
||||
return encodedSnapshot{}, err
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
zw := gzip.NewWriter(&buf)
|
||||
if _, err := zw.Write(raw); err != nil {
|
||||
return encodedSnapshot{}, err
|
||||
}
|
||||
if err := zw.Close(); err != nil {
|
||||
return encodedSnapshot{}, err
|
||||
}
|
||||
return encodedSnapshot{etag: `"` + snap.Checksum() + `"`, json: raw, gzip: buf.Bytes()}, nil
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// sharedSnapshot builds and encodes 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) (encodedSnapshot, 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)
|
||||
snap, err := s.buildSnapshot(ctx, page)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return encodeSnapshot(snap)
|
||||
})
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return agentapi.PageSnapshot{}, ctx.Err()
|
||||
return encodedSnapshot{}, ctx.Err()
|
||||
case r := <-ch:
|
||||
if r.Err != nil {
|
||||
return agentapi.PageSnapshot{}, r.Err
|
||||
return encodedSnapshot{}, r.Err
|
||||
}
|
||||
return r.Val.(agentapi.PageSnapshot), nil
|
||||
return r.Val.(encodedSnapshot), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package api
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRoundRatio(t *testing.T) {
|
||||
for _, c := range []struct{ in, want float64 }{
|
||||
{1, 1},
|
||||
{-1, -1},
|
||||
{0, 0},
|
||||
{0.99930555555556, 0.999306},
|
||||
{0.99, 0.99},
|
||||
// One failure in millions still is not 100%.
|
||||
{0.9999997, 0.999999},
|
||||
} {
|
||||
if got := roundRatio(c.in); got != c.want {
|
||||
t.Errorf("roundRatio(%v) = %v, want %v", c.in, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -481,3 +483,75 @@ func TestStatusPageGroupsAndDetails(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestAgentPageEncoding fetches a page as a status page server would, with
|
||||
// and without gzip, and through both the HTTP API and the client.
|
||||
func TestAgentPageEncoding(t *testing.T) {
|
||||
e := newEnv(t)
|
||||
ctx := context.Background()
|
||||
owner := e.browser(t)
|
||||
owner.signup("o@"+uniq("enc")+".test", uniq("enc-"))
|
||||
slug := uniq("enc-")
|
||||
_, body := owner.do("POST", "/api/v1/org/statuspages", map[string]any{"slug": slug, "title": "Encoded"})
|
||||
owner.do("PUT", "/api/v1/org/statuspages/"+body["id"].(string), map[string]any{"slug": slug, "title": "Encoded", "published": true})
|
||||
|
||||
tok, params := api.NewAgentToken(nil, "statuspage", "sp-"+uuid.NewString()[:6], nil)
|
||||
if err := tenant.New(e.dbPool).Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
_, err := q.CreateAgent(ctx, params)
|
||||
return err
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// No transparent decompression: the test sees what the API sends.
|
||||
hc := &http.Client{Transport: &http.Transport{DisableCompression: true, TLSClientConfig: e.srv.Client().Transport.(*http.Transport).TLSClientConfig}}
|
||||
get := func(header map[string]string) *http.Response {
|
||||
t.Helper()
|
||||
req, _ := http.NewRequest(http.MethodGet, e.srv.URL+"/agent/v1/pages?slug="+slug, nil)
|
||||
req.Header.Set("Authorization", "Bearer "+tok)
|
||||
req.Header.Set(agentapi.VersionHeader, strconv.Itoa(agentapi.Version))
|
||||
req.Header.Set(agentapi.InstanceHeader, uuid.NewString())
|
||||
for k, v := range header {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = resp.Body.Close() })
|
||||
return resp
|
||||
}
|
||||
|
||||
plain := get(nil)
|
||||
raw, _ := io.ReadAll(plain.Body)
|
||||
var snap agentapi.PageSnapshot
|
||||
if plain.StatusCode != http.StatusOK || plain.Header.Get("Content-Encoding") != "" || json.Unmarshal(raw, &snap) != nil || snap.Title != "Encoded" {
|
||||
t.Fatalf("plain page = %d %q %.200s", plain.StatusCode, plain.Header.Get("Content-Encoding"), raw)
|
||||
}
|
||||
etag := plain.Header.Get("ETag")
|
||||
if etag != `"`+snap.Checksum()+`"` {
|
||||
t.Errorf("ETag = %s, want the checksum %s", etag, snap.Checksum())
|
||||
}
|
||||
|
||||
packed := get(map[string]string{"Accept-Encoding": "gzip"})
|
||||
if packed.Header.Get("Content-Encoding") != "gzip" || packed.Header.Get("ETag") != etag {
|
||||
t.Fatalf("gzip page encoding %q, ETag %q; want gzip and %s", packed.Header.Get("Content-Encoding"), packed.Header.Get("ETag"), etag)
|
||||
}
|
||||
zr, err := gzip.NewReader(packed.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var unpacked agentapi.PageSnapshot
|
||||
if err := json.NewDecoder(zr).Decode(&unpacked); err != nil || unpacked.Checksum() != snap.Checksum() {
|
||||
t.Errorf("the gzipped page differs from the plain one: %v", err)
|
||||
}
|
||||
|
||||
if st := get(map[string]string{"If-None-Match": etag, "Accept-Encoding": "gzip"}).StatusCode; st != http.StatusNotModified {
|
||||
t.Errorf("page with the current ETag = %d, want 304", st)
|
||||
}
|
||||
|
||||
// The client asks for gzip and unpacks it, over plain HTTP too.
|
||||
client := agentapi.NewClient(e.srv.URL, tok, uuid.New(), "test").WithHTTPClient(e.srv.Client())
|
||||
if got, err := client.Page(ctx, "", slug); err != nil || got.Checksum() != snap.Checksum() {
|
||||
t.Errorf("client Page() = %q, %v; want the same page", got.Title, err)
|
||||
}
|
||||
}
|
||||
@@ -314,6 +314,7 @@ func (s *Server) deliverSubscriberBatch(ctx context.Context) int {
|
||||
}
|
||||
for _, n := range rows {
|
||||
sendErr := s.smtp.Send(ctx, s.subscriberMail(n))
|
||||
s.metrics.SubscriberMail(sendErr)
|
||||
err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
if sendErr == nil {
|
||||
return q.MarkSubscriberNotificationSent(ctx, n.ID)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"math/rand/v2"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -30,6 +31,9 @@ const (
|
||||
// quickPoll is a long poll answered empty faster than any wait would.
|
||||
quickPoll = 200 * time.Millisecond
|
||||
flushInterval = 2 * time.Second
|
||||
// fullHeartbeat is how often a checker with every slot busy still polls,
|
||||
// so the API keeps it live; well below schedule.StaleAfter.
|
||||
fullHeartbeat = 5 * time.Second
|
||||
// maxPending bounds results kept while the API is unreachable.
|
||||
maxPending = 50_000
|
||||
)
|
||||
@@ -39,6 +43,8 @@ type Runner struct {
|
||||
api API
|
||||
log *slog.Logger
|
||||
slots chan struct{}
|
||||
// freed is signalled when a slot is freed, for a poll waiting for one.
|
||||
freed chan struct{}
|
||||
run func(context.Context, check.Spec) check.Outcome
|
||||
|
||||
results chan agentapi.Result
|
||||
@@ -46,6 +52,8 @@ type Runner struct {
|
||||
|
||||
evidenceMu sync.Mutex
|
||||
evidence map[uuid.UUID]evidenceState
|
||||
// jitter returns a random duration in [0, d), replaced in tests.
|
||||
jitter func(d time.Duration) time.Duration
|
||||
}
|
||||
|
||||
// evidenceState remembers what was last sent for a monitor.
|
||||
@@ -61,13 +69,23 @@ const evidenceEvery = 10 * time.Minute
|
||||
// shouldSendEvidence decides whether a result carries its evidence: every
|
||||
// failure, every change between success and failure, and otherwise every
|
||||
// evidenceEvery. Most results thus stay small.
|
||||
//
|
||||
// Evidence sent for another reason than the period, like the first result
|
||||
// after a start, puts the next periodic one at a random point of the
|
||||
// period. Otherwise every monitor would send its evidence in the same
|
||||
// minute every period after a restart, and the API would have to store all
|
||||
// of it at once.
|
||||
func (r *Runner) shouldSendEvidence(monitor uuid.UUID, ok bool, now time.Time) bool {
|
||||
r.evidenceMu.Lock()
|
||||
defer r.evidenceMu.Unlock()
|
||||
last, seen := r.evidence[monitor]
|
||||
send := !ok || !seen || last.ok != ok || now.Sub(last.sent) >= evidenceEvery
|
||||
if send {
|
||||
periodic := seen && last.ok == ok && now.Sub(last.sent) >= evidenceEvery
|
||||
send := !ok || !seen || last.ok != ok || periodic
|
||||
switch {
|
||||
case periodic:
|
||||
last.sent = now
|
||||
case send:
|
||||
last.sent = now.Add(-r.jitter(evidenceEvery))
|
||||
}
|
||||
last.ok = ok
|
||||
r.evidence[monitor] = last
|
||||
@@ -80,10 +98,12 @@ func New(api API, concurrency int, log *slog.Logger) *Runner {
|
||||
api: api,
|
||||
log: log,
|
||||
slots: make(chan struct{}, max(concurrency, 1)),
|
||||
freed: make(chan struct{}, 1),
|
||||
run: check.Run,
|
||||
results: make(chan agentapi.Result, 1024),
|
||||
|
||||
evidence: map[uuid.UUID]evidenceState{},
|
||||
jitter: rand.N[time.Duration],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,19 +190,49 @@ func (r *Runner) poll(ctx context.Context, running *sync.WaitGroup) error {
|
||||
r.slots <- struct{}{}
|
||||
running.Add(1)
|
||||
go func() {
|
||||
defer func() { <-r.slots; running.Done() }()
|
||||
defer func() { r.release(); running.Done() }()
|
||||
r.results <- r.execute(ctx, j)
|
||||
}()
|
||||
}
|
||||
// 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) {
|
||||
switch {
|
||||
case free == 0:
|
||||
// Take work again as soon as a check finishes, not after a
|
||||
// fixed pause, which would cap throughput at slots per pause.
|
||||
r.waitForSlot(ctx, fullHeartbeat)
|
||||
case len(jobs) == 0 && wait > 0 && time.Since(asked) < quickPoll:
|
||||
// A long poll answered empty at once, as by an instance
|
||||
// shutting down, is not repeated at once either.
|
||||
sleep(ctx, time.Second)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// release frees a slot and wakes a poll waiting for one.
|
||||
func (r *Runner) release() {
|
||||
<-r.slots
|
||||
select {
|
||||
case r.freed <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
// waitForSlot returns once a slot is free, ctx is done or at most after
|
||||
// d.
|
||||
func (r *Runner) waitForSlot(ctx context.Context, d time.Duration) {
|
||||
t := time.NewTimer(d)
|
||||
defer t.Stop()
|
||||
for len(r.slots) == cap(r.slots) {
|
||||
select {
|
||||
case <-r.freed:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-t.C:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Runner) execute(ctx context.Context, j agentapi.Job) agentapi.Result {
|
||||
// Checks already started finish even during shutdown; their timeout
|
||||
// bounds them.
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
func TestEvidencePolicy(t *testing.T) {
|
||||
r := New(nil, 1, slog.New(slog.DiscardHandler))
|
||||
r.jitter = func(time.Duration) time.Duration { return 0 }
|
||||
m := uuid.New()
|
||||
now := time.Now()
|
||||
steps := []struct {
|
||||
@@ -31,3 +32,39 @@ func TestEvidencePolicy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestEvidenceSpreadsAfterStart starts with many healthy monitors at once:
|
||||
// their periodic evidence must not all fall into the same minute again.
|
||||
func TestEvidenceSpreadsAfterStart(t *testing.T) {
|
||||
r := New(nil, 1, slog.New(slog.DiscardHandler))
|
||||
start := time.Now()
|
||||
const monitors = 600
|
||||
ids := make([]uuid.UUID, monitors)
|
||||
for i := range ids {
|
||||
ids[i] = uuid.New()
|
||||
if !r.shouldSendEvidence(ids[i], true, start) {
|
||||
t.Fatal("first result sent no evidence")
|
||||
}
|
||||
}
|
||||
// One result per monitor and minute over the next period.
|
||||
perMinute := map[int]int{}
|
||||
for minute := 1; minute <= int(evidenceEvery/time.Minute); minute++ {
|
||||
for _, id := range ids {
|
||||
if r.shouldSendEvidence(id, true, start.Add(time.Duration(minute)*time.Minute)) {
|
||||
perMinute[minute]++
|
||||
}
|
||||
}
|
||||
}
|
||||
total, peak := 0, 0
|
||||
for _, n := range perMinute {
|
||||
total += n
|
||||
peak = max(peak, n)
|
||||
}
|
||||
if total != monitors {
|
||||
t.Errorf("periodic evidence in the first period = %d, want one per monitor, %d", total, monitors)
|
||||
}
|
||||
// 60 a minute on average; all 600 in one minute without the jitter.
|
||||
if peak > 150 {
|
||||
t.Errorf("busiest minute sent %d evidence, want them spread at about %d a minute", peak, monitors/10)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package checker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/check"
|
||||
)
|
||||
|
||||
// backlogAPI hands out queued jobs as fast as the checker asks for them.
|
||||
type backlogAPI struct {
|
||||
mu sync.Mutex
|
||||
queued int
|
||||
polls int
|
||||
reported atomic.Int64
|
||||
}
|
||||
|
||||
func (b *backlogAPI) Jobs(ctx context.Context, max int, wait time.Duration) ([]agentapi.Job, error) {
|
||||
b.mu.Lock()
|
||||
b.polls++
|
||||
n := min(max, b.queued)
|
||||
b.queued -= n
|
||||
b.mu.Unlock()
|
||||
if n == 0 {
|
||||
select {
|
||||
case <-time.After(min(wait, 50*time.Millisecond)):
|
||||
case <-ctx.Done():
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
jobs := make([]agentapi.Job, n)
|
||||
for i := range jobs {
|
||||
jobs[i] = agentapi.Job{MonitorID: uuid.New(), Type: "tcp", Target: "x:1"}
|
||||
}
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
func (b *backlogAPI) Report(_ context.Context, rs []agentapi.Result) error {
|
||||
b.reported.Add(int64(len(rs)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *backlogAPI) Release(context.Context) error { return nil }
|
||||
|
||||
// TestFullCheckerTakesWorkAsSlotsFree runs a backlog through a single slot.
|
||||
// A checker pausing a second whenever its slots are full would need about a
|
||||
// second per job.
|
||||
func TestFullCheckerTakesWorkAsSlotsFree(t *testing.T) {
|
||||
const jobs = 10
|
||||
api := &backlogAPI{queued: jobs}
|
||||
r := New(api, 1, slog.New(slog.DiscardHandler))
|
||||
var ran atomic.Int64
|
||||
r.run = func(context.Context, check.Spec) check.Outcome {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
ran.Add(1)
|
||||
return check.Outcome{OK: true}
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- r.Run(ctx, time.Second) }()
|
||||
|
||||
start := time.Now()
|
||||
for ran.Load() < jobs && time.Since(start) < 5*time.Second {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
took := time.Since(start)
|
||||
cancel()
|
||||
if err := <-done; err != nil {
|
||||
t.Errorf("Run() = %v", err)
|
||||
}
|
||||
if n := ran.Load(); n != jobs {
|
||||
t.Fatalf("ran %d checks in %v, want %d", n, took, jobs)
|
||||
}
|
||||
if took > 2*time.Second {
|
||||
t.Errorf("%d checks through one slot took %v, want well under a second each", jobs, took)
|
||||
}
|
||||
if n := api.reported.Load(); n != jobs {
|
||||
t.Errorf("reported %d results, want %d", n, jobs)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWaitForSlotKeepsPolling bounds the wait, so a checker whose slots
|
||||
// stay busy still polls as a heartbeat.
|
||||
func TestWaitForSlotKeepsPolling(t *testing.T) {
|
||||
r := New(nil, 1, slog.New(slog.DiscardHandler))
|
||||
r.slots <- struct{}{}
|
||||
start := time.Now()
|
||||
r.waitForSlot(context.Background(), 50*time.Millisecond)
|
||||
if took := time.Since(start); took < 50*time.Millisecond || took > time.Second {
|
||||
t.Errorf("waitForSlot() with every slot busy returned after %v, want the bound of 50ms", took)
|
||||
}
|
||||
go func() {
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
r.release()
|
||||
}()
|
||||
start = time.Now()
|
||||
r.waitForSlot(context.Background(), 5*time.Second)
|
||||
if took := time.Since(start); took > time.Second {
|
||||
t.Errorf("waitForSlot() returned %v after a slot was freed, want at once", took)
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,9 @@ const (
|
||||
SignupClosed SignupMode = "closed"
|
||||
)
|
||||
|
||||
// MetricsOff switches the metrics listener off.
|
||||
const MetricsOff = "off"
|
||||
|
||||
// API configures cmd/api.
|
||||
type API struct {
|
||||
Common
|
||||
@@ -77,6 +80,11 @@ type API struct {
|
||||
Listen string `env:"UPTIME_API_LISTEN" envDefault:":8080"`
|
||||
SecretKeys string `env:"UPTIME_SECRET_KEYS"`
|
||||
Signup SignupMode `env:"UPTIME_SIGNUP" envDefault:"first-user"`
|
||||
|
||||
// MetricsListen is where Prometheus metrics are served, apart from the
|
||||
// public listener; "off" switches them off.
|
||||
MetricsListen string `env:"UPTIME_API_METRICS_LISTEN" envDefault:":9090"`
|
||||
|
||||
// SignupVerify is "auto", "required" or "off": whether new accounts
|
||||
// confirm their email address before signing in. Auto requires it in
|
||||
// the cloud edition and wherever mail can be sent.
|
||||
|
||||
@@ -1000,6 +1000,9 @@
|
||||
"members.step_down_confirm": "Als Owner zurücktreten? Ohne andere Rollen arbeitest du mit der Admin-Rolle weiter.",
|
||||
"members.title": "Mitglieder",
|
||||
"members.unassign": "Rolle entfernen",
|
||||
"meta.app_card_subtitle": "Monitore, Alarme und Statusseiten, Open Source",
|
||||
"meta.app_card_title": "Uptime-Monitoring und Statusseiten",
|
||||
"meta.app_description": "UptimeSebi überwacht Websites, Server und Dienste aus mehreren Regionen, alarmiert bei Ausfällen und betreibt öffentliche Statusseiten. Open Source.",
|
||||
"moderation.actions": "Sperren oder löschen …",
|
||||
"moderation.created": "Erstellt",
|
||||
"moderation.delete_confirm_org": "Organisation {{.Name}} mit allen Monitoren, Ergebnissen und Statusseiten endgültig löschen?",
|
||||
@@ -1127,6 +1130,7 @@
|
||||
"monitors.ping_intro": "Rufe diese URL am Ende jedes erfolgreichen Laufs auf, per GET, HEAD oder POST. Mit angehängtem /fail meldest du einen Fehler; ein POST-Body oder ?msg= wird als Meldung gespeichert.",
|
||||
"monitors.ping_secret": "Halte die URL geheim: Wer sie kennt, kann den Job als gesund melden. Nur Mitglieder, die diesen Monitor bearbeiten dürfen, sehen sie.",
|
||||
"monitors.ping_url": "Ping-URL",
|
||||
"monitors.platform_regions_limit": "Bis zu {{.Max}} Plattform-Regionen pro Monitor; eigene Regionen zählen nicht.",
|
||||
"monitors.prom_empty_ok": "Keine Daten sind in Ordnung",
|
||||
"monitors.prom_hint": "Ziel ist die Basis-URL von Prometheus, z. B. https://prometheus.example.com. Thanos, Mimir und VictoriaMetrics funktionieren ebenso. Für geschützte Server Authorization-Header nutzen.",
|
||||
"monitors.prom_mode": "Serien",
|
||||
@@ -1143,6 +1147,7 @@
|
||||
"monitors.recent": "Letzte Checks",
|
||||
"monitors.regions": "Regionen",
|
||||
"monitors.regions_hint": "Geprüft von einem zufälligen Checker jeder gewählten Region. Deine eigenen Regionen stehen oben.",
|
||||
"monitors.regions_limit": "Bis zu {{.Max}} Regionen pro Monitor.",
|
||||
"monitors.results_title": "Prüfergebnisse",
|
||||
"monitors.search": "Nach Name oder Ziel suchen",
|
||||
"monitors.secret_unchanged": "unverändert",
|
||||
@@ -1256,6 +1261,7 @@
|
||||
"page.incidents": "Letzte Vorfälle",
|
||||
"page.maintenance_ongoing": "Laufende Wartung",
|
||||
"page.maintenance_upcoming": "Geplante Wartung",
|
||||
"page.meta_description": "Aktueller Status von {{.Title}}: {{.Status}}. Störungen und geplante Wartungen auf einen Blick.",
|
||||
"page.no_incidents": "Keine Vorfälle in den letzten 14 Tagen.",
|
||||
"page.stale": "Live-Aktualisierung derzeit nicht verfügbar. Diese Seite zeigt den Stand von {{.Time}}.",
|
||||
"page.status.degraded": "Einige Systeme haben Probleme",
|
||||
|
||||
@@ -1000,6 +1000,9 @@
|
||||
"members.step_down_confirm": "Step down as owner? You keep working with the Admin role unless you have other roles.",
|
||||
"members.title": "Members",
|
||||
"members.unassign": "Remove role",
|
||||
"meta.app_card_subtitle": "Monitors, alerts and status pages, open source",
|
||||
"meta.app_card_title": "Uptime monitoring and status pages",
|
||||
"meta.app_description": "UptimeSebi watches websites, servers and services from several regions, alerts you on outages and runs public status pages. Open source.",
|
||||
"moderation.actions": "Suspend or delete …",
|
||||
"moderation.created": "Created",
|
||||
"moderation.delete_confirm_org": "Delete the organization {{.Name}} with all its monitors, results and status pages for good?",
|
||||
@@ -1127,6 +1130,7 @@
|
||||
"monitors.ping_intro": "Call this URL at the end of every successful run, with GET, HEAD or POST. Append /fail to report a failure; a POST body or ?msg= is stored as the message.",
|
||||
"monitors.ping_secret": "Keep the URL secret: anyone who knows it can report the job as healthy. Only members who may edit this monitor see it.",
|
||||
"monitors.ping_url": "Ping URL",
|
||||
"monitors.platform_regions_limit": "Up to {{.Max}} platform regions per monitor; your own regions do not count.",
|
||||
"monitors.prom_empty_ok": "No data is fine",
|
||||
"monitors.prom_hint": "Target is the Prometheus base URL, e.g. https://prometheus.example.com. Thanos, Mimir and VictoriaMetrics work as well. Use Authorization headers for protected servers.",
|
||||
"monitors.prom_mode": "Series",
|
||||
@@ -1143,6 +1147,7 @@
|
||||
"monitors.recent": "Recent checks",
|
||||
"monitors.regions": "Regions",
|
||||
"monitors.regions_hint": "Checked from a random checker in each selected region. Your own regions are listed first.",
|
||||
"monitors.regions_limit": "Up to {{.Max}} regions per monitor.",
|
||||
"monitors.results_title": "Check results",
|
||||
"monitors.search": "Search by name or target",
|
||||
"monitors.secret_unchanged": "unchanged",
|
||||
@@ -1256,6 +1261,7 @@
|
||||
"page.incidents": "Recent incidents",
|
||||
"page.maintenance_ongoing": "Maintenance in progress",
|
||||
"page.maintenance_upcoming": "Planned maintenance",
|
||||
"page.meta_description": "Current status of {{.Title}}: {{.Status}}. Incidents and planned maintenance at a glance.",
|
||||
"page.no_incidents": "No incidents in the last 14 days.",
|
||||
"page.stale": "Live updates are currently unavailable. This page shows the status as of {{.Time}}.",
|
||||
"page.status.degraded": "Some systems are experiencing problems",
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
// Package metrics holds the Prometheus metrics of the API for operators:
|
||||
// requests, the checker pipeline, notifications, background jobs and the
|
||||
// connection pools. Every Metrics has a registry of its own, so tests and
|
||||
// replicas never share state.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo"
|
||||
)
|
||||
|
||||
const namespace = "uptimesebi"
|
||||
|
||||
// Metrics are the instruments the API updates as it works.
|
||||
type Metrics struct {
|
||||
reg *prometheus.Registry
|
||||
|
||||
requests *prometheus.CounterVec
|
||||
duration *prometheus.HistogramVec
|
||||
inFlight prometheus.Gauge
|
||||
dispatched prometheus.Counter
|
||||
stale prometheus.Counter
|
||||
results *prometheus.CounterVec
|
||||
rejected *prometheus.CounterVec
|
||||
resultDelay prometheus.Histogram
|
||||
notifications *prometheus.CounterVec
|
||||
notifyDuration *prometheus.HistogramVec
|
||||
subscriberMail *prometheus.CounterVec
|
||||
incidents *prometheus.CounterVec
|
||||
jobRuns *prometheus.CounterVec
|
||||
jobDuration *prometheus.HistogramVec
|
||||
jobSuccess *prometheus.GaugeVec
|
||||
}
|
||||
|
||||
// New returns Metrics with the Go runtime, process and build metrics
|
||||
// registered. edition labels the build info.
|
||||
func New(edition string) *Metrics {
|
||||
reg := prometheus.NewRegistry()
|
||||
m := &Metrics{
|
||||
reg: reg,
|
||||
requests: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace, Name: "http_requests_total",
|
||||
Help: "HTTP requests by method, route and status code. Requests no route matches have the route \"unmatched\".",
|
||||
}, []string{"method", "route", "code"}),
|
||||
duration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace, Name: "http_request_duration_seconds",
|
||||
Help: "Time to answer HTTP requests, without long polls and event streams.",
|
||||
Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10},
|
||||
}, []string{"method", "route"}),
|
||||
inFlight: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: namespace, Name: "http_requests_in_flight",
|
||||
Help: "HTTP requests being answered, long polls and event streams included.",
|
||||
}),
|
||||
dispatched: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace, Name: "checks_dispatched_total",
|
||||
Help: "Checks this instance moved from the schedule to the checkers' queues.",
|
||||
}),
|
||||
stale: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace, Name: "checks_stale_total",
|
||||
Help: "Queued checks dropped because they waited longer than two intervals; a newer run of the monitor was queued by then.",
|
||||
}),
|
||||
results: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace, Name: "check_results_total",
|
||||
Help: "Check results stored, by region (\"own\" for organizations' own checkers) and outcome.",
|
||||
}, []string{"region", "ok"}),
|
||||
rejected: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace, Name: "check_results_rejected_total",
|
||||
Help: "Check results not stored: duplicate (a retried report), unknown_monitor (not checked in the region) or bad_time (timestamp out of range).",
|
||||
}, []string{"reason"}),
|
||||
resultDelay: prometheus.NewHistogram(prometheus.HistogramOpts{
|
||||
Namespace: namespace, Name: "check_result_delay_seconds",
|
||||
Help: "Time from the start of a check to its result reaching the API.",
|
||||
Buckets: []float64{0.5, 1, 2.5, 5, 10, 30, 60, 120, 300},
|
||||
}),
|
||||
notifications: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace, Name: "notifications_total",
|
||||
Help: "Notification delivery attempts by channel type and result.",
|
||||
}, []string{"channel_type", "result"}),
|
||||
notifyDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace, Name: "notification_send_duration_seconds",
|
||||
Help: "Time to deliver a notification, by channel type.",
|
||||
Buckets: []float64{0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30},
|
||||
}, []string{"channel_type"}),
|
||||
subscriberMail: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace, Name: "subscriber_notifications_total",
|
||||
Help: "Mails to status page subscribers by result.",
|
||||
}, []string{"result"}),
|
||||
incidents: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace, Name: "incidents_total",
|
||||
Help: "Incidents this instance opened or resolved.",
|
||||
}, []string{"event"}),
|
||||
jobRuns: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace, Name: "job_runs_total",
|
||||
Help: "Runs of background jobs by result, ok or failed.",
|
||||
}, []string{"job", "result"}),
|
||||
jobDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace, Name: "job_duration_seconds",
|
||||
Help: "Duration of background job runs.",
|
||||
Buckets: []float64{0.01, 0.05, 0.1, 0.5, 1, 5, 10, 30, 60, 300},
|
||||
}, []string{"job"}),
|
||||
jobSuccess: prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: namespace, Name: "job_last_success_timestamp_seconds",
|
||||
Help: "Unix time of the last successful run of a background job on this instance.",
|
||||
}, []string{"job"}),
|
||||
}
|
||||
build := prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: namespace, Name: "build_info",
|
||||
Help: "Always 1; the labels name the running release.",
|
||||
}, []string{"version", "commit", "edition"})
|
||||
build.WithLabelValues(buildinfo.Version, buildinfo.Commit, edition).Set(1)
|
||||
reg.MustRegister(
|
||||
collectors.NewGoCollector(),
|
||||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||
build,
|
||||
m.requests, m.duration, m.inFlight,
|
||||
m.dispatched, m.stale, m.results, m.rejected, m.resultDelay,
|
||||
m.notifications, m.notifyDuration, m.subscriberMail,
|
||||
m.incidents,
|
||||
m.jobRuns, m.jobDuration, m.jobSuccess,
|
||||
)
|
||||
return m
|
||||
}
|
||||
|
||||
// Register adds collectors, such as those reading the database when
|
||||
// scraped.
|
||||
func (m *Metrics) Register(cs ...prometheus.Collector) { m.reg.MustRegister(cs...) }
|
||||
|
||||
// Handler serves the metrics in the Prometheus text format.
|
||||
func (m *Metrics) Handler() http.Handler {
|
||||
return promhttp.HandlerFor(m.reg, promhttp.HandlerOpts{Registry: m.reg})
|
||||
}
|
||||
|
||||
// Gatherer exposes the registry to tests.
|
||||
func (m *Metrics) Gatherer() prometheus.Gatherer { return m.reg }
|
||||
|
||||
// HTTP counts and times the requests of r. Routes listed in streaming are
|
||||
// counted but not timed, since they stay open on purpose.
|
||||
func (m *Metrics) HTTP(streaming ...string) gin.HandlerFunc {
|
||||
skip := map[string]bool{}
|
||||
for _, r := range streaming {
|
||||
skip[r] = true
|
||||
}
|
||||
return func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
m.inFlight.Inc()
|
||||
defer m.inFlight.Dec()
|
||||
c.Next()
|
||||
route := c.FullPath()
|
||||
if route == "" {
|
||||
route = "unmatched"
|
||||
}
|
||||
m.requests.WithLabelValues(c.Request.Method, route, strconv.Itoa(c.Writer.Status())).Inc()
|
||||
if !skip[route] {
|
||||
m.duration.WithLabelValues(c.Request.Method, route).Observe(time.Since(start).Seconds())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dispatched counts checks moved to the checkers' queues.
|
||||
func (m *Metrics) Dispatched(n int) { m.dispatched.Add(float64(n)) }
|
||||
|
||||
// Stale counts n queued checks dropped as out of date.
|
||||
func (m *Metrics) Stale(n int) {
|
||||
if n > 0 {
|
||||
m.stale.Add(float64(n))
|
||||
}
|
||||
}
|
||||
|
||||
// Result counts a stored check result and how long it took to arrive.
|
||||
func (m *Metrics) Result(region string, ok bool, delay time.Duration) {
|
||||
m.results.WithLabelValues(region, strconv.FormatBool(ok)).Inc()
|
||||
m.resultDelay.Observe(max(delay, 0).Seconds())
|
||||
}
|
||||
|
||||
// Rejected counts n check results not stored for reason.
|
||||
func (m *Metrics) Rejected(reason string, n int) {
|
||||
if n > 0 {
|
||||
m.rejected.WithLabelValues(reason).Add(float64(n))
|
||||
}
|
||||
}
|
||||
|
||||
// Notification counts a delivery attempt to a channel of type typ.
|
||||
func (m *Metrics) Notification(typ string, err error, took time.Duration) {
|
||||
m.notifications.WithLabelValues(typ, result(err)).Inc()
|
||||
m.notifyDuration.WithLabelValues(typ).Observe(took.Seconds())
|
||||
}
|
||||
|
||||
// SubscriberMail counts a mail to a status page subscriber.
|
||||
func (m *Metrics) SubscriberMail(err error) { m.subscriberMail.WithLabelValues(result(err)).Inc() }
|
||||
|
||||
// Incident counts an incident event, "opened" or "resolved".
|
||||
func (m *Metrics) Incident(event string) { m.incidents.WithLabelValues(event).Inc() }
|
||||
|
||||
// Job runs one round of the background job name and records its outcome.
|
||||
// It returns run's error.
|
||||
func (m *Metrics) Job(name string, run func() error) error {
|
||||
start := time.Now()
|
||||
err := run()
|
||||
outcome := "ok"
|
||||
if err != nil {
|
||||
outcome = "failed"
|
||||
}
|
||||
m.jobRuns.WithLabelValues(name, outcome).Inc()
|
||||
m.jobDuration.WithLabelValues(name).Observe(time.Since(start).Seconds())
|
||||
if err == nil {
|
||||
m.jobSuccess.WithLabelValues(name).SetToCurrentTime()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func result(err error) string {
|
||||
if err != nil {
|
||||
return "failed"
|
||||
}
|
||||
return "sent"
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func TestHTTPCountsRoutesAndTimesShortRequests(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
m := New("selfhosted")
|
||||
r := gin.New()
|
||||
r.Use(m.HTTP("/stream"))
|
||||
r.GET("/items/:id", func(c *gin.Context) { c.Status(http.StatusTeapot) })
|
||||
r.GET("/stream", func(c *gin.Context) { c.Status(http.StatusOK) })
|
||||
for _, path := range []string{"/items/1", "/items/2", "/stream", "/nowhere"} {
|
||||
r.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest(http.MethodGet, path, nil))
|
||||
}
|
||||
|
||||
if got := testutil.ToFloat64(m.requests.WithLabelValues("GET", "/items/:id", "418")); got != 2 {
|
||||
t.Errorf("requests for the route = %v, want 2", got)
|
||||
}
|
||||
if got := testutil.ToFloat64(m.requests.WithLabelValues("GET", "unmatched", "404")); got != 1 {
|
||||
t.Errorf("unmatched requests = %v, want 1", got)
|
||||
}
|
||||
// The stream is counted, not timed.
|
||||
if got := testutil.CollectAndCount(m.duration); got != 2 {
|
||||
t.Errorf("timed series = %d, want 2: the route and unmatched paths, not the stream", got)
|
||||
}
|
||||
if got := testutil.ToFloat64(m.inFlight); got != 0 {
|
||||
t.Errorf("in flight after the requests = %v, want 0", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJobRecordsOutcome(t *testing.T) {
|
||||
m := New("cloud")
|
||||
boom := errors.New("boom")
|
||||
if err := m.Job("housekeeping", func() error { return nil }); err != nil {
|
||||
t.Fatalf("Job() = %v, want nil", err)
|
||||
}
|
||||
if err := m.Job("housekeeping", func() error { return boom }); !errors.Is(err, boom) {
|
||||
t.Fatalf("Job() = %v, want the run's error", err)
|
||||
}
|
||||
if got := testutil.ToFloat64(m.jobRuns.WithLabelValues("housekeeping", "ok")); got != 1 {
|
||||
t.Errorf("ok runs = %v, want 1", got)
|
||||
}
|
||||
if got := testutil.ToFloat64(m.jobRuns.WithLabelValues("housekeeping", "failed")); got != 1 {
|
||||
t.Errorf("failed runs = %v, want 1", got)
|
||||
}
|
||||
if got := testutil.ToFloat64(m.jobSuccess.WithLabelValues("housekeeping")); got < float64(time.Now().Add(-time.Minute).Unix()) {
|
||||
t.Errorf("last success = %v, want about now", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCountersAndHandler(t *testing.T) {
|
||||
m := New("cloud")
|
||||
m.Dispatched(3)
|
||||
m.Stale(2)
|
||||
m.Stale(0)
|
||||
m.Result("fsn", true, 2*time.Second)
|
||||
m.Result("fsn", false, -time.Second)
|
||||
m.Rejected("duplicate", 2)
|
||||
m.Rejected("bad_time", 0)
|
||||
m.Notification("slack", nil, time.Second)
|
||||
m.Notification("slack", errors.New("x"), time.Second)
|
||||
m.SubscriberMail(nil)
|
||||
m.Incident("opened")
|
||||
|
||||
for name, c := range map[string]struct {
|
||||
got, want float64
|
||||
}{
|
||||
"dispatched": {testutil.ToFloat64(m.dispatched), 3},
|
||||
"stale": {testutil.ToFloat64(m.stale), 2},
|
||||
"ok results": {testutil.ToFloat64(m.results.WithLabelValues("fsn", "true")), 1},
|
||||
"failed results": {testutil.ToFloat64(m.results.WithLabelValues("fsn", "false")), 1},
|
||||
"duplicates": {testutil.ToFloat64(m.rejected.WithLabelValues("duplicate")), 2},
|
||||
"sent": {testutil.ToFloat64(m.notifications.WithLabelValues("slack", "sent")), 1},
|
||||
"failed": {testutil.ToFloat64(m.notifications.WithLabelValues("slack", "failed")), 1},
|
||||
"subscriber": {testutil.ToFloat64(m.subscriberMail.WithLabelValues("sent")), 1},
|
||||
"incidents": {testutil.ToFloat64(m.incidents.WithLabelValues("opened")), 1},
|
||||
} {
|
||||
if c.got != c.want {
|
||||
t.Errorf("%s = %v, want %v", name, c.got, c.want)
|
||||
}
|
||||
}
|
||||
if got := testutil.CollectAndCount(m.rejected); got != 1 {
|
||||
t.Errorf("rejection series = %d, want 1: zero rejections add none", got)
|
||||
}
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
m.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/metrics", nil))
|
||||
body, _ := io.ReadAll(rec.Body)
|
||||
for _, want := range []string{`uptimesebi_build_info{commit="none",edition="cloud",version="dev"} 1`, "go_goroutines", "uptimesebi_checks_dispatched_total 3"} {
|
||||
if !strings.Contains(string(body), want) {
|
||||
t.Errorf("metrics lack %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPoolCollectors(t *testing.T) {
|
||||
// Neither pool connects before it is used.
|
||||
pool, err := pgxpool.New(context.Background(), "postgres://u@127.0.0.1:1/db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pool.Close()
|
||||
rdb := redis.NewClient(&redis.Options{Addr: "127.0.0.1:1"})
|
||||
defer func() { _ = rdb.Close() }()
|
||||
|
||||
m := New("cloud")
|
||||
m.Register(DBPool(pool), RedisPool(rdb))
|
||||
for _, c := range []prometheus.Collector{DBPool(pool), RedisPool(rdb)} {
|
||||
if problems, err := testutil.CollectAndLint(c); err != nil || len(problems) > 0 {
|
||||
t.Errorf("pool metrics lint: %v %v", problems, err)
|
||||
}
|
||||
}
|
||||
if got := testutil.CollectAndCount(DBPool(pool)); got != 7 {
|
||||
t.Errorf("DB pool series = %d, want 7", got)
|
||||
}
|
||||
if got := testutil.CollectAndCount(RedisPool(rdb)); got != 6 {
|
||||
t.Errorf("Redis pool series = %d, want 6", got)
|
||||
}
|
||||
if _, err := m.Gatherer().Gather(); err != nil {
|
||||
t.Errorf("Gather() = %v", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// DBPool reports the state of a Postgres connection pool when scraped.
|
||||
func DBPool(pool *pgxpool.Pool) prometheus.Collector { return dbPool{pool} }
|
||||
|
||||
type dbPool struct{ pool *pgxpool.Pool }
|
||||
|
||||
var (
|
||||
dbConns = prometheus.NewDesc(namespace+"_db_pool_connections",
|
||||
"Connections of the Postgres pool by state.", []string{"state"}, nil)
|
||||
dbMax = prometheus.NewDesc(namespace+"_db_pool_max_connections",
|
||||
"Size limit of the Postgres pool.", nil, nil)
|
||||
dbAcquires = prometheus.NewDesc(namespace+"_db_pool_acquires_total",
|
||||
"Connections taken from the Postgres pool.", nil, nil)
|
||||
dbEmptyAcquires = prometheus.NewDesc(namespace+"_db_pool_empty_acquires_total",
|
||||
"Acquires that had to wait for or open a connection because none was idle.", nil, nil)
|
||||
dbAcquireWait = prometheus.NewDesc(namespace+"_db_pool_acquire_seconds_total",
|
||||
"Total time spent acquiring Postgres connections.", nil, nil)
|
||||
)
|
||||
|
||||
// Describe implements prometheus.Collector.
|
||||
func (dbPool) Describe(ch chan<- *prometheus.Desc) {
|
||||
for _, d := range []*prometheus.Desc{dbConns, dbMax, dbAcquires, dbEmptyAcquires, dbAcquireWait} {
|
||||
ch <- d
|
||||
}
|
||||
}
|
||||
|
||||
// Collect implements prometheus.Collector.
|
||||
func (p dbPool) Collect(ch chan<- prometheus.Metric) {
|
||||
s := p.pool.Stat()
|
||||
ch <- prometheus.MustNewConstMetric(dbConns, prometheus.GaugeValue, float64(s.AcquiredConns()), "acquired")
|
||||
ch <- prometheus.MustNewConstMetric(dbConns, prometheus.GaugeValue, float64(s.IdleConns()), "idle")
|
||||
ch <- prometheus.MustNewConstMetric(dbConns, prometheus.GaugeValue, float64(s.ConstructingConns()), "constructing")
|
||||
ch <- prometheus.MustNewConstMetric(dbMax, prometheus.GaugeValue, float64(s.MaxConns()))
|
||||
ch <- prometheus.MustNewConstMetric(dbAcquires, prometheus.CounterValue, float64(s.AcquireCount()))
|
||||
ch <- prometheus.MustNewConstMetric(dbEmptyAcquires, prometheus.CounterValue, float64(s.EmptyAcquireCount()))
|
||||
ch <- prometheus.MustNewConstMetric(dbAcquireWait, prometheus.CounterValue, s.AcquireDuration().Seconds())
|
||||
}
|
||||
|
||||
// RedisPool reports the state of a Redis client's connection pool when
|
||||
// scraped.
|
||||
func RedisPool(rdb redis.UniversalClient) prometheus.Collector { return redisPool{rdb} }
|
||||
|
||||
type redisPool struct{ rdb redis.UniversalClient }
|
||||
|
||||
var (
|
||||
redisConns = prometheus.NewDesc(namespace+"_redis_pool_connections",
|
||||
"Connections of the Redis pool by state.", []string{"state"}, nil)
|
||||
redisHits = prometheus.NewDesc(namespace+"_redis_pool_hits_total",
|
||||
"Times an idle Redis connection was reused.", nil, nil)
|
||||
redisMisses = prometheus.NewDesc(namespace+"_redis_pool_misses_total",
|
||||
"Times no idle Redis connection was available.", nil, nil)
|
||||
redisTimeouts = prometheus.NewDesc(namespace+"_redis_pool_timeouts_total",
|
||||
"Times waiting for a Redis connection timed out.", nil, nil)
|
||||
redisStale = prometheus.NewDesc(namespace+"_redis_pool_stale_total",
|
||||
"Stale Redis connections the pool closed.", nil, nil)
|
||||
)
|
||||
|
||||
// Describe implements prometheus.Collector.
|
||||
func (redisPool) Describe(ch chan<- *prometheus.Desc) {
|
||||
for _, d := range []*prometheus.Desc{redisConns, redisHits, redisMisses, redisTimeouts, redisStale} {
|
||||
ch <- d
|
||||
}
|
||||
}
|
||||
|
||||
// Collect implements prometheus.Collector.
|
||||
func (p redisPool) Collect(ch chan<- prometheus.Metric) {
|
||||
s := p.rdb.PoolStats()
|
||||
ch <- prometheus.MustNewConstMetric(redisConns, prometheus.GaugeValue, float64(s.TotalConns), "total")
|
||||
ch <- prometheus.MustNewConstMetric(redisConns, prometheus.GaugeValue, float64(s.IdleConns), "idle")
|
||||
ch <- prometheus.MustNewConstMetric(redisHits, prometheus.CounterValue, float64(s.Hits))
|
||||
ch <- prometheus.MustNewConstMetric(redisMisses, prometheus.CounterValue, float64(s.Misses))
|
||||
ch <- prometheus.MustNewConstMetric(redisTimeouts, prometheus.CounterValue, float64(s.Timeouts))
|
||||
ch <- prometheus.MustNewConstMetric(redisStale, prometheus.CounterValue, float64(s.StaleConns))
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
// Package ogimage draws the preview images link previews show for status
|
||||
// pages and the app (Open Graph and Twitter cards): 1200×630 PNGs in the
|
||||
// style of the console.
|
||||
package ogimage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"math"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/gofont/gobold"
|
||||
"golang.org/x/image/font/gofont/goregular"
|
||||
"golang.org/x/image/font/opentype"
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
|
||||
// Width and Height are the size link previews expect.
|
||||
const (
|
||||
Width = 1200
|
||||
Height = 630
|
||||
)
|
||||
|
||||
// Colors of the console's palette.
|
||||
var (
|
||||
Paper = color.RGBA{0xf4, 0xf2, 0xee, 0xff}
|
||||
Ink = color.RGBA{0x1c, 0x1d, 0x1f, 0xff}
|
||||
Muted = color.RGBA{0x6b, 0x67, 0x5f, 0xff}
|
||||
Rule = color.RGBA{0xd9, 0xd5, 0xcc, 0xff}
|
||||
Up = color.RGBA{0x2f, 0x7d, 0x4f, 0xff}
|
||||
Down = color.RGBA{0xb3, 0x36, 0x1f, 0xff}
|
||||
Degraded = color.RGBA{0xb5, 0x7b, 0x14, 0xff}
|
||||
Unknown = color.RGBA{0x8a, 0x8a, 0x86, 0xff}
|
||||
Maintenance = color.RGBA{0x3d, 0x6f, 0xa6, 0xff}
|
||||
)
|
||||
|
||||
// Card is what an image shows: a title, a line below it marked with a dot
|
||||
// in Accent, and a footer such as the page's address.
|
||||
type Card struct {
|
||||
Title string
|
||||
Subtitle string
|
||||
Footer string
|
||||
Accent color.Color
|
||||
}
|
||||
|
||||
var (
|
||||
fontsOnce sync.Once
|
||||
regular *opentype.Font
|
||||
bold *opentype.Font
|
||||
fontsErr error
|
||||
)
|
||||
|
||||
func loadFonts() error {
|
||||
fontsOnce.Do(func() {
|
||||
if regular, fontsErr = opentype.Parse(goregular.TTF); fontsErr != nil {
|
||||
return
|
||||
}
|
||||
bold, fontsErr = opentype.Parse(gobold.TTF)
|
||||
})
|
||||
return fontsErr
|
||||
}
|
||||
|
||||
func face(f *opentype.Font, size float64) (font.Face, error) {
|
||||
return opentype.NewFace(f, &opentype.FaceOptions{Size: size, DPI: 72, Hinting: font.HintingFull})
|
||||
}
|
||||
|
||||
const margin = 80
|
||||
|
||||
// Render draws c as a PNG.
|
||||
func Render(c Card) ([]byte, error) {
|
||||
if err := loadFonts(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
accent := c.Accent
|
||||
if accent == nil {
|
||||
accent = Ink
|
||||
}
|
||||
img := image.NewRGBA(image.Rect(0, 0, Width, Height))
|
||||
draw.Draw(img, img.Bounds(), image.NewUniform(Paper), image.Point{}, draw.Src)
|
||||
// A band in the accent colour along the top, and a rule above the footer.
|
||||
fill(img, image.Rect(0, 0, Width, 14), accent)
|
||||
fill(img, image.Rect(margin, Height-130, Width-margin, Height-128), Rule)
|
||||
|
||||
brand, err := face(bold, 30)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
drawText(img, brand, Ink, margin, 104, "UptimeSebi")
|
||||
|
||||
// The title shrinks for long names and wraps onto at most two lines.
|
||||
y := 230
|
||||
for _, size := range []float64{76, 64, 54} {
|
||||
title, err := face(bold, size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lines := wrap(title, c.Title, Width-2*margin, 2)
|
||||
if len(lines) == 1 || size == 54 {
|
||||
lh := int(size * 1.15)
|
||||
for _, l := range lines {
|
||||
drawText(img, title, Ink, margin, y, l)
|
||||
y += lh
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if c.Subtitle != "" {
|
||||
sub, err := face(regular, 38)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
y += 30
|
||||
dot(img, margin+14, y-13, 14, accent)
|
||||
lines := wrap(sub, c.Subtitle, Width-2*margin-48, 1)
|
||||
drawText(img, sub, Ink, margin+48, y, lines[0])
|
||||
}
|
||||
|
||||
if c.Footer != "" {
|
||||
foot, err := face(regular, 28)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
drawText(img, foot, Muted, margin, Height-72, wrap(foot, c.Footer, Width-2*margin, 1)[0])
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := png.Encode(&buf, img); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func fill(img *image.RGBA, r image.Rectangle, c color.Color) {
|
||||
draw.Draw(img, r, image.NewUniform(c), image.Point{}, draw.Src)
|
||||
}
|
||||
|
||||
// dot draws a filled circle of radius r around (cx, cy), smoothing its edge.
|
||||
func dot(img *image.RGBA, cx, cy, r int, c color.Color) {
|
||||
cr, cg, cb, _ := c.RGBA()
|
||||
for y := cy - r - 1; y <= cy+r+1; y++ {
|
||||
for x := cx - r - 1; x <= cx+r+1; x++ {
|
||||
// Coverage from the distance of the pixel centre to the edge.
|
||||
dx, dy := float64(x-cx)+0.5, float64(y-cy)+0.5
|
||||
d := float64(r) - math.Sqrt(dx*dx+dy*dy) + 0.5
|
||||
if d <= 0 {
|
||||
continue
|
||||
}
|
||||
if d > 1 {
|
||||
d = 1
|
||||
}
|
||||
bg := img.RGBAAt(x, y)
|
||||
mix := func(fg uint32, b uint8) uint8 { return uint8(float64(fg>>8)*d + float64(b)*(1-d)) }
|
||||
img.SetRGBA(x, y, color.RGBA{mix(cr, bg.R), mix(cg, bg.G), mix(cb, bg.B), 0xff})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func drawText(img *image.RGBA, f font.Face, c color.Color, x, y int, s string) {
|
||||
d := font.Drawer{Dst: img, Src: image.NewUniform(c), Face: f, Dot: fixed.P(x, y)}
|
||||
d.DrawString(s)
|
||||
}
|
||||
|
||||
// wrap breaks s into lines no wider than width, at most max of them; the
|
||||
// last one ends in an ellipsis when s does not fit.
|
||||
func wrap(f font.Face, s string, width, max int) []string {
|
||||
words := strings.Fields(s)
|
||||
if len(words) == 0 {
|
||||
return []string{""}
|
||||
}
|
||||
limit := fixed.I(width)
|
||||
var lines []string
|
||||
line := ""
|
||||
for i, w := range words {
|
||||
next := strings.TrimSpace(line + " " + w)
|
||||
if font.MeasureString(f, next) <= limit {
|
||||
line = next
|
||||
continue
|
||||
}
|
||||
if line != "" {
|
||||
lines = append(lines, line)
|
||||
}
|
||||
line = w
|
||||
if len(lines) == max {
|
||||
// Out of lines: finish the last one with what is left.
|
||||
rest := strings.Join(words[i:], " ")
|
||||
lines[max-1] = ellipsize(f, lines[max-1]+" "+rest, limit)
|
||||
return lines
|
||||
}
|
||||
}
|
||||
return append(lines, ellipsize(f, line, limit))
|
||||
}
|
||||
|
||||
// ellipsize shortens s until it fits limit, marking the cut with "…".
|
||||
func ellipsize(f font.Face, s string, limit fixed.Int26_6) string {
|
||||
if font.MeasureString(f, s) <= limit {
|
||||
return s
|
||||
}
|
||||
r := []rune(s)
|
||||
for len(r) > 0 && font.MeasureString(f, string(r)+"…") > limit {
|
||||
r = r[:len(r)-1]
|
||||
}
|
||||
return strings.TrimSpace(string(r)) + "…"
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package ogimage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image/png"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRender(t *testing.T) {
|
||||
for _, c := range []Card{
|
||||
{Title: "Hetzner Cloud", Subtitle: "All systems operational", Footer: "uptimesebi-status.net/hetzner", Accent: Up},
|
||||
{Title: strings.Repeat("A very long status page name ", 6), Subtitle: strings.Repeat("problems ", 20), Footer: "x", Accent: Down},
|
||||
{Title: ""},
|
||||
} {
|
||||
b, err := Render(c)
|
||||
if err != nil {
|
||||
t.Fatalf("Render(%q) error = %v", c.Title, err)
|
||||
}
|
||||
img, err := png.Decode(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
t.Fatalf("Render(%q) is no PNG: %v", c.Title, err)
|
||||
}
|
||||
if r := img.Bounds(); r.Dx() != Width || r.Dy() != Height {
|
||||
t.Errorf("Render(%q) size = %v, want %dx%d", c.Title, r, Width, Height)
|
||||
}
|
||||
if dir := os.Getenv("OGIMAGE_OUT"); dir != "" {
|
||||
_ = os.WriteFile(dir+"/"+string(rune('a'+len(c.Title)%26))+".png", b, 0o600)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWrap(t *testing.T) {
|
||||
if err := loadFonts(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f, err := face(bold, 76)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lines := wrap(f, strings.Repeat("word ", 100), 1040, 2)
|
||||
if len(lines) != 2 || !strings.HasSuffix(lines[1], "…") {
|
||||
t.Errorf("wrap() = %q, want two lines ending in an ellipsis", lines)
|
||||
}
|
||||
if got := wrap(f, "Short", 1040, 2); len(got) != 1 || got[0] != "Short" {
|
||||
t.Errorf("wrap(Short) = %q", got)
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,10 @@ func Compress() gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// AcceptsGzip reports whether an Accept-Encoding header allows gzip, for
|
||||
// handlers that send content compressed ahead of time.
|
||||
func AcceptsGzip(header string) bool { return acceptsGzip(header) }
|
||||
|
||||
// acceptsGzip reports whether an Accept-Encoding header allows gzip.
|
||||
func acceptsGzip(header string) bool {
|
||||
for _, part := range strings.Split(header, ",") {
|
||||
|
||||
+198
-46
@@ -7,12 +7,18 @@
|
||||
// number of API replicas can dispatch concurrently without a leader, and a
|
||||
// lost job never stops a monitor from running again.
|
||||
//
|
||||
// Each monitor has a fixed phase within its interval, derived from its ID.
|
||||
// After its first run, which is right away, a monitor runs on its phase, so
|
||||
// runs spread evenly over the interval however the monitors were created,
|
||||
// and late runs do not all gather at the moment they were dispatched.
|
||||
//
|
||||
// Instances announce themselves by polling. One that stops polling is
|
||||
// considered gone after StaleAfter; its queued jobs return to the region.
|
||||
package schedule
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
@@ -33,6 +39,8 @@ const (
|
||||
const (
|
||||
keyRegions = "sched:regions"
|
||||
keyIntervals = "sched:intervals"
|
||||
// keyPhases holds each monitor's phase within its interval, in ms.
|
||||
keyPhases = "sched:phases"
|
||||
// keyTouched records when each monitor was last upserted, so a
|
||||
// reconciliation based on an older database read leaves it alone.
|
||||
keyTouched = "sched:touched"
|
||||
@@ -60,6 +68,9 @@ func New(rdb redis.UniversalClient) *Scheduler {
|
||||
type Entry struct {
|
||||
MonitorID uuid.UUID
|
||||
ScheduledAt time.Time
|
||||
// DispatchedAt is when the run was queued; zero for runs queued before
|
||||
// dispatch times were recorded.
|
||||
DispatchedAt time.Time
|
||||
}
|
||||
|
||||
// Monitor is the schedule-relevant part of a monitor.
|
||||
@@ -69,20 +80,55 @@ type Monitor struct {
|
||||
Regions []string
|
||||
}
|
||||
|
||||
// phaseOf returns the phase of monitor id within interval, in ms. The ID's
|
||||
// random bits spread the phases of all monitors evenly.
|
||||
func phaseOf(id uuid.UUID, interval time.Duration) int64 {
|
||||
ms := interval.Milliseconds()
|
||||
if ms <= 0 {
|
||||
return 0
|
||||
}
|
||||
return int64(binary.BigEndian.Uint64(id[8:]) % uint64(ms))
|
||||
}
|
||||
|
||||
// nextSlot returns the first time after now, in ms, at which a monitor with
|
||||
// phase and interval, both in ms, runs. dispatchScript computes the same.
|
||||
func nextSlot(now, phase, interval int64) int64 {
|
||||
if interval <= 0 {
|
||||
return now
|
||||
}
|
||||
off := (now - phase) % interval
|
||||
if off < 0 {
|
||||
off += interval
|
||||
}
|
||||
return now - off + interval
|
||||
}
|
||||
|
||||
// Upsert schedules m in its regions and removes it from others it was in.
|
||||
// A monitor new to a region runs right away; an existing schedule keeps its
|
||||
// phase so edits do not cause bursts.
|
||||
// time so edits do not cause bursts.
|
||||
func (s *Scheduler) Upsert(ctx context.Context, m Monitor, previousRegions []string) error {
|
||||
return s.upsert(ctx, m, previousRegions, true)
|
||||
}
|
||||
|
||||
// upsert is Upsert; without runNow, a monitor new to a region first runs on
|
||||
// its phase instead of right away.
|
||||
func (s *Scheduler) upsert(ctx context.Context, m Monitor, previousRegions []string, runNow bool) error {
|
||||
now := s.now().UnixMilli()
|
||||
id := m.ID.String()
|
||||
phase := phaseOf(m.ID, m.Interval)
|
||||
first := now
|
||||
if !runNow {
|
||||
first = nextSlot(now, phase, m.Interval.Milliseconds())
|
||||
}
|
||||
_, err := s.rdb.TxPipelined(ctx, func(p redis.Pipeliner) error {
|
||||
p.HSet(ctx, keyIntervals, id, int64(m.Interval/time.Millisecond))
|
||||
p.HSet(ctx, keyIntervals, id, m.Interval.Milliseconds())
|
||||
p.HSet(ctx, keyPhases, id, phase)
|
||||
p.HSet(ctx, keyTouched, id, now)
|
||||
keep := map[string]bool{}
|
||||
for _, r := range m.Regions {
|
||||
keep[r] = true
|
||||
p.SAdd(ctx, keyRegions, r)
|
||||
p.ZAddNX(ctx, keyDue(r), redis.Z{Score: float64(now), Member: id})
|
||||
p.ZAddNX(ctx, keyDue(r), redis.Z{Score: float64(first), Member: id})
|
||||
}
|
||||
for _, r := range previousRegions {
|
||||
if !keep[r] {
|
||||
@@ -99,6 +145,7 @@ func (s *Scheduler) Upsert(ctx context.Context, m Monitor, previousRegions []str
|
||||
func (s *Scheduler) Remove(ctx context.Context, id uuid.UUID, regions []string) error {
|
||||
_, err := s.rdb.TxPipelined(ctx, func(p redis.Pipeliner) error {
|
||||
p.HDel(ctx, keyIntervals, id.String())
|
||||
p.HDel(ctx, keyPhases, id.String())
|
||||
p.HDel(ctx, keyTouched, id.String())
|
||||
for _, r := range regions {
|
||||
p.ZRem(ctx, keyDue(r), id.String())
|
||||
@@ -112,11 +159,12 @@ func (s *Scheduler) Remove(ctx context.Context, id uuid.UUID, regions []string)
|
||||
// from the database at asOf. It repairs drift after a Redis failover or a
|
||||
// missed update and is safe to run from several replicas. Monitors upserted
|
||||
// after asOf are kept even if want lacks them: they were created while the
|
||||
// database was being read.
|
||||
// database was being read. Monitors it adds back first run on their phase,
|
||||
// so recovering a lost schedule causes no burst.
|
||||
func (s *Scheduler) Reconcile(ctx context.Context, want []Monitor, asOf time.Time) error {
|
||||
byRegion := map[string]map[string]bool{}
|
||||
for _, m := range want {
|
||||
if err := s.Upsert(ctx, m, nil); err != nil {
|
||||
if err := s.upsert(ctx, m, nil, false); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, r := range m.Regions {
|
||||
@@ -139,7 +187,7 @@ func (s *Scheduler) Reconcile(ctx context.Context, want []Monitor, asOf time.Tim
|
||||
if wanted[id] {
|
||||
continue
|
||||
}
|
||||
if err := pruneScript.Run(ctx, s.rdb, []string{keyIntervals, keyTouched}, id, asOfMS).Err(); err != nil {
|
||||
if err := pruneScript.Run(ctx, s.rdb, []string{keyIntervals, keyTouched, keyPhases}, id, asOfMS).Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -156,7 +204,7 @@ func (s *Scheduler) Reconcile(ctx context.Context, want []Monitor, asOf time.Tim
|
||||
if byRegion[r][id] {
|
||||
continue
|
||||
}
|
||||
if err := pruneScript.Run(ctx, s.rdb, []string{keyDue(r), keyTouched}, id, asOfMS).Err(); err != nil {
|
||||
if err := pruneScript.Run(ctx, s.rdb, []string{keyDue(r), keyTouched, keyPhases}, id, asOfMS).Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -168,7 +216,8 @@ func (s *Scheduler) Reconcile(ctx context.Context, want []Monitor, asOf time.Tim
|
||||
// upserted at or after asOf. Checking and removing in one step closes the
|
||||
// window in which a concurrent upsert would be undone.
|
||||
//
|
||||
// KEYS: hash or sorted set to prune, touched hash. ARGV: monitor id, asOf ms.
|
||||
// KEYS: hash or sorted set to prune, touched hash, phase hash.
|
||||
// ARGV: monitor id, asOf ms.
|
||||
var pruneScript = redis.NewScript(`
|
||||
local touched = tonumber(redis.call('HGET', KEYS[2], ARGV[1]) or '0')
|
||||
if touched >= tonumber(ARGV[2]) then return 0 end
|
||||
@@ -177,6 +226,7 @@ if redis.call('TYPE', KEYS[1]).ok == 'zset' then
|
||||
else
|
||||
redis.call('HDEL', KEYS[1], ARGV[1])
|
||||
redis.call('HDEL', KEYS[2], ARGV[1])
|
||||
redis.call('HDEL', KEYS[3], ARGV[1])
|
||||
end
|
||||
return 1
|
||||
`)
|
||||
@@ -188,8 +238,14 @@ func (s *Scheduler) Heartbeat(ctx context.Context, region string, instance uuid.
|
||||
|
||||
// dispatchScript runs per region.
|
||||
//
|
||||
// KEYS: due set, instance set, interval hash.
|
||||
// KEYS: due set, instance set, interval hash, phase hash.
|
||||
// ARGV: now ms, stale-before ms, batch limit, job queue prefix, queue TTL s.
|
||||
//
|
||||
// The next run is the monitor's first phase slot after now. A run off its
|
||||
// slot, like the first one, skips a slot less than half an interval away,
|
||||
// so the monitor does not run twice in quick succession. Monitors without
|
||||
// a phase, scheduled before phases existed, run every interval from their
|
||||
// last due time until reconciliation adds one.
|
||||
var dispatchScript = redis.NewScript(`
|
||||
local now = tonumber(ARGV[1])
|
||||
for _, inst in ipairs(redis.call('ZRANGEBYSCORE', KEYS[2], '-inf', ARGV[2])) do
|
||||
@@ -214,10 +270,19 @@ for i = 1, #due, 2 do
|
||||
redis.call('ZREM', KEYS[1], m)
|
||||
else
|
||||
local q = ARGV[4] .. live[math.random(#live)]
|
||||
redis.call('RPUSH', q, m .. '|' .. string.format('%.0f', at))
|
||||
redis.call('RPUSH', q, m .. '|' .. string.format('%.0f', at) .. '|' .. string.format('%.0f', now))
|
||||
redis.call('EXPIRE', q, ARGV[5])
|
||||
local nxt = at + interval
|
||||
if nxt <= now then nxt = now + interval end
|
||||
local nxt
|
||||
local phase = tonumber(redis.call('HGET', KEYS[4], m) or '')
|
||||
if phase == nil then
|
||||
nxt = at + interval
|
||||
if nxt <= now then nxt = now + interval end
|
||||
else
|
||||
nxt = now - ((now - phase) % interval) + interval
|
||||
if (at - phase) % interval ~= 0 and nxt - now < interval / 2 then
|
||||
nxt = nxt + interval
|
||||
end
|
||||
end
|
||||
redis.call('ZADD', KEYS[1], nxt, m)
|
||||
n = n + 1
|
||||
end
|
||||
@@ -236,7 +301,7 @@ func (s *Scheduler) Dispatch(ctx context.Context) (int, error) {
|
||||
total := 0
|
||||
for _, r := range regions {
|
||||
n, err := dispatchScript.Run(ctx, s.rdb,
|
||||
[]string{keyDue(r), keyInstances(r), keyIntervals},
|
||||
[]string{keyDue(r), keyInstances(r), keyIntervals, keyPhases},
|
||||
now.UnixMilli(), now.Add(-StaleAfter).UnixMilli(), 1000, jobsPrefix, int(jobsTTL.Seconds()),
|
||||
).Int()
|
||||
if err != nil {
|
||||
@@ -262,48 +327,100 @@ func (s *Scheduler) LastSeen(ctx context.Context, region string, instance uuid.U
|
||||
return time.UnixMilli(int64(score)), err
|
||||
}
|
||||
|
||||
// staleAfter is how many intervals a queued run may wait before Take drops
|
||||
// it. By then a newer run of the monitor has been dispatched, since the next
|
||||
// run is due at most one and a half intervals after the last dispatch, so
|
||||
// a checker that fell behind catches up instead of working off runs that
|
||||
// are out of date.
|
||||
const staleAfter = 2
|
||||
|
||||
// Take pops up to max queued runs for instance, waiting up to wait for the
|
||||
// first one. It returns within about a second once ctx is done, so long polls
|
||||
// do not hold up shutdown or cancelled requests.
|
||||
func (s *Scheduler) Take(ctx context.Context, instance uuid.UUID, max int, wait time.Duration) ([]Entry, error) {
|
||||
// do not hold up shutdown or cancelled requests. Runs queued for longer than
|
||||
// staleAfter intervals are dropped; Take returns how many.
|
||||
func (s *Scheduler) Take(ctx context.Context, instance uuid.UUID, max int, wait time.Duration) ([]Entry, int, error) {
|
||||
if max <= 0 {
|
||||
return nil, nil
|
||||
return nil, 0, nil
|
||||
}
|
||||
q := jobsPrefix + instance.String()
|
||||
raw, err := s.rdb.LPopCount(ctx, q, max).Result()
|
||||
if err != nil && !errors.Is(err, redis.Nil) {
|
||||
return nil, err
|
||||
}
|
||||
deadline := time.Now().Add(wait)
|
||||
for len(raw) == 0 && ctx.Err() == nil {
|
||||
left := time.Until(deadline)
|
||||
if left <= 0 {
|
||||
return nil, nil
|
||||
stale := 0
|
||||
for ctx.Err() == nil {
|
||||
raw, err := s.rdb.LPopCount(ctx, q, max).Result()
|
||||
if err != nil && !errors.Is(err, redis.Nil) {
|
||||
return nil, stale, err
|
||||
}
|
||||
// BLPOP blocks server side and ignores ctx, so wait in slices.
|
||||
first, err := s.blpop(ctx, min(left, time.Second), q)
|
||||
if errors.Is(err, redis.Nil) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
raw = []string{first[1]}
|
||||
if max > 1 {
|
||||
more, err := s.rdb.LPopCount(ctx, q, max-1).Result()
|
||||
if err != nil && !errors.Is(err, redis.Nil) {
|
||||
return nil, err
|
||||
if len(raw) == 0 {
|
||||
left := time.Until(deadline)
|
||||
if left <= 0 {
|
||||
return nil, stale, nil
|
||||
}
|
||||
raw = append(raw, more...)
|
||||
// BLPOP blocks server side and ignores ctx, so wait in slices.
|
||||
first, err := s.blpop(ctx, min(left, time.Second), q)
|
||||
if errors.Is(err, redis.Nil) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return nil, stale, err
|
||||
}
|
||||
raw = []string{first[1]}
|
||||
if max > 1 {
|
||||
more, err := s.rdb.LPopCount(ctx, q, max-1).Result()
|
||||
if err != nil && !errors.Is(err, redis.Nil) {
|
||||
return nil, stale, err
|
||||
}
|
||||
raw = append(raw, more...)
|
||||
}
|
||||
}
|
||||
out, n, err := s.fresh(ctx, raw)
|
||||
if err != nil {
|
||||
return nil, stale, err
|
||||
}
|
||||
stale += n
|
||||
if len(out) > 0 {
|
||||
return out, stale, nil
|
||||
}
|
||||
}
|
||||
out := make([]Entry, 0, len(raw))
|
||||
return nil, stale, nil
|
||||
}
|
||||
|
||||
// fresh parses popped runs and drops those queued for longer than
|
||||
// staleAfter intervals. It returns the rest and how many it dropped.
|
||||
func (s *Scheduler) fresh(ctx context.Context, raw []string) ([]Entry, int, error) {
|
||||
entries := make([]Entry, 0, len(raw))
|
||||
var ids []string
|
||||
for _, r := range raw {
|
||||
if e, ok := parseEntry(r); ok {
|
||||
out = append(out, e)
|
||||
entries = append(entries, e)
|
||||
if !e.DispatchedAt.IsZero() {
|
||||
ids = append(ids, e.MonitorID.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
if len(ids) == 0 {
|
||||
return entries, 0, nil
|
||||
}
|
||||
vals, err := s.rdb.HMGet(ctx, keyIntervals, ids...).Result()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
interval := make(map[uuid.UUID]time.Duration, len(ids))
|
||||
for i, v := range vals {
|
||||
str, _ := v.(string)
|
||||
if ms, err := strconv.ParseInt(str, 10, 64); err == nil {
|
||||
interval[uuid.MustParse(ids[i])] = time.Duration(ms) * time.Millisecond
|
||||
}
|
||||
}
|
||||
now := s.now()
|
||||
out := entries[:0]
|
||||
for _, e := range entries {
|
||||
// Removed monitors are left to the caller, which drops them.
|
||||
if iv, ok := interval[e.MonitorID]; ok && !e.DispatchedAt.IsZero() && now.Sub(e.DispatchedAt) > staleAfter*iv {
|
||||
continue
|
||||
}
|
||||
out = append(out, e)
|
||||
}
|
||||
return out, len(entries) - len(out), nil
|
||||
}
|
||||
|
||||
// blpop is BLPOP with a timeout below a second, which go-redis would round
|
||||
@@ -332,18 +449,53 @@ func (s *Scheduler) Instances(ctx context.Context, region string) (int64, error)
|
||||
return s.rdb.ZCount(ctx, keyInstances(region), min, "+inf").Result()
|
||||
}
|
||||
|
||||
// overdueScript counts the runs of a region due before a cutoff: those not
|
||||
// dispatched yet and those waiting in an instance's queue.
|
||||
//
|
||||
// KEYS: due set, instance set.
|
||||
// ARGV: cutoff ms, job queue prefix.
|
||||
var overdueScript = redis.NewScript(`
|
||||
local cutoff = tonumber(ARGV[1])
|
||||
local n = redis.call('ZCOUNT', KEYS[1], '-inf', cutoff)
|
||||
for _, inst in ipairs(redis.call('ZRANGE', KEYS[2], 0, -1)) do
|
||||
for _, job in ipairs(redis.call('LRANGE', ARGV[2] .. inst, 0, -1)) do
|
||||
local at = tonumber(string.match(job, '^[^|]*|([^|]*)'))
|
||||
if at ~= nil and at <= cutoff then n = n + 1 end
|
||||
end
|
||||
end
|
||||
return n
|
||||
`)
|
||||
|
||||
// Overdue returns how many runs of region were due more than late ago and
|
||||
// have not started: runs not dispatched, as when the region has no live
|
||||
// instance, and runs left in the queue of an instance too busy to take them.
|
||||
func (s *Scheduler) Overdue(ctx context.Context, region string, late time.Duration) (int64, error) {
|
||||
return overdueScript.Run(ctx, s.rdb, []string{keyDue(region), keyInstances(region)},
|
||||
s.now().Add(-late).UnixMilli(), jobsPrefix).Int64()
|
||||
}
|
||||
|
||||
// parseEntry parses a queued run: "monitor|scheduled ms|dispatched ms",
|
||||
// or without the dispatch time as queued by older releases.
|
||||
func parseEntry(s string) (Entry, bool) {
|
||||
id, at, ok := strings.Cut(s, "|")
|
||||
if !ok {
|
||||
parts := strings.Split(s, "|")
|
||||
if len(parts) < 2 || len(parts) > 3 {
|
||||
return Entry{}, false
|
||||
}
|
||||
mid, err := uuid.Parse(id)
|
||||
mid, err := uuid.Parse(parts[0])
|
||||
if err != nil {
|
||||
return Entry{}, false
|
||||
}
|
||||
ms, err := strconv.ParseFloat(at, 64)
|
||||
ms, err := strconv.ParseFloat(parts[1], 64)
|
||||
if err != nil {
|
||||
return Entry{}, false
|
||||
}
|
||||
return Entry{MonitorID: mid, ScheduledAt: time.UnixMilli(int64(ms))}, true
|
||||
e := Entry{MonitorID: mid, ScheduledAt: time.UnixMilli(int64(ms))}
|
||||
if len(parts) == 3 {
|
||||
d, err := strconv.ParseFloat(parts[2], 64)
|
||||
if err != nil {
|
||||
return Entry{}, false
|
||||
}
|
||||
e.DispatchedAt = time.UnixMilli(int64(d))
|
||||
}
|
||||
return e, true
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func newTest(t *testing.T) (*Scheduler, *time.Time) {
|
||||
|
||||
func takeAll(t *testing.T, s *Scheduler, inst uuid.UUID) []Entry {
|
||||
t.Helper()
|
||||
e, err := s.Take(context.Background(), inst, 1000, 0)
|
||||
e, _, err := s.Take(context.Background(), inst, 1000, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Take() failed: %v", err)
|
||||
}
|
||||
@@ -100,11 +100,20 @@ func TestDispatchReschedulesAndKeepsRegionsApart(t *testing.T) {
|
||||
if n := mustDispatch(t, s); n != 0 {
|
||||
t.Errorf("Dispatch() before next interval = %d, want 0", n)
|
||||
}
|
||||
*now = now.Add(30 * time.Second)
|
||||
// The next run is on the monitor's phase, at least half an interval
|
||||
// after the first one.
|
||||
next := dueAt(t, s, "eu", m.ID)
|
||||
if off := (next.UnixMilli() - phaseOf(m.ID, m.Interval)) % m.Interval.Milliseconds(); off != 0 {
|
||||
t.Errorf("next run %v is %dms off its phase", next, off)
|
||||
}
|
||||
if gap := next.Sub(*now); gap < m.Interval/2 || gap > 3*m.Interval/2 {
|
||||
t.Errorf("next run %v after the first, want between half and one and a half intervals", gap)
|
||||
}
|
||||
*now = next
|
||||
_ = s.Heartbeat(ctx, "eu", eu)
|
||||
_ = s.Heartbeat(ctx, "us", us)
|
||||
if n := mustDispatch(t, s); n != 2 {
|
||||
t.Errorf("Dispatch() after interval = %d, want 2", n)
|
||||
t.Errorf("Dispatch() on the next slot = %d, want 2", n)
|
||||
}
|
||||
|
||||
// Leaving a region stops runs there.
|
||||
@@ -177,6 +186,9 @@ func TestRemoveAndReconcile(t *testing.T) {
|
||||
if len(got) != 1 || got[0].MonitorID != keep.ID {
|
||||
t.Errorf("jobs after Reconcile = %+v, want only %v", got, keep.ID)
|
||||
}
|
||||
if s.rdb.HExists(ctx, keyPhases, gone.ID.String()).Val() {
|
||||
t.Error("Reconcile left the phase of a removed monitor")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTakeWaits(t *testing.T) {
|
||||
@@ -184,7 +196,7 @@ func TestTakeWaits(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
in := uuid.New()
|
||||
start := time.Now()
|
||||
got, err := s.Take(ctx, in, 10, 300*time.Millisecond)
|
||||
got, _, err := s.Take(ctx, in, 10, 300*time.Millisecond)
|
||||
if err != nil || len(got) != 0 {
|
||||
t.Fatalf("Take() on empty queue = %v, %v", got, err)
|
||||
}
|
||||
@@ -202,7 +214,7 @@ func TestTakeGetsAJobDuringAShortWait(t *testing.T) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
s.rdb.RPush(ctx, jobsPrefix+in.String(), monitor.String()+"|1800000000000")
|
||||
}()
|
||||
got, err := s.Take(ctx, in, 10, 600*time.Millisecond)
|
||||
got, _, err := s.Take(ctx, in, 10, 600*time.Millisecond)
|
||||
if err != nil || len(got) != 1 || got[0].MonitorID != monitor {
|
||||
t.Fatalf("Take() = %v, %v; want the job pushed while waiting", got, err)
|
||||
}
|
||||
@@ -213,7 +225,7 @@ func TestTakeReturnsWhenCancelled(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go func() { time.Sleep(100 * time.Millisecond); cancel() }()
|
||||
start := time.Now()
|
||||
_, _ = s.Take(ctx, uuid.New(), 10, 20*time.Second)
|
||||
_, _, _ = s.Take(ctx, uuid.New(), 10, 20*time.Second)
|
||||
if took := time.Since(start); took > 2*time.Second {
|
||||
t.Errorf("Take() returned %v after cancellation, want within about a second", took)
|
||||
}
|
||||
@@ -239,3 +251,261 @@ func TestReconcileKeepsMonitorsCreatedDuringRead(t *testing.T) {
|
||||
t.Errorf("jobs after Reconcile = %+v, want the freshly created monitor", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverdueCountsRunsLeftBehind(t *testing.T) {
|
||||
s, now := newTest(t)
|
||||
ctx := context.Background()
|
||||
for range 2 {
|
||||
_ = s.Upsert(ctx, Monitor{ID: uuid.New(), Interval: time.Minute, Regions: []string{"eu"}}, nil)
|
||||
}
|
||||
overdue := func() int64 {
|
||||
t.Helper()
|
||||
n, err := s.Overdue(ctx, "eu", 10*time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("Overdue() failed: %v", err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
if n := overdue(); n != 0 {
|
||||
t.Errorf("Overdue() right after scheduling = %d, want 0", n)
|
||||
}
|
||||
// No instance takes the runs.
|
||||
*now = now.Add(11 * time.Second)
|
||||
mustDispatch(t, s)
|
||||
if n := overdue(); n != 2 {
|
||||
t.Errorf("Overdue() without instances = %d, want 2", n)
|
||||
}
|
||||
busy := uuid.New()
|
||||
_ = s.Heartbeat(ctx, "eu", busy)
|
||||
mustDispatch(t, s)
|
||||
// The queued runs were due 11 seconds ago and are still waiting.
|
||||
if n := overdue(); n != 2 {
|
||||
t.Errorf("Overdue() with the runs left in a queue = %d, want 2", n)
|
||||
}
|
||||
if _, _, err := s.Take(ctx, busy, 10, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n := overdue(); n != 0 {
|
||||
t.Errorf("Overdue() after the instance took the runs = %d, want 0", n)
|
||||
}
|
||||
}
|
||||
|
||||
func dueAt(t *testing.T, s *Scheduler, region string, id uuid.UUID) time.Time {
|
||||
t.Helper()
|
||||
score, err := s.rdb.ZScore(context.Background(), keyDue(region), id.String()).Result()
|
||||
if err != nil {
|
||||
t.Fatalf("no due time for %v in %s: %v", id, region, err)
|
||||
}
|
||||
return time.UnixMilli(int64(score))
|
||||
}
|
||||
|
||||
// TestPhaseSpreadsBurst creates many monitors at once. Their first runs are
|
||||
// right away; after that they spread over the interval instead of all
|
||||
// running in the same second again.
|
||||
func TestPhaseSpreadsBurst(t *testing.T) {
|
||||
s, now := newTest(t)
|
||||
ctx := context.Background()
|
||||
in := uuid.New()
|
||||
const monitors = 600
|
||||
for range monitors {
|
||||
if err := s.Upsert(ctx, Monitor{ID: uuid.New(), Interval: time.Minute, Regions: []string{"eu"}}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
perSecond := make([]int, 180)
|
||||
for sec := range perSecond {
|
||||
_ = s.Heartbeat(ctx, "eu", in)
|
||||
perSecond[sec] = mustDispatch(t, s)
|
||||
takeAll(t, s, in)
|
||||
*now = now.Add(time.Second)
|
||||
}
|
||||
if perSecond[0] != monitors {
|
||||
t.Errorf("first second dispatched %d, want all %d first runs", perSecond[0], monitors)
|
||||
}
|
||||
total, peak := 0, 0
|
||||
for _, n := range perSecond[60:] {
|
||||
total += n
|
||||
peak = max(peak, n)
|
||||
}
|
||||
if total != 2*monitors {
|
||||
t.Errorf("seconds 60 to 180 dispatched %d runs, want %d: one per monitor and minute", total, 2*monitors)
|
||||
}
|
||||
// 10 per second on average; all 600 at once without phases.
|
||||
if peak > 30 {
|
||||
t.Errorf("busiest second dispatched %d runs, want them spread at about 10 per second", peak)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLateRunSnapsToPhase dispatches runs long overdue. Each comes back on
|
||||
// its own phase instead of all gathering at the dispatch time.
|
||||
func TestLateRunSnapsToPhase(t *testing.T) {
|
||||
s, now := newTest(t)
|
||||
ctx := context.Background()
|
||||
in := uuid.New()
|
||||
ms := []Monitor{}
|
||||
for range 50 {
|
||||
m := Monitor{ID: uuid.New(), Interval: time.Minute, Regions: []string{"eu"}}
|
||||
ms = append(ms, m)
|
||||
_ = s.Upsert(ctx, m, nil)
|
||||
}
|
||||
_ = s.Heartbeat(ctx, "eu", in)
|
||||
mustDispatch(t, s)
|
||||
// No instance for three intervals.
|
||||
*now = now.Add(3*time.Minute + 7*time.Second)
|
||||
_ = s.Heartbeat(ctx, "eu", in)
|
||||
if n := mustDispatch(t, s); n != len(ms) {
|
||||
t.Fatalf("Dispatch() of the overdue runs = %d, want %d", n, len(ms))
|
||||
}
|
||||
distinct := map[time.Time]bool{}
|
||||
for _, m := range ms {
|
||||
got := dueAt(t, s, "eu", m.ID)
|
||||
want := time.UnixMilli(nextSlot(now.UnixMilli(), phaseOf(m.ID, m.Interval), m.Interval.Milliseconds()))
|
||||
if !got.Equal(want) {
|
||||
t.Errorf("monitor next due %v, want its next slot %v", got, want)
|
||||
}
|
||||
distinct[got] = true
|
||||
}
|
||||
if len(distinct) < len(ms)-5 {
|
||||
t.Errorf("%d monitors share %d due times, want them apart", len(ms), len(distinct))
|
||||
}
|
||||
}
|
||||
|
||||
// TestReconcileAddsOnPhase rebuilds a lost schedule without a burst.
|
||||
func TestReconcileAddsOnPhase(t *testing.T) {
|
||||
s, now := newTest(t)
|
||||
ctx := context.Background()
|
||||
in := uuid.New()
|
||||
_ = s.Heartbeat(ctx, "eu", in)
|
||||
ms := []Monitor{}
|
||||
for range 20 {
|
||||
ms = append(ms, Monitor{ID: uuid.New(), Interval: time.Minute, Regions: []string{"eu"}})
|
||||
}
|
||||
if err := s.Reconcile(ctx, ms, *now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, m := range ms {
|
||||
want := time.UnixMilli(nextSlot(now.UnixMilli(), phaseOf(m.ID, m.Interval), m.Interval.Milliseconds()))
|
||||
if got := dueAt(t, s, "eu", m.ID); !got.Equal(want) {
|
||||
t.Errorf("reconciled monitor due %v, want its slot %v", got, want)
|
||||
}
|
||||
}
|
||||
if n := mustDispatch(t, s); n != 0 {
|
||||
t.Errorf("Dispatch() right after Reconcile = %d, want 0", n)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPhaseFallback covers monitors scheduled before phases existed.
|
||||
func TestPhaseFallback(t *testing.T) {
|
||||
s, now := newTest(t)
|
||||
ctx := context.Background()
|
||||
in := uuid.New()
|
||||
_ = s.Heartbeat(ctx, "eu", in)
|
||||
m := Monitor{ID: uuid.New(), Interval: time.Minute, Regions: []string{"eu"}}
|
||||
_ = s.Upsert(ctx, m, nil)
|
||||
s.rdb.HDel(ctx, keyPhases, m.ID.String())
|
||||
mustDispatch(t, s)
|
||||
if got, want := dueAt(t, s, "eu", m.ID), now.Add(time.Minute); !got.Equal(want) {
|
||||
t.Errorf("monitor without phase next due %v, want one interval later, %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNextSlot(t *testing.T) {
|
||||
for _, c := range []struct{ now, phase, interval, want int64 }{
|
||||
{now: 100, phase: 30, interval: 60, want: 150},
|
||||
{now: 150, phase: 30, interval: 60, want: 210},
|
||||
{now: 10, phase: 30, interval: 60, want: 30},
|
||||
{now: 100, phase: 0, interval: 0, want: 100},
|
||||
} {
|
||||
if got := nextSlot(c.now, c.phase, c.interval); got != c.want {
|
||||
t.Errorf("nextSlot(%d, %d, %d) = %d, want %d", c.now, c.phase, c.interval, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestTakeDropsStaleRuns lets a busy instance fall behind: the runs it left
|
||||
// in its queue for more than two intervals are dropped, the newer ones of
|
||||
// the same monitors are handed out.
|
||||
func TestTakeDropsStaleRuns(t *testing.T) {
|
||||
s, now := newTest(t)
|
||||
ctx := context.Background()
|
||||
busy := uuid.New()
|
||||
m := Monitor{ID: uuid.New(), Interval: time.Minute, Regions: []string{"eu"}}
|
||||
_ = s.Upsert(ctx, m, nil)
|
||||
_ = s.Heartbeat(ctx, "eu", busy)
|
||||
mustDispatch(t, s)
|
||||
|
||||
// Within two intervals the run is still handed out.
|
||||
*now = now.Add(2 * time.Minute)
|
||||
if got, stale, err := s.Take(ctx, busy, 10, 0); err != nil || len(got) != 1 || stale != 0 {
|
||||
t.Fatalf("Take() after two intervals = %v, %d stale, %v; want the run", got, stale, err)
|
||||
}
|
||||
|
||||
// Left waiting longer, it is dropped in favour of the newer run.
|
||||
_ = s.Heartbeat(ctx, "eu", busy)
|
||||
mustDispatch(t, s)
|
||||
*now = now.Add(2*time.Minute + time.Second)
|
||||
_ = s.Heartbeat(ctx, "eu", busy)
|
||||
if n := mustDispatch(t, s); n != 1 {
|
||||
t.Fatalf("Dispatch() of the newer run = %d, want 1", n)
|
||||
}
|
||||
got, stale, err := s.Take(ctx, busy, 10, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stale != 1 || len(got) != 1 || !got[0].DispatchedAt.Equal(*now) {
|
||||
t.Errorf("Take() = %+v with %d stale, want only the run dispatched now and 1 stale", got, stale)
|
||||
}
|
||||
}
|
||||
|
||||
// TestTakeSkipsAllStaleRuns does not return empty-handed while fresh runs
|
||||
// wait behind a batch of stale ones.
|
||||
func TestTakeSkipsAllStaleRuns(t *testing.T) {
|
||||
s, now := newTest(t)
|
||||
ctx := context.Background()
|
||||
in := uuid.New()
|
||||
for range 5 {
|
||||
_ = s.Upsert(ctx, Monitor{ID: uuid.New(), Interval: time.Minute, Regions: []string{"eu"}}, nil)
|
||||
}
|
||||
_ = s.Heartbeat(ctx, "eu", in)
|
||||
mustDispatch(t, s)
|
||||
*now = now.Add(3 * time.Minute)
|
||||
fresh := Monitor{ID: uuid.New(), Interval: time.Minute, Regions: []string{"eu"}}
|
||||
_ = s.Upsert(ctx, fresh, nil)
|
||||
_ = s.Heartbeat(ctx, "eu", in)
|
||||
mustDispatch(t, s)
|
||||
// The first pop of 5 holds only stale runs.
|
||||
got, stale, err := s.Take(ctx, in, 5, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stale != 5 {
|
||||
t.Errorf("stale runs = %d, want 5", stale)
|
||||
}
|
||||
// It pops on and hands out the next runs, all dispatched now.
|
||||
if len(got) != 5 {
|
||||
t.Fatalf("Take() = %d runs, want 5", len(got))
|
||||
}
|
||||
for _, e := range got {
|
||||
if !e.DispatchedAt.Equal(*now) {
|
||||
t.Errorf("Take() handed out %+v, want only runs dispatched now", e)
|
||||
}
|
||||
}
|
||||
if rest := takeAll(t, s, in); len(rest) != 1 || rest[0].MonitorID != fresh.ID {
|
||||
t.Errorf("remaining runs = %+v, want the new monitor's", rest)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseEntry(t *testing.T) {
|
||||
id := uuid.New()
|
||||
if e, ok := parseEntry(id.String() + "|1800000000000"); !ok || !e.DispatchedAt.IsZero() || e.ScheduledAt.UnixMilli() != 1_800_000_000_000 {
|
||||
t.Errorf("entry without dispatch time = %+v, %v", e, ok)
|
||||
}
|
||||
if e, ok := parseEntry(id.String() + "|1800000000000|1800000005000"); !ok || e.DispatchedAt.UnixMilli() != 1_800_000_005_000 {
|
||||
t.Errorf("entry with dispatch time = %+v, %v", e, ok)
|
||||
}
|
||||
for _, bad := range []string{"x|1", id.String(), id.String() + "|1|2|3", id.String() + "|1|x"} {
|
||||
if _, ok := parseEntry(bad); ok {
|
||||
t.Errorf("parseEntry(%q) accepted", bad)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package statuspage
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/ogimage"
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
|
||||
)
|
||||
|
||||
// maxDescription bounds a page's description, about what search results
|
||||
// show.
|
||||
const maxDescription = 160
|
||||
|
||||
// origin is the scheme and host the visitor reached the server at.
|
||||
func origin(c *gin.Context) string {
|
||||
scheme := "http"
|
||||
if c.Request.TLS != nil || strings.EqualFold(c.GetHeader("X-Forwarded-Proto"), "https") {
|
||||
scheme = "https"
|
||||
}
|
||||
return scheme + "://" + c.Request.Host
|
||||
}
|
||||
|
||||
var statusAccent = map[string]color.Color{
|
||||
agentapi.PageOperational: ogimage.Up,
|
||||
agentapi.PageDegraded: ogimage.Degraded,
|
||||
agentapi.PageOutage: ogimage.Down,
|
||||
agentapi.PageUnderMaintenance: ogimage.Maintenance,
|
||||
agentapi.PageUnknown: ogimage.Unknown,
|
||||
}
|
||||
|
||||
// pageMeta describes the status page at base for search engines and link
|
||||
// previews, in the language the request was localized to.
|
||||
func (s *Server) pageMeta(c *gin.Context, snap agentapi.PageSnapshot, base string) *web.PageMeta {
|
||||
ctx := c.Request.Context()
|
||||
lang := i18n.Lang(ctx)
|
||||
desc := web.PlainText(snap.Description, maxDescription)
|
||||
if desc == "" {
|
||||
desc = i18n.T(ctx, "page.meta_description", "Title", snap.Title, "Status", i18n.T(ctx, "page.status."+snap.Status))
|
||||
}
|
||||
abs := origin(c) + base
|
||||
image := web.LangURL(abs+"og.png", lang)
|
||||
_, chosen := c.GetQuery("lang")
|
||||
return web.NewPageMeta(snap.Title, desc, abs, image, snap.Title, lang, chosen && s.catalog.IsSupported(c.Query("lang")), s.catalog.Supported())
|
||||
}
|
||||
|
||||
// ogCache keeps each page's preview image until its title, status or
|
||||
// language changes.
|
||||
type ogCache struct {
|
||||
mu sync.Mutex
|
||||
images map[string]ogEntry
|
||||
}
|
||||
|
||||
type ogEntry struct {
|
||||
sig string
|
||||
png []byte
|
||||
}
|
||||
|
||||
// serveOG draws the page's preview image: its name and current status.
|
||||
func (s *Server) serveOG(c *gin.Context, e entry, base string) {
|
||||
s.localizeRequest(c)
|
||||
ctx := c.Request.Context()
|
||||
snap := e.Snap.WithMaintenance(s.now())
|
||||
card := ogimage.Card{
|
||||
Title: snap.Title,
|
||||
Subtitle: i18n.T(ctx, "page.status."+snap.Status),
|
||||
Footer: strings.TrimSuffix(c.Request.Host+base, "/"),
|
||||
Accent: statusAccent[snap.Status],
|
||||
}
|
||||
sig := strings.Join([]string{card.Title, card.Subtitle, card.Footer, snap.Status}, "\x00")
|
||||
key := e.Key + "\x00" + i18n.Lang(ctx)
|
||||
s.og.mu.Lock()
|
||||
cached, ok := s.og.images[key]
|
||||
s.og.mu.Unlock()
|
||||
if !ok || cached.sig != sig {
|
||||
png, err := ogimage.Render(card)
|
||||
if err != nil {
|
||||
s.log.Warn("drawing preview image failed", "page", e.Key, "error", err)
|
||||
c.Status(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
cached = ogEntry{sig: sig, png: png}
|
||||
s.og.mu.Lock()
|
||||
if s.og.images == nil {
|
||||
s.og.images = map[string]ogEntry{}
|
||||
}
|
||||
s.og.images[key] = cached
|
||||
s.og.mu.Unlock()
|
||||
}
|
||||
c.Header("Cache-Control", "public, max-age=300")
|
||||
c.Data(http.StatusOK, "image/png", cached.png)
|
||||
}
|
||||
|
||||
func (s *Server) forgetOG(key string) {
|
||||
s.og.mu.Lock()
|
||||
defer s.og.mu.Unlock()
|
||||
for k := range s.og.images {
|
||||
if strings.HasPrefix(k, key+"\x00") {
|
||||
delete(s.og.images, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) serveSitemap(c *gin.Context, base string) {
|
||||
// No lastmod: a snapshot is regenerated every minute, which says
|
||||
// nothing about whether the page changed.
|
||||
body, err := web.Sitemap([]string{origin(c) + base}, s.catalog.Supported(), time.Time{})
|
||||
if err != nil {
|
||||
c.Status(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
c.Header("Cache-Control", "public, max-age=3600")
|
||||
c.Data(http.StatusOK, "application/xml; charset=utf-8", body)
|
||||
}
|
||||
|
||||
// serveRobots lets crawlers read the pages but not the feeds, the API or
|
||||
// the subscription forms. A custom domain serves one page, so its sitemap
|
||||
// can be named; the shared hosts serve many under their slugs.
|
||||
func (s *Server) serveRobots(c *gin.Context) {
|
||||
var b strings.Builder
|
||||
b.WriteString("User-agent: *\n")
|
||||
prefix := "/*"
|
||||
custom := s.IsCustomDomain(hostOnly(c.Request.Host))
|
||||
if custom {
|
||||
prefix = ""
|
||||
}
|
||||
for _, p := range []string{"/api/", "/subscribe", "/unsubscribe", "/feed.rss"} {
|
||||
b.WriteString("Disallow: " + prefix + p + "\n")
|
||||
}
|
||||
b.WriteString("Allow: /\n")
|
||||
if custom {
|
||||
b.WriteString("\nSitemap: " + origin(c) + "/sitemap.xml\n")
|
||||
}
|
||||
c.Header("Cache-Control", "public, max-age=3600")
|
||||
c.Data(http.StatusOK, "text/plain; charset=utf-8", []byte(b.String()))
|
||||
}
|
||||
@@ -34,6 +34,8 @@ const (
|
||||
routeSubscribe
|
||||
routeConfirm
|
||||
routeUnsubscribe
|
||||
routeOG
|
||||
routeSitemap
|
||||
)
|
||||
|
||||
// posts reports whether the route takes form posts.
|
||||
@@ -63,6 +65,10 @@ func routeOf(parts []string) (route, bool) {
|
||||
return route{kind: routeConfirm}, true
|
||||
case len(parts) == 1 && parts[0] == "unsubscribe":
|
||||
return route{kind: routeUnsubscribe}, true
|
||||
case len(parts) == 1 && parts[0] == "og.png":
|
||||
return route{kind: routeOG}, true
|
||||
case len(parts) == 1 && parts[0] == "sitemap.xml":
|
||||
return route{kind: routeSitemap}, true
|
||||
case len(parts) == 3 && parts[0] == "api" && parts[1] == "v1" && apiResources[parts[2]]:
|
||||
return route{kind: routeAPI, arg: parts[2]}, true
|
||||
case len(parts) == 1 && parts[0] != "" && parts[0] != "api":
|
||||
|
||||
@@ -73,6 +73,8 @@ type Server struct {
|
||||
src Source
|
||||
catalog *i18n.Catalog
|
||||
log *slog.Logger
|
||||
// og keeps the pages' preview images.
|
||||
og ogCache
|
||||
// ownHosts are the hosts that serve pages by slug; any other host is
|
||||
// looked up as a custom domain.
|
||||
ownHosts map[string]bool
|
||||
@@ -221,6 +223,7 @@ func (s *Server) persist(e entry) {
|
||||
}
|
||||
|
||||
func (s *Server) forget(key string) {
|
||||
s.forgetOG(key)
|
||||
s.mu.Lock()
|
||||
delete(s.cache, key)
|
||||
delete(s.visited, key)
|
||||
@@ -261,6 +264,10 @@ func hostOnly(h string) string {
|
||||
}
|
||||
|
||||
func (s *Server) serve(c *gin.Context) {
|
||||
if c.Request.URL.Path == "/robots.txt" && (c.Request.Method == http.MethodGet || c.Request.Method == http.MethodHead) {
|
||||
s.serveRobots(c)
|
||||
return
|
||||
}
|
||||
host := hostOnly(c.Request.Host)
|
||||
var parts []string
|
||||
if trimmed := strings.Trim(c.Request.URL.Path, "/"); trimmed != "" {
|
||||
@@ -295,16 +302,23 @@ func (s *Server) serve(c *gin.Context) {
|
||||
}
|
||||
e, ok := s.lookup(c.Request.Context(), key, host, slug)
|
||||
if !ok {
|
||||
if rt.kind == routeFeed || rt.kind == routeAPI {
|
||||
if rt.kind == routeFeed || rt.kind == routeAPI || rt.kind == routeOG || rt.kind == routeSitemap {
|
||||
c.Status(http.StatusNotFound)
|
||||
} else {
|
||||
s.notFound(c)
|
||||
}
|
||||
return
|
||||
}
|
||||
if rt.kind == routeLegal {
|
||||
switch rt.kind {
|
||||
case routeLegal:
|
||||
s.serveLegal(c, e, rt.arg, base)
|
||||
return
|
||||
case routeOG:
|
||||
s.serveOG(c, e, base)
|
||||
return
|
||||
case routeSitemap:
|
||||
s.serveSitemap(c, base)
|
||||
return
|
||||
}
|
||||
var staleSince time.Time
|
||||
if s.now().Sub(e.Fetched) > staleNoticeAfter {
|
||||
@@ -319,6 +333,7 @@ func (s *Server) serve(c *gin.Context) {
|
||||
}
|
||||
switch rt.kind {
|
||||
case routeComponent:
|
||||
assets.NoIndex = true
|
||||
s.serveComponent(c, e, rt.arg, assets)
|
||||
return
|
||||
case routeFeed:
|
||||
@@ -328,6 +343,7 @@ func (s *Server) serve(c *gin.Context) {
|
||||
s.serveAPI(c, e, rt.arg, base)
|
||||
return
|
||||
case routeSubscribe, routeConfirm, routeUnsubscribe:
|
||||
assets.NoIndex = true
|
||||
s.serveSubscription(c, e, rt.kind, host, slug, base, assets)
|
||||
return
|
||||
}
|
||||
@@ -339,7 +355,9 @@ func (s *Server) serve(c *gin.Context) {
|
||||
assets.Query = q
|
||||
}
|
||||
assets.OnlyProblems = c.Query("problems") == "1"
|
||||
web.Render(c, http.StatusOK, web.PublicStatusPage(e.Snap.WithMaintenance(s.now()), assets))
|
||||
snap := e.Snap.WithMaintenance(s.now())
|
||||
assets.Meta = s.pageMeta(c, snap, base)
|
||||
web.Render(c, http.StatusOK, web.PublicStatusPage(snap, assets))
|
||||
}
|
||||
|
||||
// componentsPerPage is how many of its own components a section of a
|
||||
@@ -403,14 +421,17 @@ func (s *Server) serveLegal(c *gin.Context, e entry, kind, base string) {
|
||||
}
|
||||
s.localizeRequest(c)
|
||||
c.Header("Cache-Control", "public, max-age=300")
|
||||
web.Render(c, http.StatusOK, web.PublicLegalPage(e.Snap, web.PublicAssets{CSSHref: "/static/dist/app.css"}, kind, html, base))
|
||||
web.Render(c, http.StatusOK, web.PublicLegalPage(e.Snap, web.PublicAssets{CSSHref: "/static/dist/app.css", NoIndex: true}, kind, html, base))
|
||||
}
|
||||
}
|
||||
|
||||
// localizeRequest shows the language ?lang= names, else the visitor's
|
||||
// preferred one; each language has its own address for search engines.
|
||||
func (s *Server) localizeRequest(c *gin.Context) {
|
||||
l := s.catalog.Match(c.GetHeader("Accept-Language"))
|
||||
l := s.catalog.Match(c.Query("lang"), c.GetHeader("Accept-Language"))
|
||||
c.Request = c.Request.WithContext(i18n.NewContext(c.Request.Context(), l))
|
||||
c.Header("Content-Language", l.Lang())
|
||||
c.Writer.Header().Add("Vary", "Accept-Language")
|
||||
}
|
||||
|
||||
// lookup answers from the cache whenever possible and refreshes in the
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package statuspage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -690,3 +691,88 @@ func TestComponentPagingAndSearch(t *testing.T) {
|
||||
t.Errorf("component page lacks the bar tooltips")
|
||||
}
|
||||
}
|
||||
|
||||
func (h harness) getFull(host, path string) *httptest.ResponseRecorder {
|
||||
req := httptest.NewRequest(http.MethodGet, path, nil)
|
||||
req.Host = host
|
||||
req.Header.Set("Accept-Language", "de")
|
||||
w := httptest.NewRecorder()
|
||||
h.r.ServeHTTP(w, req)
|
||||
return w
|
||||
}
|
||||
|
||||
func TestSearchAndPreviewMetadata(t *testing.T) {
|
||||
now := time.Now()
|
||||
src := newSource()
|
||||
src.set(func(f *fakeSource) {
|
||||
p := f.pages["|acme"]
|
||||
p.Description = "Status of **Acme** services.\n\nSecond paragraph."
|
||||
p.ShowDetails = true
|
||||
p.Sections = []agentapi.Section{{Components: []agentapi.Component{{ID: "c1", Name: "API", Status: agentapi.PageOperational}}}}
|
||||
f.pages["|acme"] = p
|
||||
})
|
||||
h := newHarness(t, src, t.TempDir(), &now)
|
||||
|
||||
_, body := h.get("status.example.test", "/acme")
|
||||
for _, want := range []string{
|
||||
`<meta name="description" content="Status of Acme services. Second paragraph.">`,
|
||||
`<link rel="canonical" href="http://status.example.test/acme/">`,
|
||||
`<link rel="alternate" hreflang="en" href="http://status.example.test/acme/?lang=en">`,
|
||||
`<link rel="alternate" hreflang="x-default" href="http://status.example.test/acme/">`,
|
||||
`<meta property="og:title" content="Acme status">`,
|
||||
`<meta property="og:image" content="http://status.example.test/acme/og.png?lang=de">`,
|
||||
`<meta property="og:locale" content="de_DE">`,
|
||||
`<meta name="twitter:card" content="summary_large_image">`,
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("status page lacks %s", want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(body, "noindex") {
|
||||
t.Errorf("status page is noindex")
|
||||
}
|
||||
|
||||
// ?lang= picks the language and becomes the canonical address.
|
||||
_, body = h.get("status.example.test", "/acme?lang=en&q=api")
|
||||
if !strings.Contains(body, "All systems operational") || !strings.Contains(body, `<link rel="canonical" href="http://status.example.test/acme/?lang=en">`) {
|
||||
t.Errorf("?lang=en does not show English with its own canonical address")
|
||||
}
|
||||
|
||||
// A page without a description describes itself by its status.
|
||||
_, body = h.get("status.acme.test", "/")
|
||||
if !strings.Contains(body, `<meta name="description" content="Aktueller Status von Acme on own domain: Größere Störung. Störungen`) {
|
||||
t.Errorf("custom domain page lacks the generated description")
|
||||
}
|
||||
if !strings.Contains(body, `<link rel="canonical" href="http://status.acme.test/">`) {
|
||||
t.Errorf("custom domain canonical address missing")
|
||||
}
|
||||
|
||||
for _, path := range []string{"/acme/components/c1", "/acme/subscribe"} {
|
||||
if code, body := h.get("status.example.test", path); code == 200 && !strings.Contains(body, `<meta name="robots" content="noindex, nofollow">`) {
|
||||
t.Errorf("GET %s is indexable", path)
|
||||
}
|
||||
}
|
||||
|
||||
w := h.getFull("status.example.test", "/acme/og.png")
|
||||
if w.Code != 200 || w.Header().Get("Content-Type") != "image/png" || !bytes.HasPrefix(w.Body.Bytes(), []byte("\x89PNG")) {
|
||||
t.Errorf("preview image = %d %s", w.Code, w.Header().Get("Content-Type"))
|
||||
}
|
||||
if code, _ := h.get("status.example.test", "/missing/og.png"); code != 404 {
|
||||
t.Errorf("preview image of a missing page = %d, want 404", code)
|
||||
}
|
||||
|
||||
w = h.getFull("status.acme.test", "/sitemap.xml")
|
||||
sm := w.Body.String()
|
||||
if w.Code != 200 || !strings.Contains(sm, "<loc>http://status.acme.test/</loc>") || !strings.Contains(sm, `hreflang="de" href="http://status.acme.test/?lang=de"`) {
|
||||
t.Errorf("sitemap = %d %s", w.Code, sm)
|
||||
}
|
||||
|
||||
_, robots := h.get("status.acme.test", "/robots.txt")
|
||||
if !strings.Contains(robots, "Disallow: /api/") || !strings.Contains(robots, "Sitemap: http://status.acme.test/sitemap.xml") {
|
||||
t.Errorf("custom domain robots.txt = %q", robots)
|
||||
}
|
||||
_, robots = h.get("status.example.test", "/robots.txt")
|
||||
if !strings.Contains(robots, "Disallow: /*/api/") || strings.Contains(robots, "Sitemap:") {
|
||||
t.Errorf("shared host robots.txt = %q", robots)
|
||||
}
|
||||
}
|
||||
@@ -13,17 +13,18 @@ import (
|
||||
)
|
||||
|
||||
const deleteSuccessEvidence = `-- name: DeleteSuccessEvidence :exec
|
||||
DELETE FROM check_evidence WHERE monitor_id = $1 AND region = $2 AND ok
|
||||
DELETE FROM check_evidence
|
||||
WHERE region = $1 AND ok AND monitor_id = ANY($2::uuid[])
|
||||
`
|
||||
|
||||
type DeleteSuccessEvidenceParams struct {
|
||||
MonitorID uuid.UUID
|
||||
Region string
|
||||
Region string
|
||||
MonitorIds []uuid.UUID
|
||||
}
|
||||
|
||||
// Only the latest success per monitor and region is kept.
|
||||
func (q *Queries) DeleteSuccessEvidence(ctx context.Context, arg DeleteSuccessEvidenceParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteSuccessEvidence, arg.MonitorID, arg.Region)
|
||||
_, err := q.db.Exec(ctx, deleteSuccessEvidence, arg.Region, arg.MonitorIds)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -124,27 +125,43 @@ func (q *Queries) InsertEvidence(ctx context.Context, arg InsertEvidenceParams)
|
||||
return err
|
||||
}
|
||||
|
||||
const lastFailureEvidence = `-- name: LastFailureEvidence :one
|
||||
SELECT time, coalesce(error, '')::text AS error FROM check_evidence
|
||||
WHERE monitor_id = $1 AND region = $2 AND NOT ok
|
||||
ORDER BY time DESC LIMIT 1
|
||||
const lastFailureEvidence = `-- name: LastFailureEvidence :many
|
||||
SELECT DISTINCT ON (monitor_id) monitor_id, time, coalesce(error, '')::text AS error
|
||||
FROM check_evidence
|
||||
WHERE region = $1 AND NOT ok AND monitor_id = ANY($2::uuid[])
|
||||
ORDER BY monitor_id, time DESC
|
||||
`
|
||||
|
||||
type LastFailureEvidenceParams struct {
|
||||
MonitorID uuid.UUID
|
||||
Region string
|
||||
Region string
|
||||
MonitorIds []uuid.UUID
|
||||
}
|
||||
|
||||
type LastFailureEvidenceRow struct {
|
||||
Time time.Time
|
||||
Error string
|
||||
MonitorID uuid.UUID
|
||||
Time time.Time
|
||||
Error string
|
||||
}
|
||||
|
||||
func (q *Queries) LastFailureEvidence(ctx context.Context, arg LastFailureEvidenceParams) (LastFailureEvidenceRow, error) {
|
||||
row := q.db.QueryRow(ctx, lastFailureEvidence, arg.MonitorID, arg.Region)
|
||||
var i LastFailureEvidenceRow
|
||||
err := row.Scan(&i.Time, &i.Error)
|
||||
return i, err
|
||||
// The newest failure per monitor in region.
|
||||
func (q *Queries) LastFailureEvidence(ctx context.Context, arg LastFailureEvidenceParams) ([]LastFailureEvidenceRow, error) {
|
||||
rows, err := q.db.Query(ctx, lastFailureEvidence, arg.Region, arg.MonitorIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []LastFailureEvidenceRow{}
|
||||
for rows.Next() {
|
||||
var i LastFailureEvidenceRow
|
||||
if err := rows.Scan(&i.MonitorID, &i.Time, &i.Error); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listEvidence = `-- name: ListEvidence :many
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: metrics.sql
|
||||
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const monitorCounts = `-- name: MonitorCounts :many
|
||||
SELECT type, enabled, count(*)::bigint AS monitors
|
||||
FROM monitors
|
||||
GROUP BY type, enabled
|
||||
ORDER BY type, enabled
|
||||
`
|
||||
|
||||
type MonitorCountsRow struct {
|
||||
Type string
|
||||
Enabled bool
|
||||
Monitors int64
|
||||
}
|
||||
|
||||
// System scope. Monitors by type and whether they are enabled.
|
||||
func (q *Queries) MonitorCounts(ctx context.Context) ([]MonitorCountsRow, error) {
|
||||
rows, err := q.db.Query(ctx, monitorCounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []MonitorCountsRow{}
|
||||
for rows.Next() {
|
||||
var i MonitorCountsRow
|
||||
if err := rows.Scan(&i.Type, &i.Enabled, &i.Monitors); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const platformCounts = `-- name: PlatformCounts :one
|
||||
SELECT
|
||||
(SELECT count(*) FROM orgs)::bigint AS orgs,
|
||||
(SELECT count(*) FROM users)::bigint AS users,
|
||||
(SELECT count(*) FROM status_pages)::bigint AS status_pages,
|
||||
(SELECT count(*) FROM status_page_subscribers WHERE confirmed_at IS NOT NULL)::bigint AS subscribers,
|
||||
(SELECT count(*) FROM incidents WHERE resolved_at IS NULL)::bigint AS open_incidents,
|
||||
(SELECT count(*) FROM notifications WHERE status = 'pending')::bigint AS pending_notifications,
|
||||
(SELECT count(*) FROM subscriber_notifications WHERE status = 'pending')::bigint AS pending_subscriber_notifications
|
||||
`
|
||||
|
||||
type PlatformCountsRow struct {
|
||||
Orgs int64
|
||||
Users int64
|
||||
StatusPages int64
|
||||
Subscribers int64
|
||||
OpenIncidents int64
|
||||
PendingNotifications int64
|
||||
PendingSubscriberNotifications int64
|
||||
}
|
||||
|
||||
// System scope. Platform totals for the operator metrics.
|
||||
func (q *Queries) PlatformCounts(ctx context.Context) (PlatformCountsRow, error) {
|
||||
row := q.db.QueryRow(ctx, platformCounts)
|
||||
var i PlatformCountsRow
|
||||
err := row.Scan(
|
||||
&i.Orgs,
|
||||
&i.Users,
|
||||
&i.StatusPages,
|
||||
&i.Subscribers,
|
||||
&i.OpenIncidents,
|
||||
&i.PendingNotifications,
|
||||
&i.PendingSubscriberNotifications,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -217,7 +217,8 @@ type Querier interface {
|
||||
InsertRecoveryCodes(ctx context.Context, arg []InsertRecoveryCodesParams) (int64, error)
|
||||
InvitationOrg(ctx context.Context, hash []byte) (uuid.UUID, error)
|
||||
IsMember(ctx context.Context, arg IsMemberParams) (bool, error)
|
||||
LastFailureEvidence(ctx context.Context, arg LastFailureEvidenceParams) (LastFailureEvidenceRow, error)
|
||||
// The newest failure per monitor in region.
|
||||
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.
|
||||
@@ -314,6 +315,8 @@ type Querier interface {
|
||||
MemberGrants(ctx context.Context, arg MemberGrantsParams) ([]MemberGrantsRow, error)
|
||||
MonitorAlertGroups(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
|
||||
MonitorAlertRoutes(ctx context.Context, monitorID uuid.UUID) ([]MonitorAlertRoutesRow, error)
|
||||
// System scope. Monitors by type and whether they are enabled.
|
||||
MonitorCounts(ctx context.Context) ([]MonitorCountsRow, error)
|
||||
MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
|
||||
// System scope: monitors to hand to a checker of region, skipping ones that
|
||||
// were disabled, deleted or moved out of the region since dispatch. An
|
||||
@@ -341,6 +344,8 @@ type Querier interface {
|
||||
OrgServesOwnPages(ctx context.Context, orgID *uuid.UUID) (bool, error)
|
||||
// Organizations user owns, with their member and owner counts.
|
||||
OwnedOrgs(ctx context.Context, userID uuid.UUID) ([]OwnedOrgsRow, error)
|
||||
// System scope. Platform totals for the operator metrics.
|
||||
PlatformCounts(ctx context.Context) (PlatformCountsRow, error)
|
||||
// The public updates of incidents shown on a status page, newest first.
|
||||
PublicIncidentUpdates(ctx context.Context, ids []uuid.UUID) ([]PublicIncidentUpdatesRow, error)
|
||||
// Resolved and long silent alerts are history the monitors' results keep.
|
||||
|
||||
@@ -4,12 +4,15 @@ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
||||
|
||||
-- name: DeleteSuccessEvidence :exec
|
||||
-- Only the latest success per monitor and region is kept.
|
||||
DELETE FROM check_evidence WHERE monitor_id = $1 AND region = $2 AND ok;
|
||||
DELETE FROM check_evidence
|
||||
WHERE region = sqlc.arg(region) AND ok AND monitor_id = ANY(sqlc.arg(monitor_ids)::uuid[]);
|
||||
|
||||
-- name: LastFailureEvidence :one
|
||||
SELECT time, coalesce(error, '')::text AS error FROM check_evidence
|
||||
WHERE monitor_id = $1 AND region = $2 AND NOT ok
|
||||
ORDER BY time DESC LIMIT 1;
|
||||
-- name: LastFailureEvidence :many
|
||||
-- The newest failure per monitor in region.
|
||||
SELECT DISTINCT ON (monitor_id) monitor_id, time, coalesce(error, '')::text AS error
|
||||
FROM check_evidence
|
||||
WHERE region = sqlc.arg(region) AND NOT ok AND monitor_id = ANY(sqlc.arg(monitor_ids)::uuid[])
|
||||
ORDER BY monitor_id, time DESC;
|
||||
|
||||
-- name: ListEvidence :many
|
||||
-- Newest first, a page from a keyset cursor (see paging.go).
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
-- name: PlatformCounts :one
|
||||
-- System scope. Platform totals for the operator metrics.
|
||||
SELECT
|
||||
(SELECT count(*) FROM orgs)::bigint AS orgs,
|
||||
(SELECT count(*) FROM users)::bigint AS users,
|
||||
(SELECT count(*) FROM status_pages)::bigint AS status_pages,
|
||||
(SELECT count(*) FROM status_page_subscribers WHERE confirmed_at IS NOT NULL)::bigint AS subscribers,
|
||||
(SELECT count(*) FROM incidents WHERE resolved_at IS NULL)::bigint AS open_incidents,
|
||||
(SELECT count(*) FROM notifications WHERE status = 'pending')::bigint AS pending_notifications,
|
||||
(SELECT count(*) FROM subscriber_notifications WHERE status = 'pending')::bigint AS pending_subscriber_notifications;
|
||||
|
||||
-- name: MonitorCounts :many
|
||||
-- System scope. Monitors by type and whether they are enabled.
|
||||
SELECT type, enabled, count(*)::bigint AS monitors
|
||||
FROM monitors
|
||||
GROUP BY type, enabled
|
||||
ORDER BY type, enabled;
|
||||
@@ -164,6 +164,29 @@
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
/* Pins whose label would cover another one turn it to the left of their
|
||||
point, or show only their dot until hovered. */
|
||||
.is-flipped > .region-pin {
|
||||
flex-direction: row-reverse;
|
||||
padding: 3px 5px 3px 9px;
|
||||
translate: calc(16px - 100%);
|
||||
}
|
||||
.maplibregl-marker:is(.is-flipped, .is-compact):not(.is-hover, :hover) { z-index: 2; }
|
||||
.is-compact > .region-pin { gap: 0; padding: 3px 5px; }
|
||||
.is-compact:not(.is-hover, :hover) > .region-pin > :last-child { display: none; }
|
||||
.is-compact.is-hover > .region-pin,
|
||||
.is-compact:hover > .region-pin { gap: 6px; padding: 3px 9px 3px 5px; }
|
||||
@media (pointer: coarse) {
|
||||
.is-flipped > .region-pin { padding: 6px 8px 6px 11px; }
|
||||
.is-compact > .region-pin { padding: 6px 8px; }
|
||||
}
|
||||
/* Regions locked by the monitor's region limit. */
|
||||
label.is-locked { opacity: 0.5; cursor: not-allowed; }
|
||||
/* Opaque, so stacked pins do not show through each other. */
|
||||
.region-pin.is-disabled { color: var(--color-muted); cursor: not-allowed; box-shadow: none; }
|
||||
.region-pin.is-disabled .region-pin-dot { background: var(--color-unknown); }
|
||||
.is-hover > .region-pin.is-disabled,
|
||||
.region-pin.is-disabled:hover { transform: none; }
|
||||
.region-pin:focus-visible { outline: 2px solid var(--color-maintenance); outline-offset: 2px; }
|
||||
.region-pick {
|
||||
width: 14px;
|
||||
|
||||
@@ -698,6 +698,7 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
|
||||
fit();
|
||||
|
||||
const selecting = box.dataset.regionMap === "select";
|
||||
const markers = [];
|
||||
for (const item of items) {
|
||||
// The list row (a label or table row) and the marker light up together.
|
||||
const row = item.closest("label, tr") ?? item;
|
||||
@@ -708,6 +709,7 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
|
||||
const holder = document.createElement("div");
|
||||
holder.append(pin);
|
||||
const marker = new gl.Marker({ element: holder, anchor: "left", offset: [-8, 0] }).setLngLat(lngLat(item)).addTo(map);
|
||||
markers.push({ holder, pin, marker });
|
||||
const hover = (on) => {
|
||||
holder.classList.toggle("is-hover", on);
|
||||
row.classList.toggle("is-hover", on);
|
||||
@@ -724,8 +726,12 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
|
||||
pin.classList.toggle("is-checked", item.checked);
|
||||
row.classList.toggle("is-checked", item.checked);
|
||||
pin.setAttribute("aria-pressed", String(item.checked));
|
||||
// Locked once the monitor uses as many regions as it may.
|
||||
pin.classList.toggle("is-disabled", item.disabled);
|
||||
pin.setAttribute("aria-disabled", String(item.disabled));
|
||||
};
|
||||
paint();
|
||||
item.closest("[data-region-limit]")?.addEventListener("regionlimit", paint);
|
||||
item.addEventListener("change", () => {
|
||||
paint();
|
||||
// A region ticked in the list comes into view on the map.
|
||||
@@ -743,6 +749,48 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Labels run to the right of their point, or to the left where that
|
||||
// would cover another pin or leave the map, as with regions a few
|
||||
// kilometres apart. A pin with room on neither side shows only its dot
|
||||
// and its name on hover; the list names every region. No label covers
|
||||
// the dot of another pin.
|
||||
const place = () => {
|
||||
const width = box.clientWidth;
|
||||
const height = box.clientHeight;
|
||||
if (!width) return;
|
||||
for (const m of markers) m.holder.classList.remove("is-flipped", "is-compact");
|
||||
const spots = markers.map((m) => {
|
||||
const at = map.project(m.marker.getLngLat());
|
||||
const h = m.pin.offsetHeight;
|
||||
return { m, at, w: m.pin.offsetWidth, h, dot: { left: at.x - 8, right: at.x + 12, top: at.y - h / 2, bottom: at.y + h / 2 } };
|
||||
});
|
||||
// The rounded ends of two pills may touch.
|
||||
const hits = (a, b) => a.left + 4 < b.right - 4 && b.left + 4 < a.right - 4 && a.top < b.bottom && b.top < a.bottom;
|
||||
const labels = [];
|
||||
const fits = (a, self) =>
|
||||
a.left >= 0 && a.right <= width && a.top >= 0 && a.bottom <= height &&
|
||||
!labels.some((b) => hits(a, b)) &&
|
||||
// Dots stacked on its own one stay beside it either way.
|
||||
!spots.some((s) => s !== self && !hits(s.dot, self.dot) && hits(a, s.dot));
|
||||
for (const s of spots.sort((a, b) => b.at.x - a.at.x)) {
|
||||
const right = { ...s.dot, right: s.at.x - 8 + s.w };
|
||||
const left = { ...s.dot, left: s.at.x + 8 - s.w, right: s.at.x + 8 };
|
||||
if (fits(right, s)) {
|
||||
labels.push(right);
|
||||
} else if (fits(left, s)) {
|
||||
s.m.holder.classList.add("is-flipped");
|
||||
labels.push(left);
|
||||
} else {
|
||||
s.m.holder.classList.add("is-compact");
|
||||
}
|
||||
}
|
||||
};
|
||||
map.on("load", place);
|
||||
map.on("zoom", place);
|
||||
map.on("moveend", place);
|
||||
map.on("resize", place);
|
||||
|
||||
if (selecting) return;
|
||||
let pick;
|
||||
map.on("click", (ev) => {
|
||||
@@ -758,5 +806,24 @@ for (const el of document.querySelectorAll("input[data-tz-default]")) {
|
||||
pick.setLngLat(point);
|
||||
});
|
||||
};
|
||||
// A monitor may use only so many counted regions: once they are all
|
||||
// ticked, the other counted ones are locked until one is unticked. The
|
||||
// server enforces the limit either way.
|
||||
for (const list of document.querySelectorAll("[data-region-limit]")) {
|
||||
const limit = Number(list.dataset.regionLimit);
|
||||
const counted = [...list.querySelectorAll("input[data-counted]")];
|
||||
const count = list.closest("fieldset")?.querySelector("[data-region-count]");
|
||||
const update = () => {
|
||||
const n = counted.filter((i) => i.checked).length;
|
||||
for (const i of counted) {
|
||||
i.disabled = !i.checked && n >= limit;
|
||||
i.closest("label")?.classList.toggle("is-locked", i.disabled);
|
||||
}
|
||||
if (count) count.textContent = `(${n}/${limit})`;
|
||||
list.dispatchEvent(new Event("regionlimit"));
|
||||
};
|
||||
list.addEventListener("change", update);
|
||||
update();
|
||||
}
|
||||
for (const box of document.querySelectorAll("[data-region-map]")) initRegionMap(box);
|
||||
})();
|
||||
@@ -19,6 +19,9 @@ type Page struct {
|
||||
Legal []LegalLink
|
||||
// RefreshSeconds reloads pages that show live state.
|
||||
RefreshSeconds int
|
||||
// Meta describes public pages for search engines and link previews;
|
||||
// pages without it are kept out of search engines.
|
||||
Meta *PageMeta
|
||||
}
|
||||
|
||||
templ Layout(p Page) {
|
||||
@@ -34,6 +37,11 @@ templ Layout(p Page) {
|
||||
<meta http-equiv="refresh" content={ strconv.Itoa(p.RefreshSeconds) }/>
|
||||
}
|
||||
<title>{ i18n.T(ctx, p.TitleID) } · UptimeSebi</title>
|
||||
if p.Meta != nil {
|
||||
@metaTags(p.Meta)
|
||||
} else {
|
||||
@noIndex()
|
||||
}
|
||||
@faviconLinks()
|
||||
<link rel="stylesheet" href="/static/dist/app.css"/>
|
||||
<script src="/static/dist/axios.min.js" defer></script>
|
||||
|
||||
@@ -28,6 +28,9 @@ type Page struct {
|
||||
Legal []LegalLink
|
||||
// RefreshSeconds reloads pages that show live state.
|
||||
RefreshSeconds int
|
||||
// Meta describes public pages for search engines and link previews;
|
||||
// pages without it are kept out of search engines.
|
||||
Meta *PageMeta
|
||||
}
|
||||
|
||||
func Layout(p Page) templ.Component {
|
||||
@@ -55,7 +58,7 @@ func Layout(p Page) templ.Component {
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.Lang(ctx)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 26, Col: 28}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 29, Col: 28}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -73,7 +76,7 @@ func Layout(p Page) templ.Component {
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(p.CSRF).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 31, Col: 44}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 34, Col: 44}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -92,7 +95,7 @@ func Layout(p Page) templ.Component {
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templruntime.NewAttributeExpression(strconv.Itoa(p.RefreshSeconds)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 34, Col: 71}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 37, Col: 71}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -110,7 +113,7 @@ func Layout(p Page) templ.Component {
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.TitleID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 36, Col: 34}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 39, Col: 34}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -120,6 +123,17 @@ func Layout(p Page) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if p.Meta != nil {
|
||||
templ_7745c5c3_Err = metaTags(p.Meta).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
templ_7745c5c3_Err = noIndex().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = faviconLinks().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
@@ -131,7 +145,7 @@ func Layout(p Page) templ.Component {
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "app.network_error")).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 42, Col: 94}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 50, Col: 94}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -191,7 +205,7 @@ func languageSwitch(langs []string) templ.Component {
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(l)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 55, Col: 50}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 63, Col: 50}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -209,7 +223,7 @@ func languageSwitch(langs []string) templ.Component {
|
||||
var templ_7745c5c3_Var9 string
|
||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templruntime.NewAttributeExpression(l).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 57, Col: 41}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 65, Col: 41}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -222,7 +236,7 @@ func languageSwitch(langs []string) templ.Component {
|
||||
var templ_7745c5c3_Var10 string
|
||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "lang."+l)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 57, Col: 108}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 65, Col: 108}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -235,7 +249,7 @@ func languageSwitch(langs []string) templ.Component {
|
||||
var templ_7745c5c3_Var11 string
|
||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(l)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 57, Col: 114}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 65, Col: 114}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -304,7 +318,7 @@ func authShell(p Page) templ.Component {
|
||||
var templ_7745c5c3_Var14 string
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.TitleID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 70, Col: 66}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 78, Col: 66}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -360,7 +374,7 @@ func field(label, name, typ, autocomplete string, required bool) templ.Component
|
||||
var templ_7745c5c3_Var16 string
|
||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(label)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 79, Col: 90}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 87, Col: 90}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -373,7 +387,7 @@ func field(label, name, typ, autocomplete string, required bool) templ.Component
|
||||
var templ_7745c5c3_Var17 string
|
||||
templ_7745c5c3_Var17, templ_7745c5c3_Err = templruntime.NewAttributeExpression(typ).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 82, Col: 13}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 90, Col: 13}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -386,7 +400,7 @@ func field(label, name, typ, autocomplete string, required bool) templ.Component
|
||||
var templ_7745c5c3_Var18 string
|
||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 83, Col: 14}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 91, Col: 14}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var18)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -399,7 +413,7 @@ func field(label, name, typ, autocomplete string, required bool) templ.Component
|
||||
var templ_7745c5c3_Var19 string
|
||||
templ_7745c5c3_Var19, templ_7745c5c3_Err = templruntime.NewAttributeExpression(autocomplete).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 84, Col: 30}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 92, Col: 30}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var19)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -447,7 +461,7 @@ func submit(label string) templ.Component {
|
||||
var templ_7745c5c3_Var21 string
|
||||
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(label)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 92, Col: 9}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 100, Col: 9}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -486,7 +500,7 @@ func flash(p Page) templ.Component {
|
||||
var templ_7745c5c3_Var23 string
|
||||
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.ErrorID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 98, Col: 88}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 106, Col: 88}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -505,7 +519,7 @@ func flash(p Page) templ.Component {
|
||||
var templ_7745c5c3_Var24 string
|
||||
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.NoticeID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 101, Col: 77}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/layout.templ`, Line: 109, Col: 77}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"html"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/ogimage"
|
||||
)
|
||||
|
||||
// PageMeta describes a page for search engines and link previews. Pages
|
||||
// without one are private and carry noindex.
|
||||
type PageMeta struct {
|
||||
// Title is the shared title, without the site suffix of <title>.
|
||||
Title string
|
||||
Description string
|
||||
// URL is the canonical address of the page.
|
||||
URL string
|
||||
Image string
|
||||
SiteName string
|
||||
// Lang is the language the page is shown in.
|
||||
Lang string
|
||||
// Alternates are the page in each language, plus x-default.
|
||||
Alternates []MetaAlternate
|
||||
}
|
||||
|
||||
// MetaAlternate is a language version of a page; Lang "x-default" marks
|
||||
// the one that picks the language itself.
|
||||
type MetaAlternate struct {
|
||||
Lang string
|
||||
URL string
|
||||
}
|
||||
|
||||
// LangURL adds ?lang= to a page's address.
|
||||
func LangURL(base, lang string) string {
|
||||
u, err := url.Parse(base)
|
||||
if err != nil {
|
||||
return base
|
||||
}
|
||||
q := u.Query()
|
||||
q.Set("lang", lang)
|
||||
u.RawQuery = q.Encode()
|
||||
return u.String()
|
||||
}
|
||||
|
||||
// NewPageMeta fills the language versions and the canonical address of a
|
||||
// page at base: the address of its language when the visitor chose one
|
||||
// with ?lang=, else base, which picks the language itself.
|
||||
func NewPageMeta(title, description, base, image, siteName, lang string, chosen bool, langs []string) *PageMeta {
|
||||
m := &PageMeta{Title: title, Description: description, URL: base, Image: image, SiteName: siteName, Lang: lang}
|
||||
if chosen {
|
||||
m.URL = LangURL(base, lang)
|
||||
}
|
||||
for _, l := range langs {
|
||||
m.Alternates = append(m.Alternates, MetaAlternate{Lang: l, URL: LangURL(base, l)})
|
||||
}
|
||||
m.Alternates = append(m.Alternates, MetaAlternate{Lang: "x-default", URL: base})
|
||||
return m
|
||||
}
|
||||
|
||||
var tagRE = regexp.MustCompile(`<[^>]*>`)
|
||||
|
||||
// PlainText turns Markdown into a single line of text of at most max
|
||||
// characters, for descriptions.
|
||||
func PlainText(markdown string, max int) string {
|
||||
s := html.UnescapeString(tagRE.ReplaceAllString(Markdown(markdown), " "))
|
||||
s = strings.Join(strings.Fields(s), " ")
|
||||
if utf8.RuneCountInString(s) <= max {
|
||||
return s
|
||||
}
|
||||
r := []rune(s)[:max-1]
|
||||
if i := strings.LastIndex(string(r), " "); i > max/2 {
|
||||
return string(r)[:i] + "…"
|
||||
}
|
||||
return string(r) + "…"
|
||||
}
|
||||
|
||||
// ogLocale maps a language to the locale Open Graph expects.
|
||||
func ogLocale(lang string) string {
|
||||
switch lang {
|
||||
case "de":
|
||||
return "de_DE"
|
||||
case "en":
|
||||
return "en_US"
|
||||
}
|
||||
return strings.ReplaceAll(lang, "-", "_")
|
||||
}
|
||||
|
||||
// metaTags are the description, canonical address, language versions and
|
||||
// Open Graph and Twitter tags of m.
|
||||
templ metaTags(m *PageMeta) {
|
||||
if m.Description != "" {
|
||||
<meta name="description" content={ m.Description }/>
|
||||
}
|
||||
<link rel="canonical" href={ m.URL }/>
|
||||
for _, a := range m.Alternates {
|
||||
<link rel="alternate" hreflang={ a.Lang } href={ a.URL }/>
|
||||
}
|
||||
<meta property="og:type" content="website"/>
|
||||
if m.SiteName != "" {
|
||||
<meta property="og:site_name" content={ m.SiteName }/>
|
||||
}
|
||||
<meta property="og:title" content={ m.Title }/>
|
||||
if m.Description != "" {
|
||||
<meta property="og:description" content={ m.Description }/>
|
||||
}
|
||||
<meta property="og:url" content={ m.URL }/>
|
||||
<meta property="og:locale" content={ ogLocale(m.Lang) }/>
|
||||
if m.Image != "" {
|
||||
<meta property="og:image" content={ m.Image }/>
|
||||
<meta property="og:image:type" content="image/png"/>
|
||||
<meta property="og:image:width" content={ strconv.Itoa(ogimage.Width) }/>
|
||||
<meta property="og:image:height" content={ strconv.Itoa(ogimage.Height) }/>
|
||||
<meta property="og:image:alt" content={ m.Title }/>
|
||||
}
|
||||
<meta name="twitter:card" content={ twitterCard(m) }/>
|
||||
<meta name="twitter:title" content={ m.Title }/>
|
||||
if m.Description != "" {
|
||||
<meta name="twitter:description" content={ m.Description }/>
|
||||
}
|
||||
if m.Image != "" {
|
||||
<meta name="twitter:image" content={ m.Image }/>
|
||||
}
|
||||
}
|
||||
|
||||
func twitterCard(m *PageMeta) string {
|
||||
if m.Image != "" {
|
||||
return "summary_large_image"
|
||||
}
|
||||
return "summary"
|
||||
}
|
||||
|
||||
templ noIndex() {
|
||||
<meta name="robots" content="noindex, nofollow"/>
|
||||
}
|
||||
@@ -0,0 +1,439 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.3.1118
|
||||
|
||||
package web
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import (
|
||||
"html"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.zb-server.de/ZB-Server/uptimesebi/internal/ogimage"
|
||||
)
|
||||
|
||||
// PageMeta describes a page for search engines and link previews. Pages
|
||||
// without one are private and carry noindex.
|
||||
type PageMeta struct {
|
||||
// Title is the shared title, without the site suffix of <title>.
|
||||
Title string
|
||||
Description string
|
||||
// URL is the canonical address of the page.
|
||||
URL string
|
||||
Image string
|
||||
SiteName string
|
||||
// Lang is the language the page is shown in.
|
||||
Lang string
|
||||
// Alternates are the page in each language, plus x-default.
|
||||
Alternates []MetaAlternate
|
||||
}
|
||||
|
||||
// MetaAlternate is a language version of a page; Lang "x-default" marks
|
||||
// the one that picks the language itself.
|
||||
type MetaAlternate struct {
|
||||
Lang string
|
||||
URL string
|
||||
}
|
||||
|
||||
// LangURL adds ?lang= to a page's address.
|
||||
func LangURL(base, lang string) string {
|
||||
u, err := url.Parse(base)
|
||||
if err != nil {
|
||||
return base
|
||||
}
|
||||
q := u.Query()
|
||||
q.Set("lang", lang)
|
||||
u.RawQuery = q.Encode()
|
||||
return u.String()
|
||||
}
|
||||
|
||||
// NewPageMeta fills the language versions and the canonical address of a
|
||||
// page at base: the address of its language when the visitor chose one
|
||||
// with ?lang=, else base, which picks the language itself.
|
||||
func NewPageMeta(title, description, base, image, siteName, lang string, chosen bool, langs []string) *PageMeta {
|
||||
m := &PageMeta{Title: title, Description: description, URL: base, Image: image, SiteName: siteName, Lang: lang}
|
||||
if chosen {
|
||||
m.URL = LangURL(base, lang)
|
||||
}
|
||||
for _, l := range langs {
|
||||
m.Alternates = append(m.Alternates, MetaAlternate{Lang: l, URL: LangURL(base, l)})
|
||||
}
|
||||
m.Alternates = append(m.Alternates, MetaAlternate{Lang: "x-default", URL: base})
|
||||
return m
|
||||
}
|
||||
|
||||
var tagRE = regexp.MustCompile(`<[^>]*>`)
|
||||
|
||||
// PlainText turns Markdown into a single line of text of at most max
|
||||
// characters, for descriptions.
|
||||
func PlainText(markdown string, max int) string {
|
||||
s := html.UnescapeString(tagRE.ReplaceAllString(Markdown(markdown), " "))
|
||||
s = strings.Join(strings.Fields(s), " ")
|
||||
if utf8.RuneCountInString(s) <= max {
|
||||
return s
|
||||
}
|
||||
r := []rune(s)[:max-1]
|
||||
if i := strings.LastIndex(string(r), " "); i > max/2 {
|
||||
return string(r)[:i] + "…"
|
||||
}
|
||||
return string(r) + "…"
|
||||
}
|
||||
|
||||
// ogLocale maps a language to the locale Open Graph expects.
|
||||
func ogLocale(lang string) string {
|
||||
switch lang {
|
||||
case "de":
|
||||
return "de_DE"
|
||||
case "en":
|
||||
return "en_US"
|
||||
}
|
||||
return strings.ReplaceAll(lang, "-", "_")
|
||||
}
|
||||
|
||||
// metaTags are the description, canonical address, language versions and
|
||||
// Open Graph and Twitter tags of m.
|
||||
func metaTags(m *PageMeta) 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)
|
||||
if m.Description != "" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<meta name=\"description\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Description).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 96, Col: 50}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<link rel=\"canonical\" href=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.URL).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 98, Col: 35}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
for _, a := range m.Alternates {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "<link rel=\"alternate\" hreflang=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templruntime.NewAttributeExpression(a.Lang).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 100, Col: 41}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "\" href=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templruntime.NewAttributeExpression(a.URL).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 100, Col: 56}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<meta property=\"og:type\" content=\"website\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if m.SiteName != "" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<meta property=\"og:site_name\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.SiteName).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 104, Col: 52}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "<meta property=\"og:title\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Title).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 106, Col: 44}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if m.Description != "" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "<meta property=\"og:description\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Description).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 108, Col: 57}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<meta property=\"og:url\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var9 string
|
||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.URL).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 110, Col: 40}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\"><meta property=\"og:locale\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var10 string
|
||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templruntime.NewAttributeExpression(ogLocale(m.Lang)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 111, Col: 54}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if m.Image != "" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<meta property=\"og:image\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var11 string
|
||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Image).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 113, Col: 45}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var11)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\"><meta property=\"og:image:type\" content=\"image/png\"><meta property=\"og:image:width\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templruntime.NewAttributeExpression(strconv.Itoa(ogimage.Width)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 115, Col: 71}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var12)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\"><meta property=\"og:image:height\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templruntime.NewAttributeExpression(strconv.Itoa(ogimage.Height)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 116, Col: 73}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var13)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "\"><meta property=\"og:image:alt\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var14 string
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Title).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 117, Col: 49}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var14)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "<meta name=\"twitter:card\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var15 string
|
||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templruntime.NewAttributeExpression(twitterCard(m)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 119, Col: 51}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "\"><meta name=\"twitter:title\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var16 string
|
||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Title).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 120, Col: 45}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var16)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if m.Description != "" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<meta name=\"twitter:description\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var17 string
|
||||
templ_7745c5c3_Var17, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Description).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 122, Col: 58}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
if m.Image != "" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<meta name=\"twitter:image\" content=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var18 string
|
||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templruntime.NewAttributeExpression(m.Image).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/meta.templ`, Line: 125, Col: 46}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var18)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func twitterCard(m *PageMeta) string {
|
||||
if m.Image != "" {
|
||||
return "summary_large_image"
|
||||
}
|
||||
return "summary"
|
||||
}
|
||||
|
||||
func noIndex() 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, 30, "<meta name=\"robots\" content=\"noindex, nofollow\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
@@ -726,6 +726,9 @@ type RegionOption struct {
|
||||
Lat, Lon *float64
|
||||
}
|
||||
|
||||
// Counted reports whether r counts towards the form's region limit.
|
||||
func (f MonitorForm) Counted(r RegionOption) bool { return !r.Own || f.OwnRegionsCount }
|
||||
|
||||
// RegionsMapped reports whether any region of the form has a location.
|
||||
func (f MonitorForm) RegionsMapped() bool {
|
||||
for _, r := range f.Regions {
|
||||
@@ -753,6 +756,10 @@ type MonitorForm struct {
|
||||
TopLevel bool
|
||||
Regions []RegionOption
|
||||
MinInterval int
|
||||
// RegionLimit caps the counted regions a monitor uses; 0 is unlimited.
|
||||
// Own regions count only with OwnRegionsCount.
|
||||
RegionLimit int
|
||||
OwnRegionsCount bool
|
||||
// Type-specific settings.
|
||||
Method string
|
||||
ExpectStatus string
|
||||
@@ -1132,10 +1139,25 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
|
||||
<fieldset class="mb-4" data-hide-for="heartbeat alertmanager" hidden?={ passiveType(f.Type) } disabled?={ f.Type == "heartbeat" }>
|
||||
<legend class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "monitors.regions") }</legend>
|
||||
<p class="mb-2 text-xs text-muted">{ i18n.T(ctx, "monitors.regions_hint") }</p>
|
||||
if f.RegionLimit > 0 {
|
||||
<p class="mb-2 text-xs text-muted" data-region-limit-hint>
|
||||
if f.OwnRegionsCount {
|
||||
{ i18n.T(ctx, "monitors.regions_limit", "Max", f.RegionLimit) }
|
||||
} else {
|
||||
{ i18n.T(ctx, "monitors.platform_regions_limit", "Max", f.RegionLimit) }
|
||||
}
|
||||
<span class="font-mono" data-region-count></span>
|
||||
</p>
|
||||
}
|
||||
if f.RegionsMapped() {
|
||||
@regionMap("select", "#monitor-regions")
|
||||
}
|
||||
<div id="monitor-regions">
|
||||
<div
|
||||
id="monitor-regions"
|
||||
if f.RegionLimit > 0 {
|
||||
data-region-limit={ strconv.Itoa(f.RegionLimit) }
|
||||
}
|
||||
>
|
||||
for _, r := range f.Regions {
|
||||
<label class="-mx-2 mb-0.5 flex items-center gap-2 px-2 py-1 text-sm">
|
||||
<input
|
||||
@@ -1151,6 +1173,9 @@ templ MonitorEditor(p Page, me Me, f MonitorForm) {
|
||||
}
|
||||
data-name={ r.Name }
|
||||
data-live={ strconv.FormatInt(r.Live, 10) }
|
||||
if f.Counted(r) {
|
||||
data-counted
|
||||
}
|
||||
/>
|
||||
{ r.Name }
|
||||
<span class="font-mono text-xs text-muted">
|
||||
|
||||
+1265
-1186
File diff suppressed because it is too large.
Load diff
@@ -16,6 +16,11 @@ import (
|
||||
type PublicAssets struct {
|
||||
CSSHref string
|
||||
InlineCSS string
|
||||
// Meta describes the page for search engines and link previews.
|
||||
Meta *PageMeta
|
||||
// NoIndex keeps the page out of search engines, as with legal and
|
||||
// subscription pages, which only repeat or serve the status page.
|
||||
NoIndex bool
|
||||
// StaleSince, if set, tells visitors that live updates are unavailable
|
||||
// and the page shows the state of that moment.
|
||||
StaleSince time.Time
|
||||
|
||||
@@ -22,6 +22,12 @@ templ publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) {
|
||||
<link rel="alternate" type="application/rss+xml" title={ s.Title } href={ a.ComponentBase + "feed.rss" }/>
|
||||
}
|
||||
<title>{ docTitle }</title>
|
||||
if a.Meta != nil {
|
||||
@metaTags(a.Meta)
|
||||
}
|
||||
if a.NoIndex {
|
||||
@noIndex()
|
||||
}
|
||||
if a.InlineCSS == "" {
|
||||
@faviconLinks()
|
||||
}
|
||||
|
||||
+115
-103
@@ -108,6 +108,18 @@ func publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) templ
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if a.Meta != nil {
|
||||
templ_7745c5c3_Err = metaTags(a.Meta).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
if a.NoIndex {
|
||||
templ_7745c5c3_Err = noIndex().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
if a.InlineCSS == "" {
|
||||
templ_7745c5c3_Err = faviconLinks().Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -127,7 +139,7 @@ func publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) templ
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templruntime.NewAttributeExpression(a.CSSHref).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 31, Col: 43}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 37, Col: 43}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -165,7 +177,7 @@ func publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) templ
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.updated", "Time", s.GeneratedAt.UTC().Format(time.DateTime)+" UTC"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 44, Col: 98}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 50, Col: 98}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -183,7 +195,7 @@ func publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) templ
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(a.ComponentBase + "feed.rss")).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 47, Col: 60}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 53, Col: 60}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -196,7 +208,7 @@ func publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) templ
|
||||
var templ_7745c5c3_Var9 string
|
||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.feed"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 47, Col: 112}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 53, Col: 112}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -209,7 +221,7 @@ func publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) templ
|
||||
var templ_7745c5c3_Var10 string
|
||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(a.ComponentBase + "api/v1/summary")).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 48, Col: 66}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 54, Col: 66}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -222,7 +234,7 @@ func publicShell(s agentapi.PageSnapshot, a PublicAssets, docTitle string) templ
|
||||
var templ_7745c5c3_Var11 string
|
||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.api"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 48, Col: 117}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 54, Col: 117}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -280,7 +292,7 @@ func publicStaleNotice(a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.stale", "Time", a.StaleSince.UTC().Format("2006-01-02 15:04")+" UTC"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 67, Col: 92}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 73, Col: 92}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -336,7 +348,7 @@ func PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var16 string
|
||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templruntime.NewAttributeExpression(s.Theme.LogoURL).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 76, Col: 30}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 82, Col: 30}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var16)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -349,7 +361,7 @@ func PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var17 string
|
||||
templ_7745c5c3_Var17, templ_7745c5c3_Err = templruntime.NewAttributeExpression(s.Title).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 76, Col: 46}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 82, Col: 46}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -367,7 +379,7 @@ func PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var18 string
|
||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(s.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 78, Col: 88}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 84, Col: 88}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -447,7 +459,7 @@ func PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var21 string
|
||||
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.status."+s.Status))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 94, Col: 72}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 100, Col: 72}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -487,7 +499,7 @@ func PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var22 string
|
||||
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.filter_no_problems"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 107, Col: 81}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 113, Col: 81}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -505,7 +517,7 @@ func PublicStatusPage(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var23 string
|
||||
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.search_none"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 109, Col: 74}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 115, Col: 74}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -575,7 +587,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var25 string
|
||||
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.subscribe.title"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 125, Col: 112}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 131, Col: 112}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -588,7 +600,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var26 string
|
||||
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.subscribe.intro"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 126, Col: 63}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 132, Col: 63}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -601,7 +613,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var27 string
|
||||
templ_7745c5c3_Var27, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(a.ComponentBase + "subscribe")).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 127, Col: 75}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 133, Col: 75}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var27)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -614,7 +626,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var28 string
|
||||
templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.subscribe.email"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 129, Col: 86}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 135, Col: 86}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -627,7 +639,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var29 string
|
||||
templ_7745c5c3_Var29, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "page.subscribe.email")).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 130, Col: 153}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 136, Col: 153}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var29)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -640,7 +652,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var30 string
|
||||
templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.subscribe.submit"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 131, Col: 140}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 137, Col: 140}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -658,7 +670,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var31 string
|
||||
templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, ConsentLabelID(consent)))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 137, Col: 44}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 143, Col: 44}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -682,7 +694,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var32 string
|
||||
templ_7745c5c3_Var32, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(l.Href)).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 142, Col: 38}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 148, Col: 38}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var32)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -695,7 +707,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var33 string
|
||||
templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, LegalTitleID(l.Kind)))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 142, Col: 144}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 148, Col: 144}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -718,7 +730,7 @@ func publicSubscribe(s agentapi.PageSnapshot, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var34 string
|
||||
templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.subscribe.privacy"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 148, Col: 76}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 154, Col: 76}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -770,7 +782,7 @@ func PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message st
|
||||
var templ_7745c5c3_Var37 string
|
||||
templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(s.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 157, Col: 57}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 163, Col: 57}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -783,7 +795,7 @@ func PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message st
|
||||
var templ_7745c5c3_Var38 string
|
||||
templ_7745c5c3_Var38, templ_7745c5c3_Err = templ.JoinStringErrs(title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 158, Col: 86}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 164, Col: 86}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var38))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -796,7 +808,7 @@ func PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message st
|
||||
var templ_7745c5c3_Var39 string
|
||||
templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(message)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 160, Col: 36}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 166, Col: 36}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -814,7 +826,7 @@ func PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message st
|
||||
var templ_7745c5c3_Var40 string
|
||||
templ_7745c5c3_Var40, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(form.Action)).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 162, Col: 58}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 168, Col: 58}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var40)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -827,7 +839,7 @@ func PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message st
|
||||
var templ_7745c5c3_Var41 string
|
||||
templ_7745c5c3_Var41, templ_7745c5c3_Err = templruntime.NewAttributeExpression(form.Token).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 163, Col: 56}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 169, Col: 56}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var41)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -840,7 +852,7 @@ func PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message st
|
||||
var templ_7745c5c3_Var42 string
|
||||
templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(form.Button)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 164, Col: 115}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 170, Col: 115}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var42))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -858,7 +870,7 @@ func PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message st
|
||||
var templ_7745c5c3_Var43 string
|
||||
templ_7745c5c3_Var43, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(a.ComponentBase)).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 167, Col: 67}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 173, Col: 67}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var43)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -871,7 +883,7 @@ func PublicNoticePage(s agentapi.PageSnapshot, a PublicAssets, title, message st
|
||||
var templ_7745c5c3_Var44 string
|
||||
templ_7745c5c3_Var44, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.back"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 167, Col: 133}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 173, Col: 133}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var44))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -917,7 +929,7 @@ func publicComponentFilter(v ComponentView, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var46 string
|
||||
templ_7745c5c3_Var46, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(BackHref(a.ComponentBase))).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 174, Col: 69}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 180, Col: 69}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var46)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -930,7 +942,7 @@ func publicComponentFilter(v ComponentView, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var47 string
|
||||
templ_7745c5c3_Var47, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.search"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 175, Col: 76}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 181, Col: 76}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var47))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -943,7 +955,7 @@ func publicComponentFilter(v ComponentView, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var48 string
|
||||
templ_7745c5c3_Var48, templ_7745c5c3_Err = templruntime.NewAttributeExpression(v.Query).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 176, Col: 69}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 182, Col: 69}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var48)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -956,7 +968,7 @@ func publicComponentFilter(v ComponentView, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var49 string
|
||||
templ_7745c5c3_Var49, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "page.search")).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 176, Col: 128}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 182, Col: 128}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var49)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -979,7 +991,7 @@ func publicComponentFilter(v ComponentView, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var50 string
|
||||
templ_7745c5c3_Var50, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.filter_problems", "Count", v.Problems))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 179, Col: 67}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 185, Col: 67}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var50))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -992,7 +1004,7 @@ func publicComponentFilter(v ComponentView, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var51 string
|
||||
templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.search_submit"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 181, Col: 127}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 187, Col: 127}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var51))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1010,7 +1022,7 @@ func publicComponentFilter(v ComponentView, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var52 string
|
||||
templ_7745c5c3_Var52, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(v.ResetHref())).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 183, Col: 41}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 189, Col: 41}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var52)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1023,7 +1035,7 @@ func publicComponentFilter(v ComponentView, a PublicAssets) templ.Component {
|
||||
var templ_7745c5c3_Var53 string
|
||||
templ_7745c5c3_Var53, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.search_clear"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 183, Col: 112}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 189, Col: 112}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var53))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1068,7 +1080,7 @@ func publicSectionPager(sec PublicSection, v ComponentView) templ.Component {
|
||||
var templ_7745c5c3_Var55 string
|
||||
templ_7745c5c3_Var55, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "pager.label")).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 191, Col: 132}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 197, Col: 132}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var55)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1086,7 +1098,7 @@ func publicSectionPager(sec PublicSection, v ComponentView) templ.Component {
|
||||
var templ_7745c5c3_Var56 string
|
||||
templ_7745c5c3_Var56, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(v.PageHref(sec.Key, sec.Page-1))).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 193, Col: 60}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 199, Col: 60}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var56)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1099,7 +1111,7 @@ func publicSectionPager(sec PublicSection, v ComponentView) templ.Component {
|
||||
var templ_7745c5c3_Var57 string
|
||||
templ_7745c5c3_Var57, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pager.previous"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 193, Col: 143}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 199, Col: 143}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var57))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1117,7 +1129,7 @@ func publicSectionPager(sec PublicSection, v ComponentView) templ.Component {
|
||||
var templ_7745c5c3_Var58 string
|
||||
templ_7745c5c3_Var58, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.pages", "Page", sec.Page+1, "Pages", sec.Pages))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 195, Col: 113}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 201, Col: 113}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var58))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1135,7 +1147,7 @@ func publicSectionPager(sec PublicSection, v ComponentView) templ.Component {
|
||||
var templ_7745c5c3_Var59 string
|
||||
templ_7745c5c3_Var59, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(v.PageHref(sec.Key, sec.Page+1))).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 197, Col: 60}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 203, Col: 60}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var59)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1148,7 +1160,7 @@ func publicSectionPager(sec PublicSection, v ComponentView) templ.Component {
|
||||
var templ_7745c5c3_Var60 string
|
||||
templ_7745c5c3_Var60, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pager.next"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 197, Col: 143}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 203, Col: 143}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var60))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1195,7 +1207,7 @@ func publicSection(sec PublicSection, v ComponentView, s agentapi.PageSnapshot,
|
||||
var templ_7745c5c3_Var62 string
|
||||
templ_7745c5c3_Var62, templ_7745c5c3_Err = templruntime.NewAttributeExpression("g-" + sec.Key).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 207, Col: 26}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 213, Col: 26}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var62)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1225,7 +1237,7 @@ func publicSection(sec PublicSection, v ComponentView, s agentapi.PageSnapshot,
|
||||
var templ_7745c5c3_Var63 string
|
||||
templ_7745c5c3_Var63, templ_7745c5c3_Err = templruntime.NewAttributeExpression("g-" + sec.Key).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 212, Col: 35}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 218, Col: 35}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var63)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1246,7 +1258,7 @@ func publicSection(sec PublicSection, v ComponentView, s agentapi.PageSnapshot,
|
||||
var templ_7745c5c3_Var64 string
|
||||
templ_7745c5c3_Var64, templ_7745c5c3_Err = templ.JoinStringErrs(sec.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 215, Col: 20}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 221, Col: 20}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var64))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1259,7 +1271,7 @@ func publicSection(sec PublicSection, v ComponentView, s agentapi.PageSnapshot,
|
||||
var templ_7745c5c3_Var65 string
|
||||
templ_7745c5c3_Var65, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(sec.Total))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 216, Col: 84}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 222, Col: 84}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var65))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1272,7 +1284,7 @@ func publicSection(sec PublicSection, v ComponentView, s agentapi.PageSnapshot,
|
||||
var templ_7745c5c3_Var66 string
|
||||
templ_7745c5c3_Var66, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.component."+sec.Status))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 217, Col: 100}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 223, Col: 100}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var66))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1351,7 +1363,7 @@ func publicComponentList(comps []agentapi.Component, s agentapi.PageSnapshot, a
|
||||
var templ_7745c5c3_Var68 string
|
||||
templ_7745c5c3_Var68, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(href)).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 247, Col: 35}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 253, Col: 35}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var68)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1382,7 +1394,7 @@ func publicComponentList(comps []agentapi.Component, s agentapi.PageSnapshot, a
|
||||
var templ_7745c5c3_Var69 string
|
||||
templ_7745c5c3_Var69, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.details_expand"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 254, Col: 102}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 260, Col: 102}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var69))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1490,7 +1502,7 @@ func publicComponentBody(comp agentapi.Component, s agentapi.PageSnapshot, click
|
||||
var templ_7745c5c3_Var73 string
|
||||
templ_7745c5c3_Var73, templ_7745c5c3_Err = templ.JoinStringErrs(comp.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 273, Col: 87}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 279, Col: 87}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var73))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1521,7 +1533,7 @@ func publicComponentBody(comp agentapi.Component, s agentapi.PageSnapshot, click
|
||||
var templ_7745c5c3_Var74 string
|
||||
templ_7745c5c3_Var74, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.component."+comp.Status))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 281, Col: 53}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 287, Col: 53}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var74))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1563,7 +1575,7 @@ func publicComponentBody(comp agentapi.Component, s agentapi.PageSnapshot, click
|
||||
var templ_7745c5c3_Var75 string
|
||||
templ_7745c5c3_Var75, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 294, Col: 63}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 300, Col: 63}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var75))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1576,7 +1588,7 @@ func publicComponentBody(comp agentapi.Component, s agentapi.PageSnapshot, click
|
||||
var templ_7745c5c3_Var76 string
|
||||
templ_7745c5c3_Var76, templ_7745c5c3_Err = templ.JoinStringErrs(UptimeText(comp.Uptime))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 295, Col: 33}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 301, Col: 33}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var76))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1589,7 +1601,7 @@ func publicComponentBody(comp agentapi.Component, s agentapi.PageSnapshot, click
|
||||
var templ_7745c5c3_Var77 string
|
||||
templ_7745c5c3_Var77, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.today"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 296, Col: 35}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 302, Col: 35}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var77))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1639,7 +1651,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var80 string
|
||||
templ_7745c5c3_Var80, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(BackHref(a.ComponentBase))).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 303, Col: 53}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 309, Col: 53}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var80)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1652,7 +1664,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var81 string
|
||||
templ_7745c5c3_Var81, templ_7745c5c3_Err = templ.JoinStringErrs(s.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 303, Col: 103}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 309, Col: 103}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var81))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1673,7 +1685,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var82 string
|
||||
templ_7745c5c3_Var82, templ_7745c5c3_Err = templ.JoinStringErrs(comp.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 308, Col: 21}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 314, Col: 21}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var82))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1735,7 +1747,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var85 string
|
||||
templ_7745c5c3_Var85, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.component."+comp.Status))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 320, Col: 80}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 326, Col: 80}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var85))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1758,7 +1770,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var86 string
|
||||
templ_7745c5c3_Var86, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.details_last_24h"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 327, Col: 111}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 333, Col: 111}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var86))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1771,7 +1783,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var87 string
|
||||
templ_7745c5c3_Var87, templ_7745c5c3_Err = templ.JoinStringErrs(UptimeText(comp.Details.SLA24h))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 328, Col: 70}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 334, Col: 70}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var87))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1794,7 +1806,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var88 string
|
||||
templ_7745c5c3_Var88, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.latency"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 334, Col: 45}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 340, Col: 45}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var88))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1807,7 +1819,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var89 string
|
||||
templ_7745c5c3_Var89, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.details_latency_summary", "Avg", AvgLatencyText(comp.Details.Hours), "Max", strconv.Itoa(lat.MaxMS)+" ms"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 335, Col: 138}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 341, Col: 138}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var89))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1820,7 +1832,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var90 string
|
||||
templ_7745c5c3_Var90, templ_7745c5c3_Err = templruntime.NewAttributeExpression("0 0 " + strconv.Itoa(lat.Width) + " " + strconv.Itoa(lat.Height)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 337, Col: 85}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 343, Col: 85}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var90)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1833,7 +1845,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var91 string
|
||||
templ_7745c5c3_Var91, templ_7745c5c3_Err = templruntime.NewAttributeExpression(lat.Points).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 338, Col: 35}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 344, Col: 35}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var91)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1851,7 +1863,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var92 string
|
||||
templ_7745c5c3_Var92, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.sla_table"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 343, Col: 112}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 349, Col: 112}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var92))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1877,7 +1889,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var93 string
|
||||
templ_7745c5c3_Var93, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.regions"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 348, Col: 111}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 354, Col: 111}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var93))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1904,7 +1916,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var94 string
|
||||
templ_7745c5c3_Var94, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.last_90d"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 355, Col: 106}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 361, Col: 106}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var94))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1917,7 +1929,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var95 string
|
||||
templ_7745c5c3_Var95, templ_7745c5c3_Err = templ.JoinStringErrs(UptimeText(comp.Uptime))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 356, Col: 61}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 362, Col: 61}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var95))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1938,7 +1950,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var96 string
|
||||
templ_7745c5c3_Var96, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.days_ago", "Count", len(comp.Days)))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 360, Col: 65}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 366, Col: 65}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var96))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1951,7 +1963,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var97 string
|
||||
templ_7745c5c3_Var97, templ_7745c5c3_Err = templ.JoinStringErrs(UptimeText(comp.Uptime))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 361, Col: 35}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 367, Col: 35}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var97))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -1964,7 +1976,7 @@ func PublicComponentPage(s agentapi.PageSnapshot, comp agentapi.Component, a Pub
|
||||
var templ_7745c5c3_Var98 string
|
||||
templ_7745c5c3_Var98, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.today"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 362, Col: 37}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 368, Col: 37}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var98))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2029,7 +2041,7 @@ func publicSLAGrid(d *agentapi.ComponentDetails) templ.Component {
|
||||
var templ_7745c5c3_Var100 string
|
||||
templ_7745c5c3_Var100, templ_7745c5c3_Err = templ.JoinStringErrs(item.label)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 382, Col: 57}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 388, Col: 57}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var100))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2042,7 +2054,7 @@ func publicSLAGrid(d *agentapi.ComponentDetails) templ.Component {
|
||||
var templ_7745c5c3_Var101 string
|
||||
templ_7745c5c3_Var101, templ_7745c5c3_Err = templ.JoinStringErrs(UptimeText(item.value))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 383, Col: 58}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 389, Col: 58}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var101))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2098,7 +2110,7 @@ func publicRegionsList(regions []agentapi.ComponentRegion) templ.Component {
|
||||
var templ_7745c5c3_Var103 string
|
||||
templ_7745c5c3_Var103, templ_7745c5c3_Err = templ.JoinStringErrs(r.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 394, Col: 18}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 400, Col: 18}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var103))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2111,7 +2123,7 @@ func publicRegionsList(regions []agentapi.ComponentRegion) templ.Component {
|
||||
var templ_7745c5c3_Var104 string
|
||||
templ_7745c5c3_Var104, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.component."+r.Status))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 396, Col: 46}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 402, Col: 46}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var104))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2125,7 +2137,7 @@ func publicRegionsList(regions []agentapi.ComponentRegion) templ.Component {
|
||||
var templ_7745c5c3_Var105 string
|
||||
templ_7745c5c3_Var105, templ_7745c5c3_Err = templ.JoinStringErrs(" · " + strconv.Itoa(r.LatencyMS) + " ms")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 398, Col: 50}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 404, Col: 50}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var105))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2169,7 +2181,7 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
|
||||
var templ_7745c5c3_Var107 string
|
||||
templ_7745c5c3_Var107, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.incidents"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 408, Col: 106}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 414, Col: 106}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var107))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2187,7 +2199,7 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
|
||||
var templ_7745c5c3_Var108 string
|
||||
templ_7745c5c3_Var108, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.no_incidents"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 410, Col: 67}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 416, Col: 67}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var108))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2219,7 +2231,7 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
|
||||
var templ_7745c5c3_Var109 string
|
||||
templ_7745c5c3_Var109, templ_7745c5c3_Err = templ.JoinStringErrs(inc.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 418, Col: 45}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 424, Col: 45}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var109))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2232,7 +2244,7 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
|
||||
var templ_7745c5c3_Var110 string
|
||||
templ_7745c5c3_Var110, templ_7745c5c3_Err = templ.JoinStringErrs(inc.Component)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 419, Col: 56}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 425, Col: 56}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var110))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2250,7 +2262,7 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
|
||||
var templ_7745c5c3_Var111 string
|
||||
templ_7745c5c3_Var111, templ_7745c5c3_Err = templ.JoinStringErrs(inc.Component)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 421, Col: 29}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 427, Col: 29}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var111))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2268,7 +2280,7 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
|
||||
var templ_7745c5c3_Var112 string
|
||||
templ_7745c5c3_Var112, templ_7745c5c3_Err = templ.JoinStringErrs(inc.StartedAt.UTC().Format("2006-01-02 15:04"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 424, Col: 56}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 430, Col: 56}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var112))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2286,7 +2298,7 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
|
||||
var templ_7745c5c3_Var113 string
|
||||
templ_7745c5c3_Var113, templ_7745c5c3_Err = templ.JoinStringErrs(inc.ResolvedAt.UTC().Format("15:04"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 426, Col: 51}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 432, Col: 51}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var113))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2322,7 +2334,7 @@ func publicIncidents(incidents []agentapi.PageIncident) templ.Component {
|
||||
var templ_7745c5c3_Var114 string
|
||||
templ_7745c5c3_Var114, templ_7745c5c3_Err = templ.JoinStringErrs(" · " + u.At.UTC().Format("2006-01-02 15:04") + " UTC")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 437, Col: 103}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 443, Col: 103}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var114))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2393,7 +2405,7 @@ func incidentStatusLabel(st IncidentStatusInfo, open bool) templ.Component {
|
||||
var templ_7745c5c3_Var116 string
|
||||
templ_7745c5c3_Var116, templ_7745c5c3_Err = templruntime.SanitizeStyleAttributeValues("background-color:" + st.Color)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 460, Col: 89}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 466, Col: 89}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var116))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2406,7 +2418,7 @@ func incidentStatusLabel(st IncidentStatusInfo, open bool) templ.Component {
|
||||
var templ_7745c5c3_Var117 string
|
||||
templ_7745c5c3_Var117, templ_7745c5c3_Err = templ.JoinStringErrs(st.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 461, Col: 13}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 467, Col: 13}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var117))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2460,7 +2472,7 @@ func incidentStatusLabel(st IncidentStatusInfo, open bool) templ.Component {
|
||||
var templ_7745c5c3_Var120 string
|
||||
templ_7745c5c3_Var120, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incident.status."+st.Key))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 464, Col: 102}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 470, Col: 102}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var120))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2478,7 +2490,7 @@ func incidentStatusLabel(st IncidentStatusInfo, open bool) templ.Component {
|
||||
var templ_7745c5c3_Var121 string
|
||||
templ_7745c5c3_Var121, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incidents.ongoing"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 466, Col: 73}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 472, Col: 73}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var121))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2496,7 +2508,7 @@ func incidentStatusLabel(st IncidentStatusInfo, open bool) templ.Component {
|
||||
var templ_7745c5c3_Var122 string
|
||||
templ_7745c5c3_Var122, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "incidents.resolved"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 468, Col: 60}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 474, Col: 60}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var122))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2536,7 +2548,7 @@ func pageMaintenance(heading string, items []agentapi.PageMaintenance) templ.Com
|
||||
var templ_7745c5c3_Var124 string
|
||||
templ_7745c5c3_Var124, templ_7745c5c3_Err = templ.JoinStringErrs(heading)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 475, Col: 85}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 481, Col: 85}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var124))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2562,7 +2574,7 @@ func pageMaintenance(heading string, items []agentapi.PageMaintenance) templ.Com
|
||||
var templ_7745c5c3_Var125 string
|
||||
templ_7745c5c3_Var125, templ_7745c5c3_Err = templ.JoinStringErrs(m.Title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 482, Col: 17}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 488, Col: 17}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var125))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2575,7 +2587,7 @@ func pageMaintenance(heading string, items []agentapi.PageMaintenance) templ.Com
|
||||
var templ_7745c5c3_Var126 string
|
||||
templ_7745c5c3_Var126, templ_7745c5c3_Err = templ.JoinStringErrs(m.Start.UTC().Format("2006-01-02 15:04") + " – " + m.End.UTC().Format("15:04") + " UTC")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 485, Col: 99}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 491, Col: 99}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var126))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2588,7 +2600,7 @@ func pageMaintenance(heading string, items []agentapi.PageMaintenance) templ.Com
|
||||
var templ_7745c5c3_Var127 string
|
||||
templ_7745c5c3_Var127, templ_7745c5c3_Err = templ.JoinStringErrs(strings.Join(m.Components, ", "))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 488, Col: 80}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 494, Col: 80}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var127))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2652,7 +2664,7 @@ func PublicNotFoundPage(cssHref, home string) templ.Component {
|
||||
var templ_7745c5c3_Var129 string
|
||||
templ_7745c5c3_Var129, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.Lang(ctx)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 505, Col: 28}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 511, Col: 28}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var129)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2665,7 +2677,7 @@ func PublicNotFoundPage(cssHref, home string) templ.Component {
|
||||
var templ_7745c5c3_Var130 string
|
||||
templ_7745c5c3_Var130, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.not_found_title"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 510, Col: 47}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 516, Col: 47}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var130))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2686,7 +2698,7 @@ func PublicNotFoundPage(cssHref, home string) templ.Component {
|
||||
var templ_7745c5c3_Var131 string
|
||||
templ_7745c5c3_Var131, templ_7745c5c3_Err = templruntime.NewAttributeExpression(cssHref).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 512, Col: 40}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 518, Col: 40}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var131)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2699,7 +2711,7 @@ func PublicNotFoundPage(cssHref, home string) templ.Component {
|
||||
var templ_7745c5c3_Var132 string
|
||||
templ_7745c5c3_Var132, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.not_found_title"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 517, Col: 81}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 523, Col: 81}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var132))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2712,7 +2724,7 @@ func PublicNotFoundPage(cssHref, home string) templ.Component {
|
||||
var templ_7745c5c3_Var133 string
|
||||
templ_7745c5c3_Var133, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.not_found"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 518, Col: 62}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 524, Col: 62}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var133))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2730,7 +2742,7 @@ func PublicNotFoundPage(cssHref, home string) templ.Component {
|
||||
var templ_7745c5c3_Var134 string
|
||||
templ_7745c5c3_Var134, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(home)).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 521, Col: 35}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 527, Col: 35}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var134)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -2743,7 +2755,7 @@ func PublicNotFoundPage(cssHref, home string) templ.Component {
|
||||
var templ_7745c5c3_Var135 string
|
||||
templ_7745c5c3_Var135, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "page.not_found_home"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 521, Col: 161}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/public.templ`, Line: 527, Col: 161}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var135))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"time"
|
||||
)
|
||||
|
||||
type sitemapLink struct {
|
||||
Rel string `xml:"rel,attr"`
|
||||
Hreflang string `xml:"hreflang,attr"`
|
||||
Href string `xml:"href,attr"`
|
||||
}
|
||||
|
||||
type sitemapURL struct {
|
||||
Loc string `xml:"loc"`
|
||||
LastMod string `xml:"lastmod,omitempty"`
|
||||
Links []sitemapLink `xml:"xhtml:link"`
|
||||
}
|
||||
|
||||
type sitemap struct {
|
||||
XMLName xml.Name `xml:"urlset"`
|
||||
NS string `xml:"xmlns,attr"`
|
||||
XHTML string `xml:"xmlns:xhtml,attr"`
|
||||
URLs []sitemapURL `xml:"url"`
|
||||
}
|
||||
|
||||
// Sitemap lists pages with each of their language versions, as NewPageMeta
|
||||
// names them; lastMod may be zero.
|
||||
func Sitemap(pages, langs []string, lastMod time.Time) ([]byte, error) {
|
||||
sm := sitemap{NS: "http://www.sitemaps.org/schemas/sitemap/0.9", XHTML: "http://www.w3.org/1999/xhtml"}
|
||||
mod := ""
|
||||
if !lastMod.IsZero() {
|
||||
mod = lastMod.UTC().Format(time.RFC3339)
|
||||
}
|
||||
for _, page := range pages {
|
||||
m := NewPageMeta("", "", page, "", "", "", false, langs)
|
||||
links := make([]sitemapLink, len(m.Alternates))
|
||||
for i, a := range m.Alternates {
|
||||
links[i] = sitemapLink{Rel: "alternate", Hreflang: a.Lang, Href: a.URL}
|
||||
}
|
||||
for _, a := range m.Alternates {
|
||||
sm.URLs = append(sm.URLs, sitemapURL{Loc: a.URL, LastMod: mod, Links: links})
|
||||
}
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString(xml.Header)
|
||||
enc := xml.NewEncoder(&buf)
|
||||
enc.Indent("", " ")
|
||||
if err := enc.Encode(sm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buf.WriteString("\n")
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<!doctype html><html><body data-msg-network="net">
|
||||
<form id="monitor"><fieldset>
|
||||
<p><span data-region-count></span></p>
|
||||
<div id="monitor-regions" data-region-limit="2">
|
||||
<label><input type="checkbox" name="regions" value="own" data-multi checked></label>
|
||||
<label><input type="checkbox" name="regions" value="a" data-multi data-counted checked></label>
|
||||
<label><input type="checkbox" name="regions" value="b" data-multi data-counted></label>
|
||||
<label><input type="checkbox" name="regions" value="c" data-multi data-counted></label>
|
||||
</div>
|
||||
</fieldset></form>
|
||||
<pre id="out"></pre>
|
||||
<script>window.axios = { create: () => ({ interceptors: { request: { use() {} } }, request: async () => ({ data: {} }) }) };</script>
|
||||
<script src="../assets/app.js"></script>
|
||||
<script>
|
||||
(async () => {
|
||||
const out = [];
|
||||
const check = (name, got, want) => {
|
||||
const g = JSON.stringify(got), w = JSON.stringify(want);
|
||||
out.push((g === w ? "PASS " : "FAIL ") + name + (g === w ? "" : " got=" + g + " want=" + w));
|
||||
};
|
||||
const box = (v) => document.querySelector(`[value="${v}"]`);
|
||||
const locked = () => ["own", "a", "b", "c"].filter((v) => box(v).disabled);
|
||||
const count = () => document.querySelector("[data-region-count]").textContent;
|
||||
check("below the limit nothing is locked", locked(), []);
|
||||
check("count shown", count(), "(1/2)");
|
||||
box("b").click();
|
||||
check("at the limit the other counted regions lock", locked(), ["c"]);
|
||||
check("locked row marked", box("c").closest("label").classList.contains("is-locked"), true);
|
||||
check("count follows", count(), "(2/2)");
|
||||
box("c").click();
|
||||
check("a locked region cannot be ticked", box("c").checked, false);
|
||||
box("own").click();
|
||||
box("own").click();
|
||||
check("uncounted regions stay free", box("own").checked, true);
|
||||
box("a").click();
|
||||
check("unticking frees them again", locked(), []);
|
||||
document.getElementById("out").textContent = out.join("\n");
|
||||
})();
|
||||
</script>
|
||||
</body></html>
|
||||
Vendored
+14
-1
@@ -20,6 +20,12 @@
|
||||
<input name="latitude" data-number data-nullable data-location-field="latitude">
|
||||
<input name="longitude" data-number data-nullable data-location-field="longitude">
|
||||
</div></form>
|
||||
<div id="near-map" data-region-map="edit" data-region-items="#near" data-map-server="stub" data-touch-hint="t" data-scroll-hint="{key} s" data-ctrl-key="Ctrl" hidden style="width:300px;height:200px;position:relative"></div>
|
||||
<table><tbody id="near">
|
||||
<tr data-lat="50" data-lon="8" data-name="Nuremberg" data-live="1"><td></td></tr>
|
||||
<tr data-lat="50.05" data-lon="8.5" data-name="Bamberg" data-live="1"><td></td></tr>
|
||||
<tr data-lat="55" data-lon="19" data-name="Gdansk" data-live="1"><td></td></tr>
|
||||
</tbody></table>
|
||||
<pre id="out"></pre>
|
||||
<script>
|
||||
const sent = [];
|
||||
@@ -35,11 +41,13 @@ window.maplibregl = {
|
||||
fitBounds(b) { this.bounds = b.points; }
|
||||
jumpTo(o) { this.center = o.center; }
|
||||
setStyle(s) { this.style = s; }
|
||||
// 10 px per degree, 8°E 50°N at the middle of the box.
|
||||
project({ lng, lat }) { return { x: 100 + (lng - 0) * 10, y: 100 - (lat - 50) * 10 }; }
|
||||
},
|
||||
Marker: class {
|
||||
constructor(o) { this.el = o.element; }
|
||||
setLngLat(p) { this.at = p; this.el.dataset.at = p.join(","); return this; }
|
||||
getLngLat() { return this.at; }
|
||||
getLngLat() { return { lng: this.at[0], lat: this.at[1] }; }
|
||||
addTo(map) { map.container.append(this.el); return this; }
|
||||
},
|
||||
NavigationControl: class {},
|
||||
@@ -100,6 +108,11 @@ window.maplibregl = {
|
||||
click(1, 2);
|
||||
check("closed row falls back to create form", create.elements.latitude.value, "1");
|
||||
|
||||
const near = maps[2];
|
||||
near.fire("load");
|
||||
const placement = () => [...near.container.querySelectorAll(".region-pin")].map((p) => [p.title, p.parentElement.classList.contains("is-flipped") ? "left" : p.parentElement.classList.contains("is-compact") ? "dot" : "right"]);
|
||||
check("close labels make room", placement(), [["Nuremberg", "dot"], ["Bamberg", "right"], ["Gdansk", "left"]]);
|
||||
|
||||
document.getElementById("out").textContent = out.join("\n");
|
||||
})();
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user