From 0b371006dea0f3592912410e4f3c639a890a1e10 Mon Sep 17 00:00:00 2001 From: zeroalphat Date: Tue, 19 Sep 2023 08:24:18 +0000 Subject: [PATCH] Use duration instead of int64 Signed-off-by: zeroalphat --- docs/necoperf-grpc.md | 2 +- pkg/rpc/necoperf.pb.go | 60 ++++++++++++++++++++++++------------------ pkg/rpc/necoperf.proto | 7 ++--- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/docs/necoperf-grpc.md b/docs/necoperf-grpc.md index 6689bbc..62f7f08 100644 --- a/docs/necoperf-grpc.md +++ b/docs/necoperf-grpc.md @@ -29,7 +29,7 @@ | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | container_id | [string](#string) | | | -| timeout_seconds | [int64](#int64) | | | +| timeout | [google.protobuf.Duration](#google-protobuf-Duration) | | | diff --git a/pkg/rpc/necoperf.pb.go b/pkg/rpc/necoperf.pb.go index 2816c41..f4ce9cd 100644 --- a/pkg/rpc/necoperf.pb.go +++ b/pkg/rpc/necoperf.pb.go @@ -9,6 +9,7 @@ package rpc import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + durationpb "google.golang.org/protobuf/types/known/durationpb" reflect "reflect" sync "sync" ) @@ -25,8 +26,8 @@ type PerfProfileRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ContainerId string `protobuf:"bytes,1,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"` - TimeoutSeconds int64 `protobuf:"varint,2,opt,name=timeout_seconds,json=timeoutSeconds,proto3" json:"timeout_seconds,omitempty"` + ContainerId string `protobuf:"bytes,1,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"` + Timeout *durationpb.Duration `protobuf:"bytes,2,opt,name=timeout,proto3" json:"timeout,omitempty"` } func (x *PerfProfileRequest) Reset() { @@ -68,11 +69,11 @@ func (x *PerfProfileRequest) GetContainerId() string { return "" } -func (x *PerfProfileRequest) GetTimeoutSeconds() int64 { +func (x *PerfProfileRequest) GetTimeout() *durationpb.Duration { if x != nil { - return x.TimeoutSeconds + return x.Timeout } - return 0 + return nil } type PerfProfileResponse struct { @@ -127,22 +128,27 @@ var File_pkg_rpc_necoperf_proto protoreflect.FileDescriptor var file_pkg_rpc_necoperf_proto_rawDesc = []byte{ 0x0a, 0x16, 0x70, 0x6b, 0x67, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x6e, 0x65, 0x63, 0x6f, 0x70, 0x65, 0x72, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x6e, 0x65, 0x63, 0x6f, 0x70, 0x65, - 0x72, 0x66, 0x22, 0x60, 0x0a, 0x12, 0x50, 0x65, 0x72, 0x66, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, + 0x72, 0x66, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0x6c, 0x0a, 0x12, 0x50, 0x65, 0x72, 0x66, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, - 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x27, 0x0a, 0x0f, 0x74, - 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x5f, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x53, 0x65, 0x63, - 0x6f, 0x6e, 0x64, 0x73, 0x22, 0x29, 0x0a, 0x13, 0x50, 0x65, 0x72, 0x66, 0x50, 0x72, 0x6f, 0x66, - 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, - 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, - 0x54, 0x0a, 0x08, 0x4e, 0x65, 0x63, 0x6f, 0x50, 0x65, 0x72, 0x66, 0x12, 0x48, 0x0a, 0x07, 0x50, - 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x1c, 0x2e, 0x6e, 0x65, 0x63, 0x6f, 0x70, 0x65, 0x72, - 0x66, 0x2e, 0x50, 0x65, 0x72, 0x66, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x6e, 0x65, 0x63, 0x6f, 0x70, 0x65, 0x72, 0x66, 0x2e, - 0x50, 0x65, 0x72, 0x66, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x09, 0x5a, 0x07, 0x70, 0x6b, 0x67, 0x2f, 0x72, 0x70, 0x63, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x33, 0x0a, 0x07, 0x74, + 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, + 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, + 0x22, 0x29, 0x0a, 0x13, 0x50, 0x65, 0x72, 0x66, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 0x54, 0x0a, 0x08, 0x4e, + 0x65, 0x63, 0x6f, 0x50, 0x65, 0x72, 0x66, 0x12, 0x48, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x66, 0x69, + 0x6c, 0x65, 0x12, 0x1c, 0x2e, 0x6e, 0x65, 0x63, 0x6f, 0x70, 0x65, 0x72, 0x66, 0x2e, 0x50, 0x65, + 0x72, 0x66, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1d, 0x2e, 0x6e, 0x65, 0x63, 0x6f, 0x70, 0x65, 0x72, 0x66, 0x2e, 0x50, 0x65, 0x72, 0x66, + 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, + 0x01, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x63, 0x79, 0x62, 0x6f, 0x7a, 0x75, 0x2d, 0x67, 0x6f, 0x2f, 0x6e, 0x65, 0x63, 0x6f, 0x70, 0x65, + 0x72, 0x66, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -161,15 +167,17 @@ var file_pkg_rpc_necoperf_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_pkg_rpc_necoperf_proto_goTypes = []interface{}{ (*PerfProfileRequest)(nil), // 0: necoperf.PerfProfileRequest (*PerfProfileResponse)(nil), // 1: necoperf.PerfProfileResponse + (*durationpb.Duration)(nil), // 2: google.protobuf.Duration } var file_pkg_rpc_necoperf_proto_depIdxs = []int32{ - 0, // 0: necoperf.NecoPerf.Profile:input_type -> necoperf.PerfProfileRequest - 1, // 1: necoperf.NecoPerf.Profile:output_type -> necoperf.PerfProfileResponse - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 2, // 0: necoperf.PerfProfileRequest.timeout:type_name -> google.protobuf.Duration + 0, // 1: necoperf.NecoPerf.Profile:input_type -> necoperf.PerfProfileRequest + 1, // 2: necoperf.NecoPerf.Profile:output_type -> necoperf.PerfProfileResponse + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name } func init() { file_pkg_rpc_necoperf_proto_init() } diff --git a/pkg/rpc/necoperf.proto b/pkg/rpc/necoperf.proto index 6cc5278..f0f7693 100644 --- a/pkg/rpc/necoperf.proto +++ b/pkg/rpc/necoperf.proto @@ -1,8 +1,9 @@ syntax = "proto3"; +package necoperf; -option go_package = "pkg/rpc"; +import "google/protobuf/duration.proto"; -package necoperf; +option go_package = "github.com/cybozu-go/necoperf/pkg/rpc"; service NecoPerf { rpc Profile(PerfProfileRequest) returns (stream PerfProfileResponse); @@ -10,7 +11,7 @@ service NecoPerf { message PerfProfileRequest { string container_id = 1; - int64 timeout_seconds = 2; + google.protobuf.Duration timeout = 2; } message PerfProfileResponse {