Skip to content

Commit

Permalink
fix: stats operations running at wrong interval
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Feb 15, 2024
1 parent 79f529f commit 05e5ae0
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 133 deletions.
249 changes: 129 additions & 120 deletions gen/go/v1/service.pb.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions internal/api/backresthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ func (s *BackrestHandler) Cancel(ctx context.Context, req *connect.Request[types
func (s *BackrestHandler) ClearHistory(ctx context.Context, req *connect.Request[v1.ClearHistoryRequest]) (*connect.Response[emptypb.Empty], error) {
var err error
var ids []int64

if len(req.Msg.Ops) != 0 {
ids = append(ids, req.Msg.Ops...)
}

opCollector := func(op *v1.Operation) error {
if !req.Msg.OnlyFailed || op.Status == v1.OperationStatus_STATUS_ERROR {
ids = append(ids, op.Id)
Expand Down
2 changes: 1 addition & 1 deletion internal/orchestrator/taskbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func backupHelper(ctx context.Context, t Task, orchestrator *Orchestrator, plan
return fmt.Errorf("expected a final backup progress entry, got nil")
}

zap.L().Info("Backup complete", zap.String("plan", plan.Id), zap.Duration("duration", time.Since(startTime)), zap.Any("summary", summary))
zap.L().Info("Backup complete", zap.String("plan", plan.Id), zap.Duration("duration", time.Since(startTime)), zap.Any("summary", backupOp.OperationBackup.LastStatus))

// schedule followup tasks
at := time.Now()
Expand Down
26 changes: 15 additions & 11 deletions internal/orchestrator/taskstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ 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 {
if op.Status == v1.OperationStatus_STATUS_PENDING || op.Status == v1.OperationStatus_STATUS_INPROGRESS {
return nil
}
howFarBack++
if _, ok := op.Op.(*v1.Operation_OperationStats); ok {
if bytesSinceLastStat == -1 {
bytesSinceLastStat = 0
}
return oplog.ErrStopIteration
} else if backup, ok := op.Op.(*v1.Operation_OperationBackup); ok && backup.OperationBackup.LastStatus != nil {
if summary, ok := backup.OperationBackup.LastStatus.Entry.(*v1.BackupProgressEntry_Summary); ok {
if bytesSinceLastStat == -1 {
bytesSinceLastStat = 0
}
bytesSinceLastStat += summary.Summary.DataAdded
}
}
Expand All @@ -74,17 +77,18 @@ func (t *StatsTask) shouldRun() (bool, error) {
}

func (t *StatsTask) Next(now time.Time) *time.Time {
shouldRun, err := t.shouldRun()
if err != nil {
zap.S().Errorf("task %v failed to check if it should run: %v", t.Name(), err)
}
if !shouldRun {
return nil
}

ret := t.at
if ret != nil {
t.at = nil

shouldRun, err := t.shouldRun()
if err != nil {
zap.S().Errorf("task %v failed to check if it should run: %v", t.Name(), err)
}
if !shouldRun {
return nil
}

if err := t.setOperation(&v1.Operation{
PlanId: t.plan.Id,
RepoId: t.plan.Repo,
Expand Down
1 change: 1 addition & 0 deletions proto/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ message ClearHistoryRequest {
string repo_id = 1;
string plan_id = 2;
bool only_failed = 3;
repeated int64 ops = 4;
}

message ListSnapshotsRequest {
Expand Down
6 changes: 6 additions & 0 deletions webui/gen/ts/v1/service_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export class ClearHistoryRequest extends Message<ClearHistoryRequest> {
*/
onlyFailed = false;

/**
* @generated from field: repeated int64 ops = 4;
*/
ops: bigint[] = [];

constructor(data?: PartialMessage<ClearHistoryRequest>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -36,6 +41,7 @@ export class ClearHistoryRequest extends Message<ClearHistoryRequest> {
{ no: 1, name: "repo_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "plan_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "only_failed", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 4, name: "ops", kind: "scalar", T: 3 /* ScalarType.INT64 */, repeated: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ClearHistoryRequest {
Expand Down
1 change: 0 additions & 1 deletion webui/src/components/OperationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from "../../gen/ts/v1/operations_pb";
import {
Button,
Card,
Col,
Collapse,
Empty,
Expand Down

0 comments on commit 05e5ae0

Please sign in to comment.