Skip to content

Commit

Permalink
Extend Replication status report
Browse files Browse the repository at this point in the history
Now it shows "Interval" and "Sleep until":

Replication:
   Interval: 35 15-22 * * *
   Sleep until: 2024-04-28 22:35:00 +0200 CEST (29m3s remaining)
   ...
  • Loading branch information
dsh2dsh committed Apr 28, 2024
1 parent ea9ba81 commit 34b0d46
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
12 changes: 12 additions & 0 deletions client/status/viewmodel/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ func drawJob(t *stringbuilder.B, name string, v *job.Status, history *bytesProgr

t.Printf("Replication:")
t.AddIndentAndNewline(1)

if cronSpec := activeStatus.CronSpec; cronSpec != "" {
t.Printf("Interval: %s\n", cronSpec)
}
if err := activeStatus.Error; err != nil {
t.Printf("Error: %s", err)
}
if sleepUntil := activeStatus.SleepUntil; !sleepUntil.IsZero() {
t.Printf("Sleep until: %s (%s remaining)\n",
sleepUntil, time.Until(sleepUntil).Truncate(time.Second))
}

renderReplicationReport(t, activeStatus.Replication, history, fsfilter)
t.AddIndentAndNewline(-1)

Expand Down
38 changes: 30 additions & 8 deletions daemon/job/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/robfig/cron/v3"

"github.com/zrepl/zrepl/daemon/logging/trace"
"github.com/zrepl/zrepl/util/envconst"

"github.com/zrepl/zrepl/config"
"github.com/zrepl/zrepl/daemon/job/reset"
"github.com/zrepl/zrepl/daemon/job/wakeup"
"github.com/zrepl/zrepl/daemon/logging/trace"
"github.com/zrepl/zrepl/daemon/pruner"
"github.com/zrepl/zrepl/daemon/snapper"
"github.com/zrepl/zrepl/endpoint"
Expand All @@ -25,6 +23,7 @@ import (
"github.com/zrepl/zrepl/rpc"
"github.com/zrepl/zrepl/transport"
"github.com/zrepl/zrepl/transport/fromconfig"
"github.com/zrepl/zrepl/util/envconst"
"github.com/zrepl/zrepl/zfs"
)

Expand All @@ -45,6 +44,10 @@ type ActiveSide struct {

tasksMtx sync.Mutex
tasks activeSideTasks

cron *cron.Cron
cronId cron.EntryID
wakeupBusy int
}

//go:generate enumer -type=ActiveSideState
Expand Down Expand Up @@ -392,16 +395,31 @@ func (j *ActiveSide) RegisterMetrics(registerer prometheus.Registerer) {
func (j *ActiveSide) Name() string { return j.name.String() }

type ActiveSideStatus struct {
CronSpec string
SleepUntil time.Time
Error error

Replication *report.Report
PruningSender, PruningReceiver *pruner.Report
Snapshotting *snapper.Report
}

func (j *ActiveSide) Status() *Status {
tasks := j.updateTasks(nil)
s := &ActiveSideStatus{
CronSpec: j.mode.Cron(),
Snapshotting: j.mode.SnapperReport(),
}

if id := j.cronId; id > 0 {
s.SleepUntil = j.cron.Entry(id).Next
}

if cnt := j.wakeupBusy; cnt > 0 {
s.Error = fmt.Errorf(
"job frequency is too high; replication was not done %d times", cnt)
}

s := &ActiveSideStatus{}
t := j.mode.Type()
if tasks.replicationReport != nil {
s.Replication = tasks.replicationReport()
}
Expand All @@ -411,8 +429,9 @@ func (j *ActiveSide) Status() *Status {
if tasks.prunerReceiver != nil {
s.PruningReceiver = tasks.prunerReceiver.Report()
}

s.Snapshotting = j.mode.SnapperReport()
return &Status{Type: t, JobSpecific: s}
return &Status{Type: j.mode.Type(), JobSpecific: s}
}

func (j *ActiveSide) OwnedDatasetSubtreeRoot() (rfs *zfs.DatasetPath, ok bool) {
Expand Down Expand Up @@ -489,11 +508,13 @@ func (j *ActiveSide) runPeriodic(ctx context.Context,
}

log := GetLogger(ctx).WithField("cron", cronSpec)
_, err := cron.AddFunc(cronSpec, func() {
id, err := cron.AddFunc(cronSpec, func() {
select {
case wakeUpCommon <- struct{}{}:
j.wakeupBusy = 0
case <-ctx.Done():
default:
j.wakeupBusy++
log.WithField("cron", cronSpec).Warn(
"job took longer than its interval")
}
Expand All @@ -503,7 +524,8 @@ func (j *ActiveSide) runPeriodic(ctx context.Context,
return
}

log.Info("add cron job")
j.cron, j.cronId = cron, id
log.WithField("id", id).Info("add cron job")
}

func (j *ActiveSide) do(ctx context.Context) {
Expand Down

0 comments on commit 34b0d46

Please sign in to comment.