feat(api): count queued runs as overdue; alert rules in the chart
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m57s
ci / test (pull_request) Successful in 13m1s
ci / build (pull_request) Successful in 19m25s
ci / image (pull_request) In progress
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m57s
ci / test (pull_request) Successful in 13m1s
ci / build (pull_request) Successful in 19m25s
ci / image (pull_request) In progress
uptimesebi_checks_overdue counted only runs not dispatched yet. Dispatch hands due runs to an instance's queue and schedules the next run at once, so a checker too busy to take its work left the metric at 0. It now also counts queued runs due more than 10 seconds ago. The chart adds an optional PrometheusRule (api.metrics.prometheusRule): UptimeSebiRegionBehind fires when a region's checks stay overdue, and UptimeSebiPlatformMetricsFailing when the platform metrics cannot be read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
e776143ee0
commit
2fa439c47d
6 files changed
+84
-8
No files matched your search
@@ -152,7 +152,7 @@ helm install uptime uptimesebi/uptimesebi -n uptime --create-namespace \
|
||||
--set ingress.enabled=true --set ingress.tls.enabled=true
|
||||
```
|
||||
|
||||
The API pods serve metrics on port 9090 (`api.metrics`); `--set api.metrics.serviceMonitor.enabled=true` adds a ServiceMonitor for the Prometheus Operator. 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:
|
||||
|
||||
|
||||
@@ -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 }}
|
||||
@@ -137,6 +137,17 @@ api:
|
||||
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:
|
||||
|
||||
@@ -26,7 +26,7 @@ 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, as when no checker of the region is live.", []string{"region"}, nil)
|
||||
"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",
|
||||
|
||||
@@ -332,11 +332,29 @@ func (s *Scheduler) Instances(ctx context.Context, region string) (int64, error)
|
||||
return s.rdb.ZCount(ctx, keyInstances(region), min, "+inf").Result()
|
||||
}
|
||||
|
||||
// Overdue returns how many monitors of region should have been dispatched
|
||||
// more than late ago, as when the region has no live instance.
|
||||
// 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.sub(job, string.find(job, '|', 1, true) + 1))
|
||||
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) {
|
||||
max := strconv.FormatInt(s.now().Add(-late).UnixMilli(), 10)
|
||||
return s.rdb.ZCount(ctx, keyDue(region), "-inf", max).Result()
|
||||
return overdueScript.Run(ctx, s.rdb, []string{keyDue(region), keyInstances(region)},
|
||||
s.now().Add(-late).UnixMilli(), jobsPrefix).Int64()
|
||||
}
|
||||
|
||||
func parseEntry(s string) (Entry, bool) {
|
||||
|
||||
@@ -263,9 +263,17 @@ func TestOverdueCountsRunsLeftBehind(t *testing.T) {
|
||||
if n := overdue(); n != 2 {
|
||||
t.Errorf("Overdue() without instances = %d, want 2", n)
|
||||
}
|
||||
_ = s.Heartbeat(ctx, "eu", uuid.New())
|
||||
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 dispatch = %d, want 0", n)
|
||||
t.Errorf("Overdue() after the instance took the runs = %d, want 0", n)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user