@@ -37,14 +37,14 @@ export class BreakingSchemaChangeUsageHelper {
3737 return {
3838 topAffectedOperations : schemaChange . usageStatistics . topAffectedOperations . map ( operation => {
3939 // Note:
40- // "metadata.usage.totalRequestCount" is sometimes 0 in case of a integration test
41- // causing a zero devision and GraphQL exception,
42- // because we aggressively poll for the schema change after publishing usage data
43- // it seems like clickhouse slighty lags behind for the materialized view here.
44- // since it only happens in context of an integration test (no production issues )
45- // we can safely treat 0 as 1 request.
46- const totalRequestCount = Math . max ( 1 , metadata . usage . totalRequestCount ) ;
47- const percentage = ( operation . count / totalRequestCount ) * 100 ;
40+ // "metadata.usage.totalRequestCount" is sometimes 0/NaN in integration tests
41+ // due to ClickHouse eventual consistency lag.
42+ // We ensure the percentage is always a finite number to avoid GraphQL serialization errors.
43+ const totalRequestCount = Number . isFinite ( metadata . usage . totalRequestCount )
44+ ? Math . max ( 1 , metadata . usage . totalRequestCount )
45+ : 1 ;
46+ const count = Number . isFinite ( operation . count ) ? operation . count : 0 ;
47+ const percentage = ( count / totalRequestCount ) * 100 ;
4848 return {
4949 ...operation ,
5050 percentage,
@@ -53,18 +53,18 @@ export class BreakingSchemaChangeUsageHelper {
5353 } ) ,
5454 topAffectedClients : schemaChange . usageStatistics . topAffectedClients . map ( client => {
5555 // Note:
56- // "metadata.usage.totalRequestCount" is sometimes 0 in case of a integration test
57- // causing a zero devision and GraphQL exception,
58- // because we aggressively poll for the schema change after publishing usage data
59- // it seems like clickhouse slighty lags behind for the materialized view here.
60- // since it only happens in context of an integration test (no production issues )
61- // we can safely treat 0 as 1 request.
62- const totalRequestCount = Math . max ( 1 , metadata . usage . totalRequestCount ) ;
63- const percentage = ( client . count / totalRequestCount ) * 100 ;
56+ // "metadata.usage.totalRequestCount" is sometimes 0/NaN in integration tests
57+ // due to ClickHouse eventual consistency lag.
58+ // We ensure the percentage is always a finite number to avoid GraphQL serialization errors.
59+ const totalRequestCount = Number . isFinite ( metadata . usage . totalRequestCount )
60+ ? Math . max ( 1 , metadata . usage . totalRequestCount )
61+ : 1 ;
62+ const count = Number . isFinite ( client . count ) ? client . count : 0 ;
63+ const percentage = ( count / totalRequestCount ) * 100 ;
6464
6565 return {
6666 ...client ,
67- countFormatted : formatNumber ( client . count ) ,
67+ countFormatted : formatNumber ( count ) ,
6868 percentage,
6969 percentageFormatted : formatPercentage ( percentage ) ,
7070 } ;
0 commit comments