diff --git a/packages/apollo-engine-reporting-protobuf/src/reports.proto b/packages/apollo-engine-reporting-protobuf/src/reports.proto index 0c6bc319d78..c2284cc480c 100644 --- a/packages/apollo-engine-reporting-protobuf/src/reports.proto +++ b/packages/apollo-engine-reporting-protobuf/src/reports.proto @@ -4,6 +4,12 @@ package mdg.engine.proto; import "google/protobuf/timestamp.proto"; +import "google/protobuf/descriptor.proto"; + +extend google.protobuf.FieldOptions { + bool js_use_toArray = 50505; +} + message Trace { message CachePolicy { enum Scope { @@ -284,16 +290,16 @@ message PathErrorStats { } message QueryLatencyStats { - repeated int64 latency_count = 1; + repeated int64 latency_count = 1 [(js_use_toArray)=true]; uint64 request_count = 2; uint64 cache_hits = 3; uint64 persisted_query_hits = 4; uint64 persisted_query_misses = 5; - repeated int64 cache_latency_count = 6; + repeated int64 cache_latency_count = 6 [(js_use_toArray)=true]; PathErrorStats root_error_stats = 7; uint64 requests_with_errors_count = 8; - repeated int64 public_cache_ttl_count = 9; - repeated int64 private_cache_ttl_count = 10; + repeated int64 public_cache_ttl_count = 9 [(js_use_toArray)=true]; + repeated int64 private_cache_ttl_count = 10 [(js_use_toArray)=true]; uint64 registered_operation_count = 11; uint64 forbidden_operation_count = 12; } diff --git a/packages/apollo-engine-reporting/src/ContextualizedStats.ts b/packages/apollo-engine-reporting/src/ContextualizedStats.ts index 1f5e7bbb191..1efdfdc882d 100644 --- a/packages/apollo-engine-reporting/src/ContextualizedStats.ts +++ b/packages/apollo-engine-reporting/src/ContextualizedStats.ts @@ -6,6 +6,8 @@ import { ContextualizedStats as ContextualizedStatsProto, ITypeStat as TypeStatProto, IFieldStat as FieldStatProto, + IQueryLatencyStats, + QueryLatencyStats, } from 'apollo-engine-reporting-protobuf'; export interface FieldStat { @@ -15,22 +17,6 @@ export interface FieldStat { requestsWithErrorsCount: number; latencyCount: DurationHistogram; } - -export interface QueryLatencyStats { - readonly latencyCount: DurationHistogram; - requestCount: number; - cacheHits: number; - persistedQueryHits: number; - persistedQueryMisses: number; - readonly cacheLatencyCount: DurationHistogram; - readonly rootErrorStats: IPathErrorStats; - requestsWithErrorCount: number; - readonly publicCacheTtlCount: DurationHistogram; - readonly privateCacheTtlCount: DurationHistogram; - registeredOperationCount: number; - forbiddenOperationCount: number; -} - export class ContextualizedStats { statsContext: IStatsContext; queryLatencyStats: QueryLatencyStats; @@ -41,7 +27,7 @@ export class ContextualizedStats { constructor(statsContext: IStatsContext) { this.statsContext = statsContext; - this.queryLatencyStats = { + this.queryLatencyStats = new QueryLatencyStats({ latencyCount: new DurationHistogram(), requestCount: 0, cacheHits: 0, @@ -54,10 +40,11 @@ export class ContextualizedStats { privateCacheTtlCount: new DurationHistogram(), registeredOperationCount: 0, forbiddenOperationCount: 0, - }; + }); } public addTrace(trace: Trace) { + const queryLatencyStats = this.queryLatencyStats; queryLatencyStats.requestCount++; if (trace.fullQueryCacheHit) {