diff --git a/analytics/analytics.go b/analytics/analytics.go index bc8029668..539f186ef 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,24 @@ func (a *AnalyticsRecord) SetObjectID(id model.ObjectID) { a.id = id } +type GraphQLOperations int + +const ( + Operation_Unknown GraphQLOperations = iota + Operation_Query + Operation_Mutation + Operation_Subscription +) + +type GraphQLStats struct { + Types map[string][]string + OperationType GraphQLOperations + Variables string + RootFields []string + HasErrors bool + Errors []GraphError +} + type GraphError struct { Message string `json:"message"` Path []interface{} `json:"path"` diff --git a/analytics/analytics.proto b/analytics/analytics.proto index 1205a7aa9..d31dc7479 100644 --- a/analytics/analytics.proto +++ b/analytics/analytics.proto @@ -77,18 +77,20 @@ message NetworkStats { } enum GraphQLOperations{ - OPERATION_QUERY = 0; - OPERATION_MUTATION = 1; - OPERATION_SUBSCRIPTION = 2; + OPERATION_UNKNOWN = 0; + OPERATION_QUERY = 1; + OPERATION_MUTATION = 2; + OPERATION_SUBSCRIPTION = 3; } message GraphQLStats{ - map Types = 1; - GraphQLOperations OperationType = 2; - string Variables = 3; - repeated string RootFields = 4; - bool HasError = 5; - repeated string GraphErrors = 6; + 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{ diff --git a/analytics/proto/analytics.pb.go b/analytics/proto/analytics.pb.go index 5f1eaf12b..740c4f162 100644 --- a/analytics/proto/analytics.pb.go +++ b/analytics/proto/analytics.pb.go @@ -24,22 +24,25 @@ const ( type GraphQLOperations int32 const ( - GraphQLOperations_OPERATION_QUERY GraphQLOperations = 0 - GraphQLOperations_OPERATION_MUTATION GraphQLOperations = 1 - GraphQLOperations_OPERATION_SUBSCRIPTION GraphQLOperations = 2 + 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_QUERY", - 1: "OPERATION_MUTATION", - 2: "OPERATION_SUBSCRIPTION", + 0: "OPERATION_UNKNOWN", + 1: "OPERATION_QUERY", + 2: "OPERATION_MUTATION", + 3: "OPERATION_SUBSCRIPTION", } GraphQLOperations_value = map[string]int32{ - "OPERATION_QUERY": 0, - "OPERATION_MUTATION": 1, - "OPERATION_SUBSCRIPTION": 2, + "OPERATION_UNKNOWN": 0, + "OPERATION_QUERY": 1, + "OPERATION_MUTATION": 2, + "OPERATION_SUBSCRIPTION": 3, } ) @@ -724,12 +727,13 @@ type GraphQLStats struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Types map[string]*RepeatedFields `protobuf:"bytes,1,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,2,opt,name=OperationType,proto3,enum=normalproto.GraphQLOperations" json:"OperationType,omitempty"` - Variables string `protobuf:"bytes,3,opt,name=Variables,proto3" json:"Variables,omitempty"` - RootFields []string `protobuf:"bytes,4,rep,name=RootFields,proto3" json:"RootFields,omitempty"` - HasError bool `protobuf:"varint,5,opt,name=HasError,proto3" json:"HasError,omitempty"` - GraphErrors []string `protobuf:"bytes,6,rep,name=GraphErrors,proto3" json:"GraphErrors,omitempty"` + 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() { @@ -764,6 +768,13 @@ 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 @@ -775,7 +786,7 @@ func (x *GraphQLStats) GetOperationType() GraphQLOperations { if x != nil { return x.OperationType } - return GraphQLOperations_OPERATION_QUERY + return GraphQLOperations_OPERATION_UNKNOWN } func (x *GraphQLStats) GetVariables() string { @@ -964,39 +975,43 @@ var file_analytics_proto_rawDesc = []byte{ 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, 0xe3, 0x02, - 0x0a, 0x0c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x51, 0x4c, 0x53, 0x74, 0x61, 0x74, 0x73, 0x12, 0x3a, - 0x0a, 0x05, 0x54, 0x79, 0x70, 0x65, 0x73, 0x18, 0x01, 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, 0x02, 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, 0x03, 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, 0x04, 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, 0x05, 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, 0x06, 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, 0x5c, 0x0a, - 0x11, 0x47, 0x72, 0x61, 0x70, 0x68, 0x51, 0x4c, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x12, 0x13, 0x0a, 0x0f, 0x4f, 0x50, 0x45, 0x52, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x5f, - 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x00, 0x12, 0x16, 0x0a, 0x12, 0x4f, 0x50, 0x45, 0x52, 0x41, - 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x55, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x01, 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, 0x02, 0x42, 0x08, 0x5a, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 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 ( diff --git a/serializer/protobuf.go b/serializer/protobuf.go index a90e2ae45..c209aa9ec 100644 --- a/serializer/protobuf.go +++ b/serializer/protobuf.go @@ -93,7 +93,6 @@ func (pb *ProtobufSerializer) TransformSingleRecordToProto(rec analytics.Analyti } func (pb *ProtobufSerializer) TransformSingleProtoToAnalyticsRecord(rec analyticsproto.AnalyticsRecord, record *analytics.AnalyticsRecord) error { - tmpRecord := analytics.AnalyticsRecord{ Method: rec.Method, Host: rec.Host, @@ -146,6 +145,38 @@ func (pb *ProtobufSerializer) TransformSingleProtoToAnalyticsRecord(rec analytic ApiSchema: rec.ApiSchema, } tmpRecord.TimeStampFromProto(rec) + + // process anc convert graphql stats + operationType := analytics.Operation_Unknown + switch rec.GraphQLStats.OperationType { + case analyticsproto.GraphQLOperations_OPERATION_QUERY: + operationType = analytics.Operation_Query + case analyticsproto.GraphQLOperations_OPERATION_MUTATION: + operationType = analytics.Operation_Mutation + case analyticsproto.GraphQLOperations_OPERATION_SUBSCRIPTION: + operationType = analytics.Operation_Subscription + default: + operationType = analytics.Operation_Unknown + } + + 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{ + OperationType: operationType, + HasErrors: rec.GraphQLStats.HasError, + RootFields: rec.GraphQLStats.RootFields, + Types: types, + Variables: rec.GraphQLStats.Variables, + Errors: errors, + } + *record = tmpRecord return nil }