From acf69b80d3f3269dc0d81c40e423c2e60de09e13 Mon Sep 17 00:00:00 2001 From: garethgeorge Date: Wed, 14 Aug 2024 17:58:40 -0700 Subject: [PATCH] feat: accept up to 2 decimals of precision for check % and prune % policies --- gen/go/v1/config.pb.go | 6 +++--- internal/orchestrator/repo/repo.go | 2 +- proto/v1/config.proto | 2 +- webui/gen/ts/v1/config_pb.ts | 4 ++-- webui/src/views/AddRepoModal.tsx | 24 +++++++++++++++++++----- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/gen/go/v1/config.pb.go b/gen/go/v1/config.pb.go index 50278e6b..55b50d7c 100644 --- a/gen/go/v1/config.pb.go +++ b/gen/go/v1/config.pb.go @@ -1058,7 +1058,7 @@ func (x *CheckPolicy) GetStructureOnly() bool { return false } -func (x *CheckPolicy) GetReadDataSubsetPercent() int32 { +func (x *CheckPolicy) GetReadDataSubsetPercent() float64 { if x, ok := x.GetMode().(*CheckPolicy_ReadDataSubsetPercent); ok { return x.ReadDataSubsetPercent } @@ -1074,7 +1074,7 @@ type CheckPolicy_StructureOnly struct { } type CheckPolicy_ReadDataSubsetPercent struct { - ReadDataSubsetPercent int32 `protobuf:"varint,101,opt,name=read_data_subset_percent,json=readDataSubsetPercent,proto3,oneof"` // check a percentage of pack data. + ReadDataSubsetPercent float64 `protobuf:"fixed64,101,opt,name=read_data_subset_percent,json=readDataSubsetPercent,proto3,oneof"` // check a percentage of pack data. } func (*CheckPolicy_StructureOnly) isCheckPolicy_Mode() {} @@ -2101,7 +2101,7 @@ var file_v1_config_proto_rawDesc = []byte{ 0x64, 0x20, 0x01, 0x28, 0x08, 0x48, 0x00, 0x52, 0x0d, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x75, 0x72, 0x65, 0x4f, 0x6e, 0x6c, 0x79, 0x12, 0x39, 0x0a, 0x18, 0x72, 0x65, 0x61, 0x64, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x73, 0x75, 0x62, 0x73, 0x65, 0x74, 0x5f, 0x70, 0x65, 0x72, 0x63, 0x65, - 0x6e, 0x74, 0x18, 0x65, 0x20, 0x01, 0x28, 0x05, 0x48, 0x00, 0x52, 0x15, 0x72, 0x65, 0x61, 0x64, + 0x6e, 0x74, 0x18, 0x65, 0x20, 0x01, 0x28, 0x01, 0x48, 0x00, 0x52, 0x15, 0x72, 0x65, 0x61, 0x64, 0x44, 0x61, 0x74, 0x61, 0x53, 0x75, 0x62, 0x73, 0x65, 0x74, 0x50, 0x65, 0x72, 0x63, 0x65, 0x6e, 0x74, 0x42, 0x06, 0x0a, 0x04, 0x6d, 0x6f, 0x64, 0x65, 0x22, 0xa8, 0x01, 0x0a, 0x08, 0x53, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x1c, 0x0a, 0x08, 0x64, 0x69, 0x73, 0x61, 0x62, 0x6c, diff --git a/internal/orchestrator/repo/repo.go b/internal/orchestrator/repo/repo.go index b7dd75de..3d019587 100644 --- a/internal/orchestrator/repo/repo.go +++ b/internal/orchestrator/repo/repo.go @@ -273,7 +273,7 @@ func (r *RepoOrchestrator) Check(ctx context.Context, output io.Writer) error { switch m := r.repoConfig.CheckPolicy.Mode.(type) { case *v1.CheckPolicy_ReadDataSubsetPercent: if m.ReadDataSubsetPercent > 0 { - opts = append(opts, restic.WithFlags(fmt.Sprintf("--read-data-subset=%v%%", m.ReadDataSubsetPercent))) + opts = append(opts, restic.WithFlags(fmt.Sprintf("--read-data-subset=%.4f%%", m.ReadDataSubsetPercent))) } case *v1.CheckPolicy_StructureOnly: default: diff --git a/proto/v1/config.proto b/proto/v1/config.proto index 7e344c15..9d3579df 100644 --- a/proto/v1/config.proto +++ b/proto/v1/config.proto @@ -114,7 +114,7 @@ message CheckPolicy { oneof mode { bool structure_only = 100 [json_name="structureOnly"]; // only check the structure of the repo. No pack data is read. - int32 read_data_subset_percent = 101 [json_name="readDataSubsetPercent"]; // check a percentage of pack data. + double read_data_subset_percent = 101 [json_name="readDataSubsetPercent"]; // check a percentage of pack data. } } diff --git a/webui/gen/ts/v1/config_pb.ts b/webui/gen/ts/v1/config_pb.ts index 065b34e9..58d814b8 100644 --- a/webui/gen/ts/v1/config_pb.ts +++ b/webui/gen/ts/v1/config_pb.ts @@ -773,7 +773,7 @@ export class CheckPolicy extends Message { /** * check a percentage of pack data. * - * @generated from field: int32 read_data_subset_percent = 101; + * @generated from field: double read_data_subset_percent = 101; */ value: number; case: "readDataSubsetPercent"; @@ -789,7 +789,7 @@ export class CheckPolicy extends Message { static readonly fields: FieldList = proto3.util.newFieldList(() => [ { no: 1, name: "schedule", kind: "message", T: Schedule }, { no: 100, name: "structure_only", kind: "scalar", T: 8 /* ScalarType.BOOL */, oneof: "mode" }, - { no: 101, name: "read_data_subset_percent", kind: "scalar", T: 5 /* ScalarType.INT32 */, oneof: "mode" }, + { no: 101, name: "read_data_subset_percent", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, oneof: "mode" }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): CheckPolicy { diff --git a/webui/src/views/AddRepoModal.tsx b/webui/src/views/AddRepoModal.tsx index f62b2ded..66da781d 100644 --- a/webui/src/views/AddRepoModal.tsx +++ b/webui/src/views/AddRepoModal.tsx @@ -465,13 +465,13 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => { > - -
Max Unused % After Prune
+
Max Unused After Prune
} /> @@ -504,10 +504,10 @@ export const AddRepoModal = ({ template }: { template: Repo | null }) => { initialValue={0} required={false} > - -
Read Pack Data %
+
Read Data %
} /> @@ -785,3 +785,17 @@ const formatMissingEnvVars = (partialMatches: string[][]): string => { }) .join(" or "); }; + +const InputPercent = ({ ...props }) => { + return ( + + ); +};