diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2022-04-19 17:57:34 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2022-04-19 17:57:34 +0300 |
commit | ef18681a6f171af027a31de9ce335a1887d31e81 (patch) | |
tree | cd7cb1306da9cbda5f22173a498ea711602444fc | |
parent | fa2d37aadad24b730c4d85caf43465864b8e1a5d (diff) | |
parent | 4e2d52201ab72dbc2e18f4cb931a8c1303fb9d47 (diff) |
Merge branch 'jc-limit-error-proto' into 'master'
proto: Add LimitError as a structured error
See merge request gitlab-org/gitaly!4476
-rw-r--r-- | proto/errors.proto | 11 | ||||
-rw-r--r-- | proto/go/gitalypb/errors.pb.go | 110 | ||||
-rw-r--r-- | ruby/proto/gitaly/errors_pb.rb | 6 |
3 files changed, 114 insertions, 13 deletions
diff --git a/proto/errors.proto b/proto/errors.proto index 8e0b2298b..101c58bf7 100644 --- a/proto/errors.proto +++ b/proto/errors.proto @@ -4,6 +4,8 @@ package gitaly; option go_package = "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"; +import "google/protobuf/duration.proto"; + // AccessCheckError is an error returned by GitLab's `/internal/allowed` // endpoint. message AccessCheckError { @@ -43,3 +45,12 @@ message ResolveRevisionError { // Revision is the name of the revision that was tried to be resolved. bytes revision = 1; } + +// LimitError is an error returned when Gitaly enforces request limits. +message LimitError { + // ErrorMessage provides context into why a limit was enforced. + string error_message = 1; + // RetryAfter provides the duration after which a retry is safe. + // 0 indicates non-retryable. + google.protobuf.Duration retry_after = 2; +} diff --git a/proto/go/gitalypb/errors.pb.go b/proto/go/gitalypb/errors.pb.go index a228353dc..6443c2825 100644 --- a/proto/go/gitalypb/errors.pb.go +++ b/proto/go/gitalypb/errors.pb.go @@ -9,6 +9,7 @@ package gitalypb 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" ) @@ -267,11 +268,72 @@ func (x *ResolveRevisionError) GetRevision() []byte { return nil } +// LimitError is an error returned when Gitaly enforces request limits. +type LimitError struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // ErrorMessage provides context into why a limit was enforced. + ErrorMessage string `protobuf:"bytes,1,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"` + // RetryAfter provides the duration after which a retry is safe. + // 0 indicates non-retryable. + RetryAfter *durationpb.Duration `protobuf:"bytes,2,opt,name=retry_after,json=retryAfter,proto3" json:"retry_after,omitempty"` +} + +func (x *LimitError) Reset() { + *x = LimitError{} + if protoimpl.UnsafeEnabled { + mi := &file_errors_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LimitError) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LimitError) ProtoMessage() {} + +func (x *LimitError) ProtoReflect() protoreflect.Message { + mi := &file_errors_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LimitError.ProtoReflect.Descriptor instead. +func (*LimitError) Descriptor() ([]byte, []int) { + return file_errors_proto_rawDescGZIP(), []int{4} +} + +func (x *LimitError) GetErrorMessage() string { + if x != nil { + return x.ErrorMessage + } + return "" +} + +func (x *LimitError) GetRetryAfter() *durationpb.Duration { + if x != nil { + return x.RetryAfter + } + return nil +} + var File_errors_proto protoreflect.FileDescriptor var file_errors_proto_rawDesc = []byte{ 0x0a, 0x0c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, - 0x67, 0x69, 0x74, 0x61, 0x6c, 0x79, 0x22, 0x86, 0x01, 0x0a, 0x10, 0x41, 0x63, 0x63, 0x65, 0x73, + 0x67, 0x69, 0x74, 0x61, 0x6c, 0x79, 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, 0x86, 0x01, 0x0a, 0x10, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, @@ -294,11 +356,18 @@ var file_errors_proto_rawDesc = []byte{ 0x4f, 0x69, 0x64, 0x22, 0x32, 0x0a, 0x14, 0x52, 0x65, 0x73, 0x6f, 0x6c, 0x76, 0x65, 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x72, - 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x6c, 0x61, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x69, 0x74, 0x6c, 0x61, 0x62, 0x2d, 0x6f, 0x72, 0x67, - 0x2f, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x79, 0x2f, 0x76, 0x31, 0x34, 0x2f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2f, 0x67, 0x6f, 0x2f, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x79, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x6d, 0x0a, 0x0a, 0x4c, 0x69, 0x6d, 0x69, 0x74, + 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x3a, 0x0a, 0x0b, 0x72, 0x65, + 0x74, 0x72, 0x79, 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, 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, 0x0a, 0x72, 0x65, 0x74, 0x72, + 0x79, 0x41, 0x66, 0x74, 0x65, 0x72, 0x42, 0x34, 0x5a, 0x32, 0x67, 0x69, 0x74, 0x6c, 0x61, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x69, 0x74, 0x6c, 0x61, 0x62, 0x2d, 0x6f, 0x72, 0x67, 0x2f, + 0x67, 0x69, 0x74, 0x61, 0x6c, 0x79, 0x2f, 0x76, 0x31, 0x34, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2f, 0x67, 0x6f, 0x2f, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x79, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -313,19 +382,22 @@ func file_errors_proto_rawDescGZIP() []byte { return file_errors_proto_rawDescData } -var file_errors_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_errors_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_errors_proto_goTypes = []interface{}{ (*AccessCheckError)(nil), // 0: gitaly.AccessCheckError (*MergeConflictError)(nil), // 1: gitaly.MergeConflictError (*ReferenceUpdateError)(nil), // 2: gitaly.ReferenceUpdateError (*ResolveRevisionError)(nil), // 3: gitaly.ResolveRevisionError + (*LimitError)(nil), // 4: gitaly.LimitError + (*durationpb.Duration)(nil), // 5: google.protobuf.Duration } var file_errors_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] 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 + 5, // 0: gitaly.LimitError.retry_after:type_name -> google.protobuf.Duration + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] 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_errors_proto_init() } @@ -382,6 +454,18 @@ func file_errors_proto_init() { return nil } } + file_errors_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LimitError); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -389,7 +473,7 @@ func file_errors_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_errors_proto_rawDesc, NumEnums: 0, - NumMessages: 4, + NumMessages: 5, NumExtensions: 0, NumServices: 0, }, diff --git a/ruby/proto/gitaly/errors_pb.rb b/ruby/proto/gitaly/errors_pb.rb index f344beaaa..b28115768 100644 --- a/ruby/proto/gitaly/errors_pb.rb +++ b/ruby/proto/gitaly/errors_pb.rb @@ -1,6 +1,7 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: errors.proto +require 'google/protobuf/duration_pb' require 'google/protobuf' Google::Protobuf::DescriptorPool.generated_pool.build do @@ -22,6 +23,10 @@ Google::Protobuf::DescriptorPool.generated_pool.build do add_message "gitaly.ResolveRevisionError" do optional :revision, :bytes, 1 end + add_message "gitaly.LimitError" do + optional :error_message, :string, 1 + optional :retry_after, :message, 2, "google.protobuf.Duration" + end end end @@ -30,4 +35,5 @@ module Gitaly MergeConflictError = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.MergeConflictError").msgclass ReferenceUpdateError = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.ReferenceUpdateError").msgclass ResolveRevisionError = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.ResolveRevisionError").msgclass + LimitError = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("gitaly.LimitError").msgclass end |