diff --git a/analytics/analytics.go b/analytics/analytics.go index bc8029668..ce8b1c257 100644 --- a/analytics/analytics.go +++ b/analytics/analytics.go @@ -74,7 +74,8 @@ type AnalyticsRecord struct { ExpireAt time.Time `bson:"expireAt" json:"expireAt"` ApiSchema string `json:"api_schema" bson:"-" gorm:"-:all"` //nolint - CollectionName string `json:"-" bson:"-" gorm:"-:all"` + GraphQLStats GraphQLStats `json:"-" bson:"-" gorm:"-:all"` + CollectionName string `json:"-" bson:"-" gorm:"-:all"` } func (a *AnalyticsRecord) TableName() string { @@ -92,6 +93,25 @@ func (a *AnalyticsRecord) SetObjectID(id model.ObjectID) { a.id = id } +type GraphQLOperations int + +const ( + OperationUnknown GraphQLOperations = iota + OperationQuery + OperationMutation + OperationSubscription +) + +type GraphQLStats struct { + Variables string + RootFields []string + Types map[string][]string + Errors []GraphError + OperationType GraphQLOperations + HasErrors bool + IsGraphQL bool +} + type GraphError struct { Message string `json:"message"` Path []interface{} `json:"path"` diff --git a/analytics/analytics.proto b/analytics/analytics.proto index 27b90ae91..d31dc7479 100644 --- a/analytics/analytics.proto +++ b/analytics/analytics.proto @@ -40,6 +40,7 @@ message AnalyticsRecord { string OauthID = 29; string TimeZone = 30; string ApiSchema = 31; + GraphQLStats GraphQLStats = 32; } message Latency { @@ -74,3 +75,24 @@ message NetworkStats { int64 BytesIn = 3; int64 BytesOut = 4; } + +enum GraphQLOperations{ + OPERATION_UNKNOWN = 0; + OPERATION_QUERY = 1; + OPERATION_MUTATION = 2; + OPERATION_SUBSCRIPTION = 3; +} + +message GraphQLStats{ + bool IsGraphQL = 1; + map Types = 2; + GraphQLOperations OperationType = 3; + string Variables = 4; + repeated string RootFields = 5; + bool HasError = 6; + repeated string GraphErrors = 7; +} + +message RepeatedFields{ + repeated string fields = 1; +} diff --git a/analytics/proto/analytics.pb.go b/analytics/proto/analytics.pb.go index 205ad3643..867f64829 100644 --- a/analytics/proto/analytics.pb.go +++ b/analytics/proto/analytics.pb.go @@ -22,6 +22,58 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type GraphQLOperations int32 + +const ( + GraphQLOperations_OPERATION_UNKNOWN GraphQLOperations = 0 + GraphQLOperations_OPERATION_QUERY GraphQLOperations = 1 + GraphQLOperations_OPERATION_MUTATION GraphQLOperations = 2 + GraphQLOperations_OPERATION_SUBSCRIPTION GraphQLOperations = 3 +) + +// Enum value maps for GraphQLOperations. +var ( + GraphQLOperations_name = map[int32]string{ + 0: "OPERATION_UNKNOWN", + 1: "OPERATION_QUERY", + 2: "OPERATION_MUTATION", + 3: "OPERATION_SUBSCRIPTION", + } + GraphQLOperations_value = map[string]int32{ + "OPERATION_UNKNOWN": 0, + "OPERATION_QUERY": 1, + "OPERATION_MUTATION": 2, + "OPERATION_SUBSCRIPTION": 3, + } +) + +func (x GraphQLOperations) Enum() *GraphQLOperations { + p := new(GraphQLOperations) + *p = x + return p +} + +func (x GraphQLOperations) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (GraphQLOperations) Descriptor() protoreflect.EnumDescriptor { + return file_analytics_proto_enumTypes[0].Descriptor() +} + +func (GraphQLOperations) Type() protoreflect.EnumType { + return &file_analytics_proto_enumTypes[0] +} + +func (x GraphQLOperations) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use GraphQLOperations.Descriptor instead. +func (GraphQLOperations) EnumDescriptor() ([]byte, []int) { + return file_analytics_proto_rawDescGZIP(), []int{0} +} + type AnalyticsRecord struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -58,6 +110,7 @@ type AnalyticsRecord struct { OauthID string `protobuf:"bytes,29,opt,name=OauthID,proto3" json:"OauthID,omitempty"` TimeZone string `protobuf:"bytes,30,opt,name=TimeZone,proto3" json:"TimeZone,omitempty"` ApiSchema string `protobuf:"bytes,31,opt,name=ApiSchema,proto3" json:"ApiSchema,omitempty"` + GraphQLStats *GraphQLStats `protobuf:"bytes,32,opt,name=GraphQLStats,proto3" json:"GraphQLStats,omitempty"` } func (x *AnalyticsRecord) Reset() { @@ -309,6 +362,13 @@ func (x *AnalyticsRecord) GetApiSchema() string { return "" } +func (x *AnalyticsRecord) GetGraphQLStats() *GraphQLStats { + if x != nil { + return x.GraphQLStats + } + return nil +} + type Latency struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -663,6 +723,148 @@ func (x *NetworkStats) GetBytesOut() int64 { return 0 } +type GraphQLStats struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IsGraphQL bool `protobuf:"varint,1,opt,name=IsGraphQL,proto3" json:"IsGraphQL,omitempty"` + Types map[string]*RepeatedFields `protobuf:"bytes,2,rep,name=Types,proto3" json:"Types,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + OperationType GraphQLOperations `protobuf:"varint,3,opt,name=OperationType,proto3,enum=normalproto.GraphQLOperations" json:"OperationType,omitempty"` + Variables string `protobuf:"bytes,4,opt,name=Variables,proto3" json:"Variables,omitempty"` + RootFields []string `protobuf:"bytes,5,rep,name=RootFields,proto3" json:"RootFields,omitempty"` + HasError bool `protobuf:"varint,6,opt,name=HasError,proto3" json:"HasError,omitempty"` + GraphErrors []string `protobuf:"bytes,7,rep,name=GraphErrors,proto3" json:"GraphErrors,omitempty"` +} + +func (x *GraphQLStats) Reset() { + *x = GraphQLStats{} + if protoimpl.UnsafeEnabled { + mi := &file_analytics_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GraphQLStats) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GraphQLStats) ProtoMessage() {} + +func (x *GraphQLStats) ProtoReflect() protoreflect.Message { + mi := &file_analytics_proto_msgTypes[7] + 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 GraphQLStats.ProtoReflect.Descriptor instead. +func (*GraphQLStats) Descriptor() ([]byte, []int) { + return file_analytics_proto_rawDescGZIP(), []int{7} +} + +func (x *GraphQLStats) GetIsGraphQL() bool { + if x != nil { + return x.IsGraphQL + } + return false +} + +func (x *GraphQLStats) GetTypes() map[string]*RepeatedFields { + if x != nil { + return x.Types + } + return nil +} + +func (x *GraphQLStats) GetOperationType() GraphQLOperations { + if x != nil { + return x.OperationType + } + return GraphQLOperations_OPERATION_UNKNOWN +} + +func (x *GraphQLStats) GetVariables() string { + if x != nil { + return x.Variables + } + return "" +} + +func (x *GraphQLStats) GetRootFields() []string { + if x != nil { + return x.RootFields + } + return nil +} + +func (x *GraphQLStats) GetHasError() bool { + if x != nil { + return x.HasError + } + return false +} + +func (x *GraphQLStats) GetGraphErrors() []string { + if x != nil { + return x.GraphErrors + } + return nil +} + +type RepeatedFields struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Fields []string `protobuf:"bytes,1,rep,name=fields,proto3" json:"fields,omitempty"` +} + +func (x *RepeatedFields) Reset() { + *x = RepeatedFields{} + if protoimpl.UnsafeEnabled { + mi := &file_analytics_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RepeatedFields) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RepeatedFields) ProtoMessage() {} + +func (x *RepeatedFields) ProtoReflect() protoreflect.Message { + mi := &file_analytics_proto_msgTypes[8] + 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 RepeatedFields.ProtoReflect.Descriptor instead. +func (*RepeatedFields) Descriptor() ([]byte, []int) { + return file_analytics_proto_rawDescGZIP(), []int{8} +} + +func (x *RepeatedFields) GetFields() []string { + if x != nil { + return x.Fields + } + return nil +} + var File_analytics_proto protoreflect.FileDescriptor var file_analytics_proto_rawDesc = []byte{ @@ -670,7 +872,7 @@ var file_analytics_proto_rawDesc = []byte{ 0x6f, 0x12, 0x0b, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, - 0xbe, 0x07, 0x0a, 0x0f, 0x41, 0x6e, 0x61, 0x6c, 0x79, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x63, + 0xfd, 0x07, 0x0a, 0x0f, 0x41, 0x6e, 0x61, 0x6c, 0x79, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x48, 0x6f, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, @@ -730,48 +932,87 @@ var file_analytics_proto_rawDesc = []byte{ 0x6e, 0x65, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x54, 0x69, 0x6d, 0x65, 0x5a, 0x6f, 0x6e, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x41, 0x70, 0x69, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x41, 0x70, 0x69, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, - 0x22, 0x3b, 0x0a, 0x07, 0x4c, 0x61, 0x74, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x54, - 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x54, 0x6f, 0x74, 0x61, - 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x03, 0x52, 0x08, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x22, 0x23, 0x0a, - 0x07, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x49, 0x53, 0x4f, 0x43, - 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x49, 0x53, 0x4f, 0x43, 0x6f, - 0x64, 0x65, 0x22, 0x92, 0x01, 0x0a, 0x04, 0x43, 0x69, 0x74, 0x79, 0x12, 0x32, 0x0a, 0x05, 0x4e, - 0x61, 0x6d, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x6e, 0x6f, 0x72, - 0x6d, 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x69, 0x74, 0x79, 0x2e, 0x4e, 0x61, - 0x6d, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x12, - 0x1c, 0x0a, 0x09, 0x47, 0x65, 0x6f, 0x4e, 0x61, 0x6d, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x09, 0x47, 0x65, 0x6f, 0x4e, 0x61, 0x6d, 0x65, 0x49, 0x44, 0x1a, 0x38, 0x0a, - 0x0a, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x60, 0x0a, 0x08, 0x4c, 0x6f, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x4c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, 0x4c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, - 0x1c, 0x0a, 0x09, 0x4c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x01, 0x52, 0x09, 0x4c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1a, 0x0a, - 0x08, 0x54, 0x69, 0x6d, 0x65, 0x5a, 0x6f, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x08, 0x54, 0x69, 0x6d, 0x65, 0x5a, 0x6f, 0x6e, 0x65, 0x22, 0x93, 0x01, 0x0a, 0x07, 0x47, 0x65, - 0x6f, 0x44, 0x61, 0x74, 0x61, 0x12, 0x2e, 0x0a, 0x07, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x43, 0x6f, - 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x25, 0x0a, 0x04, 0x43, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x43, 0x69, 0x74, 0x79, 0x52, 0x04, 0x43, 0x69, 0x74, 0x79, 0x12, 0x31, 0x0a, 0x08, - 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, - 0x2e, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x6f, 0x63, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, - 0x9c, 0x01, 0x0a, 0x0c, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x73, - 0x12, 0x28, 0x0a, 0x0f, 0x4f, 0x70, 0x65, 0x6e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0f, 0x4f, 0x70, 0x65, 0x6e, 0x43, - 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2c, 0x0a, 0x11, 0x43, 0x6c, - 0x6f, 0x73, 0x65, 0x64, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x11, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x43, 0x6f, 0x6e, - 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x42, 0x79, 0x74, 0x65, - 0x73, 0x49, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x42, 0x79, 0x74, 0x65, 0x73, - 0x49, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x79, 0x74, 0x65, 0x73, 0x4f, 0x75, 0x74, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x42, 0x79, 0x74, 0x65, 0x73, 0x4f, 0x75, 0x74, 0x42, 0x08, - 0x5a, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x3d, 0x0a, 0x0c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x51, 0x4c, 0x53, 0x74, 0x61, 0x74, 0x73, + 0x18, 0x20, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x72, 0x61, 0x70, 0x68, 0x51, 0x4c, 0x53, 0x74, 0x61, 0x74, + 0x73, 0x52, 0x0c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x51, 0x4c, 0x53, 0x74, 0x61, 0x74, 0x73, 0x22, + 0x3b, 0x0a, 0x07, 0x4c, 0x61, 0x74, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x54, 0x6f, + 0x74, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x54, 0x6f, 0x74, 0x61, 0x6c, + 0x12, 0x1a, 0x0a, 0x08, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x08, 0x55, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x22, 0x23, 0x0a, 0x07, + 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x49, 0x53, 0x4f, 0x43, 0x6f, + 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x49, 0x53, 0x4f, 0x43, 0x6f, 0x64, + 0x65, 0x22, 0x92, 0x01, 0x0a, 0x04, 0x43, 0x69, 0x74, 0x79, 0x12, 0x32, 0x0a, 0x05, 0x4e, 0x61, + 0x6d, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x6e, 0x6f, 0x72, 0x6d, + 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x69, 0x74, 0x79, 0x2e, 0x4e, 0x61, 0x6d, + 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x12, 0x1c, + 0x0a, 0x09, 0x47, 0x65, 0x6f, 0x4e, 0x61, 0x6d, 0x65, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x09, 0x47, 0x65, 0x6f, 0x4e, 0x61, 0x6d, 0x65, 0x49, 0x44, 0x1a, 0x38, 0x0a, 0x0a, + 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x60, 0x0a, 0x08, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x4c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, 0x4c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1c, + 0x0a, 0x09, 0x4c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x01, 0x52, 0x09, 0x4c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x54, 0x69, 0x6d, 0x65, 0x5a, 0x6f, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x54, 0x69, 0x6d, 0x65, 0x5a, 0x6f, 0x6e, 0x65, 0x22, 0x93, 0x01, 0x0a, 0x07, 0x47, 0x65, 0x6f, + 0x44, 0x61, 0x74, 0x61, 0x12, 0x2e, 0x0a, 0x07, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x43, 0x6f, 0x75, + 0x6e, 0x74, 0x72, 0x79, 0x12, 0x25, 0x0a, 0x04, 0x43, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x43, 0x69, 0x74, 0x79, 0x52, 0x04, 0x43, 0x69, 0x74, 0x79, 0x12, 0x31, 0x0a, 0x08, 0x4c, + 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, + 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4c, 0x6f, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x9c, + 0x01, 0x0a, 0x0c, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x73, 0x12, + 0x28, 0x0a, 0x0f, 0x4f, 0x70, 0x65, 0x6e, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0f, 0x4f, 0x70, 0x65, 0x6e, 0x43, 0x6f, + 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2c, 0x0a, 0x11, 0x43, 0x6c, 0x6f, + 0x73, 0x65, 0x64, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x11, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x43, 0x6f, 0x6e, 0x6e, + 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x42, 0x79, 0x74, 0x65, 0x73, + 0x49, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x42, 0x79, 0x74, 0x65, 0x73, 0x49, + 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x42, 0x79, 0x74, 0x65, 0x73, 0x4f, 0x75, 0x74, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x42, 0x79, 0x74, 0x65, 0x73, 0x4f, 0x75, 0x74, 0x22, 0x81, 0x03, + 0x0a, 0x0c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x51, 0x4c, 0x53, 0x74, 0x61, 0x74, 0x73, 0x12, 0x1c, + 0x0a, 0x09, 0x49, 0x73, 0x47, 0x72, 0x61, 0x70, 0x68, 0x51, 0x4c, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x09, 0x49, 0x73, 0x47, 0x72, 0x61, 0x70, 0x68, 0x51, 0x4c, 0x12, 0x3a, 0x0a, 0x05, + 0x54, 0x79, 0x70, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x6e, 0x6f, + 0x72, 0x6d, 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x72, 0x61, 0x70, 0x68, 0x51, + 0x4c, 0x53, 0x74, 0x61, 0x74, 0x73, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x52, 0x05, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x44, 0x0a, 0x0d, 0x4f, 0x70, 0x65, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, + 0x1e, 0x2e, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x72, + 0x61, 0x70, 0x68, 0x51, 0x4c, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, + 0x0d, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1c, + 0x0a, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x12, 0x1e, 0x0a, 0x0a, + 0x52, 0x6f, 0x6f, 0x74, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x0a, 0x52, 0x6f, 0x6f, 0x74, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, + 0x48, 0x61, 0x73, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, + 0x48, 0x61, 0x73, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x47, 0x72, 0x61, 0x70, + 0x68, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x47, + 0x72, 0x61, 0x70, 0x68, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x1a, 0x55, 0x0a, 0x0a, 0x54, 0x79, + 0x70, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x31, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x6e, 0x6f, 0x72, 0x6d, + 0x61, 0x6c, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x46, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x22, 0x28, 0x0a, 0x0e, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, 0x46, 0x69, 0x65, + 0x6c, 0x64, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x06, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x2a, 0x73, 0x0a, 0x11, 0x47, + 0x72, 0x61, 0x70, 0x68, 0x51, 0x4c, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x12, 0x15, 0x0a, 0x11, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x55, 0x4e, + 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x13, 0x0a, 0x0f, 0x4f, 0x50, 0x45, 0x52, 0x41, + 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x01, 0x12, 0x16, 0x0a, 0x12, + 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x55, 0x54, 0x41, 0x54, 0x49, + 0x4f, 0x4e, 0x10, 0x02, 0x12, 0x1a, 0x0a, 0x16, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4f, + 0x4e, 0x5f, 0x53, 0x55, 0x42, 0x53, 0x43, 0x52, 0x49, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x03, + 0x42, 0x08, 0x5a, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -786,33 +1027,42 @@ func file_analytics_proto_rawDescGZIP() []byte { return file_analytics_proto_rawDescData } -var file_analytics_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_analytics_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_analytics_proto_msgTypes = make([]protoimpl.MessageInfo, 11) var file_analytics_proto_goTypes = []interface{}{ - (*AnalyticsRecord)(nil), // 0: normalproto.AnalyticsRecord - (*Latency)(nil), // 1: normalproto.Latency - (*Country)(nil), // 2: normalproto.Country - (*City)(nil), // 3: normalproto.City - (*Location)(nil), // 4: normalproto.Location - (*GeoData)(nil), // 5: normalproto.GeoData - (*NetworkStats)(nil), // 6: normalproto.NetworkStats - nil, // 7: normalproto.City.NamesEntry - (*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp + (GraphQLOperations)(0), // 0: normalproto.GraphQLOperations + (*AnalyticsRecord)(nil), // 1: normalproto.AnalyticsRecord + (*Latency)(nil), // 2: normalproto.Latency + (*Country)(nil), // 3: normalproto.Country + (*City)(nil), // 4: normalproto.City + (*Location)(nil), // 5: normalproto.Location + (*GeoData)(nil), // 6: normalproto.GeoData + (*NetworkStats)(nil), // 7: normalproto.NetworkStats + (*GraphQLStats)(nil), // 8: normalproto.GraphQLStats + (*RepeatedFields)(nil), // 9: normalproto.RepeatedFields + nil, // 10: normalproto.City.NamesEntry + nil, // 11: normalproto.GraphQLStats.TypesEntry + (*timestamppb.Timestamp)(nil), // 12: google.protobuf.Timestamp } var file_analytics_proto_depIdxs = []int32{ - 8, // 0: normalproto.AnalyticsRecord.TimeStamp:type_name -> google.protobuf.Timestamp - 1, // 1: normalproto.AnalyticsRecord.Latency:type_name -> normalproto.Latency - 5, // 2: normalproto.AnalyticsRecord.Geo:type_name -> normalproto.GeoData - 6, // 3: normalproto.AnalyticsRecord.Network:type_name -> normalproto.NetworkStats - 8, // 4: normalproto.AnalyticsRecord.ExpireAt:type_name -> google.protobuf.Timestamp - 7, // 5: normalproto.City.Names:type_name -> normalproto.City.NamesEntry - 2, // 6: normalproto.GeoData.Country:type_name -> normalproto.Country - 3, // 7: normalproto.GeoData.City:type_name -> normalproto.City - 4, // 8: normalproto.GeoData.Location:type_name -> normalproto.Location - 9, // [9:9] is the sub-list for method output_type - 9, // [9:9] is the sub-list for method input_type - 9, // [9:9] is the sub-list for extension type_name - 9, // [9:9] is the sub-list for extension extendee - 0, // [0:9] is the sub-list for field type_name + 12, // 0: normalproto.AnalyticsRecord.TimeStamp:type_name -> google.protobuf.Timestamp + 2, // 1: normalproto.AnalyticsRecord.Latency:type_name -> normalproto.Latency + 6, // 2: normalproto.AnalyticsRecord.Geo:type_name -> normalproto.GeoData + 7, // 3: normalproto.AnalyticsRecord.Network:type_name -> normalproto.NetworkStats + 12, // 4: normalproto.AnalyticsRecord.ExpireAt:type_name -> google.protobuf.Timestamp + 8, // 5: normalproto.AnalyticsRecord.GraphQLStats:type_name -> normalproto.GraphQLStats + 10, // 6: normalproto.City.Names:type_name -> normalproto.City.NamesEntry + 3, // 7: normalproto.GeoData.Country:type_name -> normalproto.Country + 4, // 8: normalproto.GeoData.City:type_name -> normalproto.City + 5, // 9: normalproto.GeoData.Location:type_name -> normalproto.Location + 11, // 10: normalproto.GraphQLStats.Types:type_name -> normalproto.GraphQLStats.TypesEntry + 0, // 11: normalproto.GraphQLStats.OperationType:type_name -> normalproto.GraphQLOperations + 9, // 12: normalproto.GraphQLStats.TypesEntry.value:type_name -> normalproto.RepeatedFields + 13, // [13:13] is the sub-list for method output_type + 13, // [13:13] is the sub-list for method input_type + 13, // [13:13] is the sub-list for extension type_name + 13, // [13:13] is the sub-list for extension extendee + 0, // [0:13] is the sub-list for field type_name } func init() { file_analytics_proto_init() } @@ -905,19 +1155,44 @@ func file_analytics_proto_init() { return nil } } + file_analytics_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GraphQLStats); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_analytics_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RepeatedFields); 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{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_analytics_proto_rawDesc, - NumEnums: 0, - NumMessages: 8, + NumEnums: 1, + NumMessages: 11, NumExtensions: 0, NumServices: 0, }, GoTypes: file_analytics_proto_goTypes, DependencyIndexes: file_analytics_proto_depIdxs, + EnumInfos: file_analytics_proto_enumTypes, MessageInfos: file_analytics_proto_msgTypes, }.Build() File_analytics_proto = out.File diff --git a/serializer/protobuf.go b/serializer/protobuf.go index a90e2ae45..d7b25b159 100644 --- a/serializer/protobuf.go +++ b/serializer/protobuf.go @@ -88,12 +88,42 @@ func (pb *ProtobufSerializer) TransformSingleRecordToProto(rec analytics.Analyti ApiSchema: rec.ApiSchema, } rec.TimestampToProto(&record) + if rec.GraphQLStats.IsGraphQL { + // operation type + operationType := analyticsproto.GraphQLOperations_OPERATION_UNKNOWN + switch rec.GraphQLStats.OperationType { + case analytics.OperationQuery: + operationType = analyticsproto.GraphQLOperations_OPERATION_QUERY + case analytics.OperationMutation: + operationType = analyticsproto.GraphQLOperations_OPERATION_MUTATION + case analytics.OperationSubscription: + operationType = analyticsproto.GraphQLOperations_OPERATION_SUBSCRIPTION + } + // graph errors + graphErrors := make([]string, len(rec.GraphQLStats.Errors)) + for i, val := range rec.GraphQLStats.Errors { + graphErrors[i] = val.Message + } + // types + graphTypes := make(map[string]*analyticsproto.RepeatedFields) + for key, val := range rec.GraphQLStats.Types { + graphTypes[key] = &analyticsproto.RepeatedFields{Fields: val} + } + record.GraphQLStats = &analyticsproto.GraphQLStats{ + IsGraphQL: true, + Variables: rec.GraphQLStats.Variables, + HasError: rec.GraphQLStats.HasErrors, + OperationType: operationType, + GraphErrors: graphErrors, + RootFields: rec.GraphQLStats.RootFields, + Types: graphTypes, + } + } return record } func (pb *ProtobufSerializer) TransformSingleProtoToAnalyticsRecord(rec analyticsproto.AnalyticsRecord, record *analytics.AnalyticsRecord) error { - tmpRecord := analytics.AnalyticsRecord{ Method: rec.Method, Host: rec.Host, @@ -146,6 +176,41 @@ func (pb *ProtobufSerializer) TransformSingleProtoToAnalyticsRecord(rec analytic ApiSchema: rec.ApiSchema, } tmpRecord.TimeStampFromProto(rec) + + if rec.GraphQLStats != nil { + // process anc convert graphql stats + var operationType analytics.GraphQLOperations + switch rec.GraphQLStats.OperationType { + case analyticsproto.GraphQLOperations_OPERATION_QUERY: + operationType = analytics.OperationQuery + case analyticsproto.GraphQLOperations_OPERATION_MUTATION: + operationType = analytics.OperationMutation + case analyticsproto.GraphQLOperations_OPERATION_SUBSCRIPTION: + operationType = analytics.OperationSubscription + default: + operationType = analytics.OperationUnknown + } + + types := make(map[string][]string) + for key, val := range rec.GraphQLStats.Types { + types[key] = val.Fields + } + errors := make([]analytics.GraphError, len(rec.GraphQLStats.GraphErrors)) + for i, val := range rec.GraphQLStats.GraphErrors { + errors[i].Message = val + } + + tmpRecord.GraphQLStats = analytics.GraphQLStats{ + IsGraphQL: rec.GraphQLStats.IsGraphQL, + OperationType: operationType, + HasErrors: rec.GraphQLStats.HasError, + RootFields: rec.GraphQLStats.RootFields, + Types: types, + Variables: rec.GraphQLStats.Variables, + Errors: errors, + } + } + *record = tmpRecord return nil }