v3.5.0 8345e76

backup_metrics_wiring.go RawHistoryFolder

1package app
2
3import (
4	"context"
5	"time"
6
7	"github.com/bnema/zerowrap"
8
9	"github.com/bnema/gordon/internal/adapters/out/telemetry"
10	"github.com/bnema/gordon/internal/domain"
11	cronSvc "github.com/bnema/gordon/internal/usecase/cron"
12)
13
14// nextRunObserver exports the next planned run of one backup kind.
15type nextRunObserver interface {
16	ObserveBackupNextRun(kind domain.BackupKind, next func() time.Time)
17}
18
19// nextRunObserverPort converts a possibly nil metrics adapter into an
20// interface that is nil when metrics are disabled. A typed nil must not
21// leak into the interface.
22func nextRunObserverPort(metrics *telemetry.Metrics) nextRunObserver {
23	if metrics == nil {
24		return nil
25	}
26	return metrics
27}
28
29// wireBackupMetrics injects backup metrics into the backup services. It
30// must run before any backup can start, so no run reads the field while
31// it is written.
32func wireBackupMetrics(svc *services) {
33	if svc == nil || svc.metrics == nil {
34		return
35	}
36	if svc.backupSvc != nil {
37		svc.backupSvc.WithMetrics(svc.metrics)
38	}
39	if svc.volumeBackupSvc != nil {
40		svc.volumeBackupSvc.WithMetrics(svc.metrics)
41	}
42}
43
44// seedBackupMetrics reports the last success of every target from
45// storage, so the metric is correct right after a restart. It only feeds
46// the metrics state (mutex-guarded), so it may run alongside backups.
47// Failures are logged, never fatal.
48func seedBackupMetrics(ctx context.Context, svc *services, log zerowrap.Logger) {
49	if svc == nil || svc.metrics == nil {
50		return
51	}
52	if svc.backupSvc != nil {
53		if err := svc.backupSvc.SeedMetrics(ctx); err != nil {
54			log.Warn().Err(err).Msg("failed to seed database backup metrics")
55		}
56	}
57	if svc.volumeBackupSvc != nil {
58		if err := svc.volumeBackupSvc.SeedMetrics(ctx); err != nil {
59			log.Warn().Err(err).Msg("failed to seed volume backup metrics")
60		}
61	}
62}
63
64// observeSchedulerNextRun exports the scheduler entry's next run, read at
65// each metrics collection.
66func observeSchedulerNextRun(obs nextRunObserver, kind domain.BackupKind, scheduler *cronSvc.Scheduler, id string) {
67	if obs == nil || scheduler == nil {
68		return
69	}
70	obs.ObserveBackupNextRun(kind, func() time.Time { return nextRunOf(scheduler, id) })
71}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close