From d964d53743bdef2d71d691405f26fb3aeae0af6e Mon Sep 17 00:00:00 2001 From: Ramky-Infoblox <111125171+Ramky-Infoblox@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:59:56 +0530 Subject: [PATCH 1/2] DDINGI-1306: Revised Data Paging/Totals (#426) * DDINGI-1306: Revised Data Paging/Totals * dependent files * comments indentation --- gateway/field_presence.go | 2 +- gateway/fields.go | 8 +- gorm/filtering.go | 2 +- gorm/utilities.go | 4 +- query/collection_operators.pb.go | 170 +++++++++++++++++-------------- query/collection_operators.proto | 5 + query/fields.go | 20 ++-- query/filtering_lexer.go | 4 +- requestid/interceptor.go | 1 - rpc/resource/jsonpb.go | 8 +- rpc/resource/string.go | 5 +- server/server.go | 2 +- tracing/annotator.go | 4 +- tracing/exporter.go | 4 +- tracing/grpc.go | 26 ++--- tracing/http.go | 26 ++--- tracing/span.go | 16 +-- 17 files changed, 170 insertions(+), 137 deletions(-) diff --git a/gateway/field_presence.go b/gateway/field_presence.go index c3143585..79b5793a 100644 --- a/gateway/field_presence.go +++ b/gateway/field_presence.go @@ -151,7 +151,7 @@ type presenceInterceptorOptionsDecorator struct { type presenceInterceptorOption func(*presenceInterceptorOptionsDecorator) -//WithOverrideFieldMask represent an option to override field mask generated by grpc-gateway +// WithOverrideFieldMask represent an option to override field mask generated by grpc-gateway func WithOverrideFieldMask(d *presenceInterceptorOptionsDecorator) { d.overrideFieldMask = true } diff --git a/gateway/fields.go b/gateway/fields.go index 9fa73fa8..e112a947 100644 --- a/gateway/fields.go +++ b/gateway/fields.go @@ -7,10 +7,10 @@ import ( "github.com/infobloxopen/atlas-app-toolkit/query" ) -//retainFields function extracts the configuration for fields that -//need to be ratained either from gRPC response or from original testRequest -//(in case when gRPC side didn't set any preferences) and retains only -//this fields on outgoing response (dynmap). +// retainFields function extracts the configuration for fields that +// need to be ratained either from gRPC response or from original testRequest +// (in case when gRPC side didn't set any preferences) and retains only +// this fields on outgoing response (dynmap). func retainFields(ctx context.Context, req *http.Request, dynmap map[string]interface{}) { fieldsStr := "" if req != nil { diff --git a/gorm/filtering.go b/gorm/filtering.go index 776ddcca..8d4d2060 100644 --- a/gorm/filtering.go +++ b/gorm/filtering.go @@ -57,7 +57,7 @@ func FilterStringToGorm(ctx context.Context, filter string, obj interface{}, pb return FilteringToGormEx(ctx, f, obj, c) } -//Deprecated: Use FilteringToGormEx instead +// Deprecated: Use FilteringToGormEx instead // FilteringToGorm returns GORM Plain SQL representation of the filtering expression. func FilteringToGorm(ctx context.Context, m *query.Filtering, obj interface{}, pb proto.Message) (string, []interface{}, map[string]struct{}, error) { c := &DefaultFilteringConditionConverter{&DefaultFilteringConditionProcessor{pb}} diff --git a/gorm/utilities.go b/gorm/utilities.go index ef16cedd..13e28d4c 100644 --- a/gorm/utilities.go +++ b/gorm/utilities.go @@ -41,7 +41,7 @@ func HandleFieldPath(ctx context.Context, fieldPath []string, obj interface{}) ( return dbPath, "", nil } -//HandleJSONFiledPath translate field path to JSONB path for postgres jsonb +// HandleJSONFiledPath translate field path to JSONB path for postgres jsonb func HandleJSONFieldPath(ctx context.Context, fieldPath []string, obj interface{}, values ...string) (string, string, error) { operator := "#>>" if isRawJSON(values...) { @@ -82,7 +82,7 @@ func isRawJSON(values ...string) bool { return true } -//TODO: add supprt for embeded objects +// TODO: add supprt for embeded objects func IsJSONCondition(ctx context.Context, fieldPath []string, obj interface{}) bool { fieldName := generator.CamelCase(fieldPath[0]) objType := indirectType(reflect.TypeOf(obj)) diff --git a/query/collection_operators.pb.go b/query/collection_operators.pb.go index 6d643a43..0f52c163 100644 --- a/query/collection_operators.pb.go +++ b/query/collection_operators.pb.go @@ -1112,7 +1112,10 @@ type Pagination struct { // The integer number of resources to be returned in the response. // The service may impose maximum value. // If omitted the service may impose a default value. - Limit int32 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` + Limit int32 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` + // The bool value enables/disables the record count. + // The default setting disables the record count. + IsTotalSizeNeeded bool `protobuf:"varint,4,opt,name=is_total_size_needed,json=isTotalSizeNeeded,proto3" json:"is_total_size_needed,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -1164,6 +1167,13 @@ func (m *Pagination) GetLimit() int32 { return 0 } +func (m *Pagination) GetIsTotalSizeNeeded() bool { + if m != nil { + return m.IsTotalSizeNeeded + } + return false +} + // PageInfo represents both server-driven and client-driven pagination response. // Server-driven pagination is a model in which the server returns some // amount of data along with an token indicating there is more data @@ -1179,7 +1189,9 @@ type PageInfo struct { Size int32 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"` // The service may optionally include the offset of the next page of resources. // A null value indicates no more pages. - Offset int32 `protobuf:"varint,3,opt,name=offset,proto3" json:"offset,omitempty"` + Offset int32 `protobuf:"varint,3,opt,name=offset,proto3" json:"offset,omitempty"` + // total_size indicates the total records present. + TotalSize int64 `protobuf:"varint,4,opt,name=total_size,json=totalSize,proto3" json:"total_size,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -1231,6 +1243,13 @@ func (m *PageInfo) GetOffset() int32 { return 0 } +func (m *PageInfo) GetTotalSize() int64 { + if m != nil { + return m.TotalSize + } + return 0 +} + // Searching represents search by. type Searching struct { Query string `protobuf:"bytes,1,opt,name=query,proto3" json:"query,omitempty"` @@ -1301,77 +1320,80 @@ func init() { } var fileDescriptor_7b72dfd3c08d3120 = []byte{ - // 1148 bytes of a gzipped FileDescriptorProto + // 1192 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x57, 0xd1, 0x52, 0xdb, 0x46, - 0x14, 0xf5, 0xda, 0x92, 0x41, 0x17, 0x30, 0xca, 0xe2, 0x12, 0x03, 0x49, 0x43, 0x35, 0x9d, 0x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0x55, 0x8c, 0xf2, 0x1e, 0x7f, - 0x0b, 0x5a, 0xd4, 0xef, 0x44, 0x95, 0xbc, 0xd4, 0xf4, 0x34, 0x83, 0xb1, 0xda, 0xea, 0x77, 0x94, - 0x10, 0x99, 0xba, 0x79, 0x02, 0xc6, 0x28, 0xf4, 0xc9, 0x22, 0xac, 0xdf, 0x35, 0x30, 0x0e, 0x5d, - 0x4f, 0xec, 0x8a, 0xef, 0xe0, 0x97, 0xb0, 0x38, 0xf4, 0xa7, 0xc4, 0x9c, 0x6a, 0xe9, 0x84, 0x39, - 0x6e, 0x97, 0x78, 0x67, 0x2a, 0xe9, 0x28, 0x67, 0x8f, 0x0a, 0xf0, 0x6b, 0x30, 0x23, 0x2e, 0x60, - 0xda, 0x5d, 0xe6, 0x5f, 0xba, 0x62, 0x02, 0xaa, 0x89, 0x14, 0x48, 0x4b, 0x66, 0xed, 0x0f, 0x93, - 0x8e, 0x72, 0xf6, 0x6a, 0x34, 0x19, 0x12, 0x58, 0x7e, 0xff, 0xa6, 0x43, 0xc3, 0x04, 0x56, 0x21, - 0x0b, 0xeb, 0x54, 0x66, 0x4d, 0x60, 0xf9, 0x93, 0x21, 0x7c, 0x00, 0x25, 0xbf, 0xef, 0x79, 0x09, - 0x24, 0x4d, 0x22, 0x6d, 0xa5, 0x91, 0x3c, 0x2f, 0x89, 0xb3, 0xe2, 0x27, 0x03, 0xf8, 0x3d, 0xac, - 0x2b, 0x75, 0x24, 0x0c, 0xc9, 0x20, 0x81, 0xa6, 0x4b, 0x34, 0x2b, 0x4b, 0x63, 0x43, 0xa4, 0x26, - 0x41, 0xcb, 0x51, 0x46, 0x5c, 0x60, 0x2b, 0xb5, 0x69, 0xec, 0x62, 0x16, 0x76, 0xac, 0x79, 0x1a, - 0xdb, 0xcf, 0x88, 0xef, 0x7d, 0x7e, 0xd7, 0xd8, 0x82, 0x8d, 0xfa, 0x5a, 0xd2, 0xa5, 0x6a, 0xbb, - 0x85, 0x3f, 0x5f, 0x15, 0x41, 0x0b, 0x19, 0xe3, 0xd6, 0x5f, 0x06, 0xac, 0xa6, 0x76, 0x17, 0x1f, - 0xc0, 0x8a, 0x47, 0x7b, 0xbc, 0x3d, 0xaf, 0x27, 0x96, 0x45, 0xd5, 0x08, 0xa5, 0x05, 0x9f, 0x49, - 0x94, 0x8f, 0x35, 0xc7, 0x9a, 0xa8, 0x4e, 0x85, 0x47, 0xa0, 0x1f, 0xeb, 0x12, 0x09, 0x9a, 0x0a, - 0xe3, 0x37, 0xb0, 0xa6, 0x40, 0xe7, 0xb7, 0xcb, 0xa3, 0x18, 0x30, 0x69, 0x99, 0x2e, 0x6c, 0x25, - 0x85, 0xa7, 0xf7, 0x76, 0x69, 0x0e, 0xdf, 0x54, 0xc6, 0x33, 0x48, 0x79, 0x67, 0x48, 0x72, 0x8f, - 0x81, 0x96, 0xe7, 0x30, 0x50, 0x65, 0x3c, 0x93, 0x14, 0xc9, 0x21, 0x94, 0x42, 0xd7, 0xb9, 0x4a, - 0x38, 0x41, 0x9f, 0xc5, 0x09, 0xc8, 0x5e, 0x91, 0x65, 0x23, 0x2b, 0xbc, 0x83, 0xf5, 0x18, 0x67, - 0xca, 0x0b, 0xc5, 0x59, 0xbc, 0x80, 0xec, 0xb2, 0x2c, 0x4f, 0x9b, 0x61, 0x04, 0x3b, 0xe5, 0x86, - 0x85, 0x59, 0xdc, 0x30, 0x84, 0x4d, 0xdb, 0xe1, 0x0c, 0xca, 0x43, 0xd8, 0x09, 0x3f, 0x2c, 0x3e, - 0xec, 0x07, 0x64, 0x63, 0x05, 0x99, 0x34, 0x04, 0x85, 0x27, 0x13, 0xf2, 0xd3, 0x9b, 0xb5, 0x32, - 0xb3, 0x23, 0x90, 0xbd, 0x91, 0x98, 0x44, 0x6a, 0xb7, 0x46, 0x34, 0xf7, 0x78, 0xa2, 0x34, 0xb3, - 0x27, 0x86, 0x34, 0x99, 0xa6, 0x78, 0x0e, 0x1a, 0x1f, 0x04, 0xb4, 0x62, 0xc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0x8d, 0x0a, 0x6c, 0xd6, 0x8d, 0xc9, 0x71, 0xc7, 0xe7, 0xd4, 0xa2, 0xcf, 0x0a, 0x06, 0xcb, 0x97, + 0xd8, 0x26, 0x67, 0xde, 0x80, 0x3e, 0x44, 0x13, 0x81, 0xca, 0xfb, 0x49, 0x92, 0xe2, 0x3e, 0x41, + 0xbd, 0x30, 0x45, 0xfd, 0x29, 0xc0, 0x84, 0xa1, 0xa0, 0x56, 0xb0, 0x74, 0x16, 0x13, 0x33, 0x1b, + 0xa0, 0xb7, 0x09, 0x0e, 0xfa, 0xd7, 0xfc, 0x84, 0x5d, 0x06, 0x4d, 0x7c, 0x12, 0xca, 0x8e, 0xd1, + 0x22, 0xe3, 0x90, 0x16, 0x8a, 0x8a, 0x6e, 0x6f, 0x24, 0x0e, 0x69, 0xdf, 0xbd, 0xfd, 0x76, 0xc1, + 0x4f, 0xce, 0x97, 0xe2, 0x6f, 0xaf, 0x28, 0x3e, 0x14, 0xbf, 0xf9, 0x2f, 0x00, 0x00, 0xff, 0xff, + 0x92, 0xa5, 0x37, 0x25, 0xb2, 0x0e, 0x00, 0x00, } diff --git a/query/collection_operators.proto b/query/collection_operators.proto index f4524216..3b75f524 100644 --- a/query/collection_operators.proto +++ b/query/collection_operators.proto @@ -202,6 +202,9 @@ message Pagination { // The service may impose maximum value. // If omitted the service may impose a default value. int32 limit = 3; + // The bool value enables/disables the record count. + // The default setting disables the record count. + bool is_total_size_needed = 4; } // PageInfo represents both server-driven and client-driven pagination response. @@ -220,6 +223,8 @@ message PageInfo { // The service may optionally include the offset of the next page of resources. // A null value indicates no more pages. int32 offset = 3; + // total_size indicates the total records present. + int64 total_size = 4; } // Searching represents search by. diff --git a/query/fields.go b/query/fields.go index 872c083f..b1af86d7 100644 --- a/query/fields.go +++ b/query/fields.go @@ -9,8 +9,8 @@ const ( opCommonInnerDelimiter = "." ) -//FieldSelectionMap is a convenience type that represents map[string]*Field -//used in FieldSelection and Field structs +// FieldSelectionMap is a convenience type that represents map[string]*Field +// used in FieldSelection and Field structs type FieldSelectionMap map[string]*Field func innerDelimiter(delimiter ...string) string { @@ -26,9 +26,9 @@ func toParts(input string, delimiter ...string) []string { return strings.Split(input, split) } -//ParseFieldSelection transforms a string with comma-separated fields that comes -//from client to FieldSelection struct. For complex fields dot is used as a delimeter by -//default, but it is also possible to specify a different delimiter. +// ParseFieldSelection transforms a string with comma-separated fields that comes +// from client to FieldSelection struct. For complex fields dot is used as a delimeter by +// default, but it is also possible to specify a different delimiter. func ParseFieldSelection(input string, delimiter ...string) *FieldSelection { if len(input) == 0 { return nil @@ -44,8 +44,8 @@ func ParseFieldSelection(input string, delimiter ...string) *FieldSelection { return result } -//GoString converts FieldSelection to a string representation -//It implements fmt.GoStringer interface and returns dot-notated fields separated by commas +// GoString converts FieldSelection to a string representation +// It implements fmt.GoStringer interface and returns dot-notated fields separated by commas func (f *FieldSelection) GoString() string { return strings.Join(f.AllFieldStrings(), opCommonDelimiter) } @@ -70,7 +70,7 @@ func addChildFieldString(result *[]string, parent string, field *Field) { } } -//Add allows to add new fields to FieldSelection +// Add allows to add new fields to FieldSelection func (f *FieldSelection) Add(field string, delimiter ...string) { if len(field) == 0 { return @@ -97,7 +97,7 @@ func (f *FieldSelection) Add(field string, delimiter ...string) { } } -//Delete allows to remove fields from FieldSelection +// Delete allows to remove fields from FieldSelection func (f *FieldSelection) Delete(field string, delimiter ...string) bool { if len(field) == 0 || f.Fields == nil { return false @@ -122,7 +122,7 @@ func (f *FieldSelection) Delete(field string, delimiter ...string) bool { return true } -//Get allows to get specified field from FieldSelection +// Get allows to get specified field from FieldSelection func (f *FieldSelection) Get(field string, delimiter ...string) *Field { if len(field) == 0 || f.Fields == nil { return nil diff --git a/query/filtering_lexer.go b/query/filtering_lexer.go index 974b0145..c3874ca6 100644 --- a/query/filtering_lexer.go +++ b/query/filtering_lexer.go @@ -221,7 +221,7 @@ func (t InToken) String() string { return "in" } -//NumberArrayToken represent number array e.g. [1,2,5] +// NumberArrayToken represent number array e.g. [1,2,5] type StringArrayToken struct { TokenBase Values []string @@ -231,7 +231,7 @@ func (t StringArrayToken) String() string { return fmt.Sprintf("%v", t.Values) } -//NumberArrayToken represent number array e.g. [1,2,5] +// NumberArrayToken represent number array e.g. [1,2,5] type NumberArrayToken struct { TokenBase Values []float64 diff --git a/requestid/interceptor.go b/requestid/interceptor.go index 2b8d140c..6218283a 100644 --- a/requestid/interceptor.go +++ b/requestid/interceptor.go @@ -11,7 +11,6 @@ import ( // that should be used as a middleware to generate/include Request-Id in headers and context // for tracing and tracking user's request. // -// // Returned middleware populates Request-Id from gRPC metadata if // they defined in a testRequest message else creates a new one. func UnaryServerInterceptor() grpc.UnaryServerInterceptor { diff --git a/rpc/resource/jsonpb.go b/rpc/resource/jsonpb.go index 32098c31..275ada9e 100644 --- a/rpc/resource/jsonpb.go +++ b/rpc/resource/jsonpb.go @@ -9,7 +9,9 @@ import ( // MarshalJSONPB implements jsonpb.JSONPBMarshaler interface by marshal // Identifier from a JSON string in accordance with Atlas Reference format -// // +// +// // +// // Support "null" value. func (m Identifier) MarshalJSONPB(*jsonpb.Marshaler) ([]byte, error) { v := BuildString(m.GetApplicationName(), m.GetResourceType(), m.GetResourceId()) @@ -28,7 +30,9 @@ var _ json.Marshaler = &Identifier{} // UnmarshalJSONPB implements jsonpb.JSONPBUnmarshaler interface by unmarshal // Identifier to a JSON string in accordance with Atlas Reference format -// // +// +// // +// // Support "null" value. func (m *Identifier) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, data []byte) error { v := strings.Trim(string(data), "\"") diff --git a/rpc/resource/string.go b/rpc/resource/string.go index 444fd91f..c3d0f272 100644 --- a/rpc/resource/string.go +++ b/rpc/resource/string.go @@ -8,7 +8,8 @@ const ( ) // BuildString builds string id according to Atlas Reference format: -// // +// +// // func BuildString(aname, rtype, rid string) string { var l []string @@ -26,7 +27,9 @@ func BuildString(aname, rtype, rid string) string { } // ParseString parses id according to Atlas Reference format: +// // // +// // All leading and trailing Delimiter are removed. // The resource_id is parsed first, then resource type and last application name. // The id "/a/b/c/" will be converted to "a/b/c" and returned as (a, b, c). diff --git a/server/server.go b/server/server.go index ee4624c7..fa839cc5 100644 --- a/server/server.go +++ b/server/server.go @@ -43,7 +43,7 @@ type Server struct { isAutomaticStop bool } -//Middleware wrapper +// Middleware wrapper type Middleware func(handler http.Handler) http.Handler // Option is a functional option for creating a Server diff --git a/tracing/annotator.go b/tracing/annotator.go index f86dc18e..8e613883 100644 --- a/tracing/annotator.go +++ b/tracing/annotator.go @@ -16,8 +16,8 @@ const ( var defaultFormat propagation.HTTPFormat = &b3.HTTPFormat{} -//SpanContextAnnotator retrieve information about current span from context or HTTP headers -//and propagate in binary format to gRPC service +// SpanContextAnnotator retrieve information about current span from context or HTTP headers +// and propagate in binary format to gRPC service func SpanContextAnnotator(ctx context.Context, req *http.Request) metadata.MD { md := make(metadata.MD) diff --git a/tracing/exporter.go b/tracing/exporter.go index bbc548cd..b979174f 100644 --- a/tracing/exporter.go +++ b/tracing/exporter.go @@ -7,7 +7,7 @@ import ( "go.opencensus.io/trace" ) -//Exporter creates a new OC Agent exporter and configure for tracing +// Exporter creates a new OC Agent exporter and configure for tracing func Exporter(address string, serviceName string, sampler trace.Sampler) error { // TRACE: Setup OC agent for tracing exporter, err := ocagent.NewExporter( @@ -25,7 +25,7 @@ func Exporter(address string, serviceName string, sampler trace.Sampler) error { return nil } -//SamplerForFraction init sampler for specified fraction +// SamplerForFraction init sampler for specified fraction func SamplerForFraction(fraction float64) trace.Sampler { return trace.ProbabilitySampler(fraction) } diff --git a/tracing/grpc.go b/tracing/grpc.go index 5db4e8a2..023620bb 100644 --- a/tracing/grpc.go +++ b/tracing/grpc.go @@ -19,7 +19,7 @@ var sensitiveMetadata = map[string]struct{}{ "authorization": struct{}{}, } -//GRPCOption allows extending handler with additional functionality +// GRPCOption allows extending handler with additional functionality type GRPCOption func(*gRPCOptions) type metadataMatcher func(string) (string, bool) @@ -42,48 +42,48 @@ func defaultGRPCOptions() *gRPCOptions { } } -//WithMetadataAnnotation annotate span with request metadata +// WithMetadataAnnotation annotate span with request metadata func WithMetadataAnnotation(f func(context.Context, stats.RPCStats) bool) GRPCOption { return func(ops *gRPCOptions) { ops.spanWithMetadata = f } } -//WithMetadataMatcher set metadata matcher to filterout or preprocess metadata +// WithMetadataMatcher set metadata matcher to filterout or preprocess metadata func WithMetadataMatcher(f func(string) (string, bool)) GRPCOption { return func(ops *gRPCOptions) { ops.metadataMatcher = f } } -//WithGRPCPayloadAnnotation add Inbound/Outbound payload as an attribute to span if f returns true +// WithGRPCPayloadAnnotation add Inbound/Outbound payload as an attribute to span if f returns true func WithGRPCPayloadAnnotation(f func(context.Context, stats.RPCStats) bool) GRPCOption { return func(ops *gRPCOptions) { ops.spanWithPayload = f } } -//WithGRPCPayloadLimit limit payload size propogated to span -//in case payload exceeds limit, payload truncated and -//annotation payload.truncated=true added into span +// WithGRPCPayloadLimit limit payload size propogated to span +// in case payload exceeds limit, payload truncated and +// annotation payload.truncated=true added into span func WithGRPCPayloadLimit(limit int) GRPCOption { return func(ops *gRPCOptions) { ops.maxPayloadSize = limit } } -//Check that &ServerHandler{} comply stats.Handler interface +// Check that &ServerHandler{} comply stats.Handler interface var _ stats.Handler = &ServerHandler{} -//ServerHandler is a wrapper over ocgrpc.ServerHandler -//wrapper extends metadata added into the span +// ServerHandler is a wrapper over ocgrpc.ServerHandler +// wrapper extends metadata added into the span type ServerHandler struct { ocgrpc.ServerHandler options *gRPCOptions } -//NewServerHandler returns wrapper over ocgrpc.ServerHandler +// NewServerHandler returns wrapper over ocgrpc.ServerHandler func NewServerHandler(ops ...GRPCOption) *ServerHandler { options := defaultGRPCOptions() for _, op := range ops { @@ -197,12 +197,12 @@ func payloadToAttributes(key string, value interface{}, limit int) ([]trace.Attr return attrs, truncated, nil } -//defaultHeaderMatcher is a header matcher which just accept all headers +// defaultHeaderMatcher is a header matcher which just accept all headers func defaultMetadataMatcher(h string) (string, bool) { return h, true } -//AlwaysGRPC for each call returns true +// AlwaysGRPC for each call returns true func AlwaysGRPC(_ context.Context, _ stats.RPCStats) bool { return true } diff --git a/tracing/http.go b/tracing/http.go index aad117d9..0a9db2ce 100644 --- a/tracing/http.go +++ b/tracing/http.go @@ -62,7 +62,7 @@ type httpOptions struct { maxPayloadSize int } -//HTTPOption allows extending handler with additional functionality +// HTTPOption allows extending handler with additional functionality type HTTPOption func(*httpOptions) func defaultHTTPOptions() *httpOptions { @@ -75,37 +75,37 @@ func defaultHTTPOptions() *httpOptions { } } -//WithHeadersAnnotation annotate span with http headers +// WithHeadersAnnotation annotate span with http headers func WithHeadersAnnotation(f func(*http.Request) bool) HTTPOption { return func(ops *httpOptions) { ops.spanWithHeaders = f } } -//WithHeaderMatcher set header matcher to filterout or preprocess headers +// WithHeaderMatcher set header matcher to filterout or preprocess headers func WithHeaderMatcher(f func(string) (string, bool)) HTTPOption { return func(ops *httpOptions) { ops.headerMatcher = f } } -//WithPayloadAnnotation add request/response body as an attribute to span if f returns true +// WithPayloadAnnotation add request/response body as an attribute to span if f returns true func WithPayloadAnnotation(f func(*http.Request) bool) HTTPOption { return func(ops *httpOptions) { ops.spanWithPayload = f } } -//WithHTTPPayloadSize limit payload size propagated to span -//in case payload exceeds limit, payload truncated and -//annotation payload.truncated=true added into span +// WithHTTPPayloadSize limit payload size propagated to span +// in case payload exceeds limit, payload truncated and +// annotation payload.truncated=true added into span func WithHTTPPayloadSize(maxSize int) HTTPOption { return func(ops *httpOptions) { ops.maxPayloadSize = maxSize } } -//NewMiddleware wrap handler +// NewMiddleware wrap handler func NewMiddleware(ops ...HTTPOption) func(http.Handler) http.Handler { options := defaultHTTPOptions() for _, op := range ops { @@ -124,10 +124,10 @@ func NewMiddleware(ops ...HTTPOption) func(http.Handler) http.Handler { } } -//Check that &Handler comply with http.Handler interface +// Check that &Handler comply with http.Handler interface var _ http.Handler = &Handler{} -//Handler is a opencensus http plugin wrapper which do some useful things to reach traces +// Handler is a opencensus http plugin wrapper which do some useful things to reach traces type Handler struct { child http.Handler @@ -213,7 +213,7 @@ func newResponseWrapper(w http.ResponseWriter) *responseBodyWrapper { } } -//responseBodyWrapper duplicate all bytes written to it to buffer +// responseBodyWrapper duplicate all bytes written to it to buffer type responseBodyWrapper struct { http.ResponseWriter @@ -249,12 +249,12 @@ func obfuscate(x string) string { return x[:countChars] + "..." } -//defaultHeaderMatcher is a header matcher which just accept all headers +// defaultHeaderMatcher is a header matcher which just accept all headers func defaultHeaderMatcher(h string) (string, bool) { return h, true } -//AlwaysHTTP for each request returns true +// AlwaysHTTP for each request returns true func AlwaysHTTP(_ *http.Request) bool { return true } diff --git a/tracing/span.go b/tracing/span.go index 04e07792..c4e5d593 100644 --- a/tracing/span.go +++ b/tracing/span.go @@ -14,7 +14,7 @@ var ( ErrSpanNotFound = errors.New("there is no currently active spans") ) -//CurrentSpan returns current span +// CurrentSpan returns current span func CurrentSpan(ctx context.Context) (*trace.Span, error) { span := trace.FromContext(ctx) if span == nil { @@ -24,17 +24,17 @@ func CurrentSpan(ctx context.Context) (*trace.Span, error) { return span, nil } -//StartSpan starts span with name +// StartSpan starts span with name func StartSpan(ctx context.Context, name string) (context.Context, *trace.Span) { return trace.StartSpan(ctx, name) } -//TagSpan tags span +// TagSpan tags span func TagSpan(span *trace.Span, attrs ...trace.Attribute) { span.AddAttributes(attrs...) } -//TagCurrentSpan get current span from context and tag it +// TagCurrentSpan get current span from context and tag it func TagCurrentSpan(ctx context.Context, attrs ...trace.Attribute) error { span, err := CurrentSpan(ctx) if err != nil { @@ -45,12 +45,12 @@ func TagCurrentSpan(ctx context.Context, attrs ...trace.Attribute) error { return nil } -//AddMessageSpan adds message into span +// AddMessageSpan adds message into span func AddMessageSpan(span *trace.Span, message string, attrs ...trace.Attribute) { span.Annotate(attrs, message) } -//AddMessageCurrentSpan get current span from context and adds message into it +// AddMessageCurrentSpan get current span from context and adds message into it func AddMessageCurrentSpan(ctx context.Context, message string, attrs ...trace.Attribute) error { span, err := CurrentSpan(ctx) if err != nil { @@ -61,7 +61,7 @@ func AddMessageCurrentSpan(ctx context.Context, message string, attrs ...trace.A return nil } -//AddErrorCurrentSpan get current span from context and adds error into it +// AddErrorCurrentSpan get current span from context and adds error into it func AddErrorCurrentSpan(ctx context.Context, err error) error { if err != nil { return nil @@ -76,7 +76,7 @@ func AddErrorCurrentSpan(ctx context.Context, err error) error { return AddErrorSpan(span, err) } -//AddErrorSpan adds error into span +// AddErrorSpan adds error into span func AddErrorSpan(span *trace.Span, err error) error { var code int32 = trace.StatusCodeUnknown status, ok := status.FromError(err) From 78aa8abc39673be2cc4b2390f150e7bcc6b1ec25 Mon Sep 17 00:00:00 2001 From: Ramky-Infoblox <111125171+Ramky-Infoblox@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:58:52 +0530 Subject: [PATCH 2/2] added prefix '_' to total_size_needed (#427) * added prefix '_' to total_size_needed * fixed lint error --- gateway/gateway.go | 3 ++- gateway/operator.go | 26 +++++++++++++++--------- query/pagination.go | 10 ++++++++- query/pagination_test.go | 44 ++++++++++++++++++++++++++++++++-------- 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/gateway/gateway.go b/gateway/gateway.go index 9d740e1e..f7efc85c 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -88,8 +88,9 @@ func ClientUnaryInterceptor(parentCtx context.Context, method string, req, reply l := vals.Get(limitQueryKey) o := vals.Get(offsetQueryKey) pt := vals.Get(pageTokenQueryKey) + t := vals.Get(isTotalSizeNeededQueryKey) - p, err = query.ParsePagination(l, o, pt) + p, err = query.ParsePagination(l, o, pt, t) if err != nil { return status.Error(codes.InvalidArgument, err.Error()) } diff --git a/gateway/operator.go b/gateway/operator.go index 19c58867..ee497f8a 100644 --- a/gateway/operator.go +++ b/gateway/operator.go @@ -11,16 +11,18 @@ import ( ) const ( - filterQueryKey = "_filter" - sortQueryKey = "_order_by" - fieldsQueryKey = "_fields" - limitQueryKey = "_limit" - offsetQueryKey = "_offset" - pageTokenQueryKey = "_page_token" - searchQueryKey = "_fts" - pageInfoSizeMetaKey = "status-page-info-size" - pageInfoOffsetMetaKey = "status-page-info-offset" - pageInfoPageTokenMetaKey = "status-page-info-page_token" + filterQueryKey = "_filter" + sortQueryKey = "_order_by" + fieldsQueryKey = "_fields" + limitQueryKey = "_limit" + offsetQueryKey = "_offset" + pageTokenQueryKey = "_page_token" + searchQueryKey = "_fts" + isTotalSizeNeededQueryKey = "_is_total_size_needed" + pageInfoSizeMetaKey = "status-page-info-size" + pageInfoOffsetMetaKey = "status-page-info-offset" + pageInfoPageTokenMetaKey = "status-page-info-page_token" + pageInfoPageTotalSizeMetaKey = "status-page-info-total_size" query_url = "query_url" ) @@ -55,5 +57,9 @@ func SetPageInfo(ctx context.Context, p *query.PageInfo) error { m[pageInfoSizeMetaKey] = strconv.FormatUint(uint64(s), 10) } + if t := p.GetTotalSize(); t != 0 { + m[pageInfoPageTotalSizeMetaKey] = strconv.FormatUint(uint64(t), 10) + } + return grpc.SetHeader(ctx, metadata.New(m)) } diff --git a/query/pagination.go b/query/pagination.go index aa6495e7..1c8c6dfe 100644 --- a/query/pagination.go +++ b/query/pagination.go @@ -14,7 +14,7 @@ const ( // Pagination parses string representation of pagination limit, offset. // Returns error if limit or offset has invalid syntax or out of range. -func ParsePagination(limit, offset, ptoken string) (*Pagination, error) { +func ParsePagination(limit, offset, ptoken, isTotalSizeNeeded string) (*Pagination, error) { p := new(Pagination) if limit != "" { @@ -43,6 +43,14 @@ func ParsePagination(limit, offset, ptoken string) (*Pagination, error) { p.PageToken = ptoken } + if isTotalSizeNeeded != "" { + u, err := strconv.ParseBool(isTotalSizeNeeded) + if err != nil { + return nil, fmt.Errorf("pagination: is_total_size_needed - %s", err.(*strconv.NumError).Err) + } + p.IsTotalSizeNeeded = u + } + return p, nil } diff --git a/query/pagination_test.go b/query/pagination_test.go index 18ff106e..b43014d5 100644 --- a/query/pagination_test.go +++ b/query/pagination_test.go @@ -2,11 +2,13 @@ package query import ( "testing" + + "github.com/stretchr/testify/assert" ) func TestParsePagination(t *testing.T) { // invalid limit - _, err := ParsePagination("1s", "0", "ptoken") + _, err := ParsePagination("1s", "0", "ptoken", "") if err == nil { t.Error("unexpected nil error - expected: pagination: limit - invalid syntax") } @@ -15,7 +17,7 @@ func TestParsePagination(t *testing.T) { } // negative limit - _, err = ParsePagination("-1", "0", "ptoken") + _, err = ParsePagination("-1", "0", "ptoken", "") if err == nil { t.Error("unexpected nil error - expected: pagination: limit must be a positive value") } @@ -24,7 +26,7 @@ func TestParsePagination(t *testing.T) { } // zero limit - _, err = ParsePagination("0", "0", "ptoken") + _, err = ParsePagination("0", "0", "ptoken", "") if err == nil { t.Error("unexpected nil error - expected: pagination: limit must be a positive value") } @@ -33,7 +35,7 @@ func TestParsePagination(t *testing.T) { } // invalid offset - _, err = ParsePagination("", "0w", "ptoken") + _, err = ParsePagination("", "0w", "ptoken", "") if err == nil { t.Error("unexpected nil error - expected: pagination: offset - invalid syntax") } @@ -42,7 +44,7 @@ func TestParsePagination(t *testing.T) { } // negative offset - _, err = ParsePagination("", "-1", "ptoken") + _, err = ParsePagination("", "-1", "ptoken", "") if err == nil { t.Error("unexpected nil error - expected: pagination: offset - negative value") } @@ -51,7 +53,7 @@ func TestParsePagination(t *testing.T) { } // null offset - p, err := ParsePagination("", "null", "ptoken") + p, err := ParsePagination("", "null", "ptoken", "") if err != nil { t.Errorf("unexpected error: %v", err) } @@ -60,14 +62,14 @@ func TestParsePagination(t *testing.T) { } // first page - p, err = ParsePagination("", "0", "ptoken") + p, err = ParsePagination("", "0", "ptoken", "") if err != nil { t.Errorf("unexpected error: %s", err) } if !p.FirstPage() { t.Errorf("invalid value of first page: %v - expected: true", p.FirstPage()) } - p, err = ParsePagination("", "100", "null") + p, err = ParsePagination("", "100", "null", "") if err != nil { t.Errorf("unexpected error: %s", err) } @@ -81,7 +83,7 @@ func TestParsePagination(t *testing.T) { } // valid pagination - p, err = ParsePagination("1000", "100", "ptoken") + p, err = ParsePagination("1000", "100", "ptoken", "") if err != nil { t.Errorf("unexpected error: %s", err) } @@ -94,6 +96,30 @@ func TestParsePagination(t *testing.T) { if p.GetPageToken() != "ptoken" { t.Errorf("invalid page token: %q - expected: ptoken", p.GetPageToken()) } + + // valid pagination with isTotalSizeNeeded=true + p, err = ParsePagination("1000", "100", "ptoken", "true") + if err != nil { + t.Errorf("unexpected error: %s", err) + } + assert.Equal(t, true, p.GetIsTotalSizeNeeded()) + + // valid pagination with isTotalSizeNeeded=false + p, err = ParsePagination("1000", "100", "ptoken", "false") + if err != nil { + t.Errorf("unexpected error: %s", err) + } + assert.Equal(t, false, p.GetIsTotalSizeNeeded()) + + // valid pagination with isTotalSizeNeeded=null + _, err = ParsePagination("1000", "100", "ptoken", "null") + if err == nil { + t.Error("unexpected nil error - expected: pagination: is_total_size_needed - invalid syntax") + } + if err.Error() != "pagination: is_total_size_needed - invalid syntax" { + t.Errorf("invalid error: %s - expected: pagination: is_total_size_needed - invalid syntax", err) + } + } func TestPageInfo(t *testing.T) {