Skip to content

Commit 12378d5

Browse files
authored
fix integration test failing due to zero division (#7312)
1 parent b909237 commit 12378d5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/services/api/src/modules/schema/providers/breaking-schema-changes-helper.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,31 @@ export class BreakingSchemaChangeUsageHelper {
3636

3737
return {
3838
topAffectedOperations: schemaChange.usageStatistics.topAffectedOperations.map(operation => {
39-
const percentage = (operation.count / metadata.usage.totalRequestCount) * 100;
39+
// 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;
4048
return {
4149
...operation,
4250
percentage,
4351
targetIds: metadata.settings.targets.map(target => target.id),
4452
};
4553
}),
4654
topAffectedClients: schemaChange.usageStatistics.topAffectedClients.map(client => {
47-
const percentage = (client.count / metadata.usage.totalRequestCount) * 100;
55+
// 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;
4864

4965
return {
5066
...client,

0 commit comments

Comments
 (0)