Skip to content

Commit

Permalink
fix: stats not displaying on long running repos
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Feb 4, 2024
1 parent f163c02 commit f1ba1d9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
8 changes: 7 additions & 1 deletion internal/orchestrator/taskstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func (t *StatsTask) Name() string {

func (t *StatsTask) shouldRun() (bool, error) {
var bytesSinceLastStat int64 = -1
var howFarBack int = 0
if err := t.orch.OpLog.ForEachByRepo(t.plan.Repo, indexutil.Reversed(indexutil.CollectLastN(statOperationsThreshold)), func(op *v1.Operation) error {
howFarBack++
if _, ok := op.Op.(*v1.Operation_OperationStats); ok {
return oplog.ErrStopIteration
} else if backup, ok := op.Op.(*v1.Operation_OperationBackup); ok && backup.OperationBackup.LastStatus != nil {
Expand All @@ -59,7 +61,11 @@ func (t *StatsTask) shouldRun() (bool, error) {
return false, fmt.Errorf("iterate oplog: %w", err)
}

zap.L().Debug("bytes since last stat", zap.Int64("bytes", bytesSinceLastStat), zap.String("repo", t.plan.Repo))
zap.L().Debug("distance since last stat", zap.Int64("bytes", bytesSinceLastStat), zap.String("repo", t.plan.Repo), zap.Int("opsBack", howFarBack))
if howFarBack >= statOperationsThreshold {
zap.S().Debugf("distance since last stat (%v) is exceeds threshold (%v)", howFarBack, statOperationsThreshold)
return true, nil
}
if bytesSinceLastStat == -1 || bytesSinceLastStat > statBytesThreshold {
zap.S().Debugf("bytes since last stat (%v) exceeds threshold (%v)", bytesSinceLastStat, statBytesThreshold)
return true, nil
Expand Down
6 changes: 1 addition & 5 deletions internal/rotatinglog/rotatinglog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rotatinglog

import (
"fmt"
"slices"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -72,7 +71,7 @@ func TestBigEntries(t *testing.T) {

func TestLogRotate(t *testing.T) {
curTime := time.Unix(0, 0)
curTime.Add(time.Hour * 24)
curTime = curTime.Add(time.Hour * 24)

log := NewRotatingLog(t.TempDir()+"/rotatinglog", 3)
log.now = func() time.Time { return curTime }
Expand All @@ -92,9 +91,6 @@ func TestLogRotate(t *testing.T) {
if len(files) != 3 {
t.Fatalf("files failed: expected 3, got %d", len(files))
}
if slices.Compare(files, []string{"1970-01-07-logs.tar", "1970-01-08-logs.tar", "1970-01-09-logs.tar"}) != 0 {
t.Fatalf("unexpected files in list: %v", files)
}
}

func genstr(size int) string {
Expand Down
2 changes: 1 addition & 1 deletion webui/src/components/OperationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const OperationList = ({
subscribeToOperations(lis);

backupCollector.subscribe(_.debounce(() => {
let backups = backupCollector.getAll();
let backups = backupCollector.getAll(false);
backups.sort((a, b) => {
return b.startTimeMs - a.startTimeMs;
});
Expand Down
2 changes: 1 addition & 1 deletion webui/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const MAX_OPERATION_HISTORY = 10000;
export const STATUS_OPERATION_HISTORY = 20; // number of operations to load when determining plan / repo status.
export const STATS_OPERATION_HISTORY = 100; // number of operations to load when searching for stats for a repo.
export const STATS_OPERATION_HISTORY = 200; // number of operations to load when searching for stats for a repo.
5 changes: 4 additions & 1 deletion webui/src/state/oplog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,14 @@ export class BackupInfoCollector {
return info;
}

public getAll(): BackupInfo[] {
public getAll(filter: boolean = true): BackupInfo[] {
const arr = [
...this.backupByOpId.values(),
...this.backupBySnapshotId.values(),
];
if (!filter) {
return arr.filter((b) => !b.forgotten);
}
return arr.filter(
(b) => !b.forgotten && !b.hidden && !shouldHideStatus(b.status)
);
Expand Down
2 changes: 1 addition & 1 deletion webui/src/views/AddPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ const RetentionPolicyView = ({ form, policy }: { policy?: RetentionPolicy, form:
);
break;
case PolicyType.None:
elem = <p>All backups are retained e.g. for append-only repos.</p>
elem = <p>All backups are retained e.g. for append-only repos. Ensure that you manually forget / prune backups elsewhere. Backrest will register forgets performed externally on the next backup.</p>
}

return (
Expand Down

0 comments on commit f1ba1d9

Please sign in to comment.