Skip to content

Commit

Permalink
[TT-9476]: add graphstats to analytics record proto (#736)
Browse files Browse the repository at this point in the history
* addgraphstats to analytics record proto

* added proto to go serializer

* add serializer

* some changes to conditional addition of graphql stats

* ran go imports

* fix ci
  • Loading branch information
kofoworola authored Oct 30, 2023
1 parent ee98014 commit 9984a1e
Show file tree
Hide file tree
Showing 4 changed files with 453 additions and 71 deletions.
22 changes: 21 additions & 1 deletion analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"`
Expand Down
22 changes: 22 additions & 0 deletions analytics/analytics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ message AnalyticsRecord {
string OauthID = 29;
string TimeZone = 30;
string ApiSchema = 31;
GraphQLStats GraphQLStats = 32;
}

message Latency {
Expand Down Expand Up @@ -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<string, RepeatedFields> 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;
}
Loading

0 comments on commit 9984a1e

Please sign in to comment.