From cf37ee3cedb60dc9bbf6c87c7f6212213c93c61e Mon Sep 17 00:00:00 2001 From: Guillaume Jacquart Date: Tue, 1 Apr 2025 17:23:08 +0200 Subject: [PATCH] fix(API): Insights - round failure rate to 3 decimals (#14325) --- .../insights/__tests__/insights.controller.test.ts | 4 ++-- .../modules/insights/__tests__/insights.service.test.ts | 8 ++++---- packages/cli/src/modules/insights/insights.service.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/modules/insights/__tests__/insights.controller.test.ts b/packages/cli/src/modules/insights/__tests__/insights.controller.test.ts index ffe2b630bf..6d1b66c86e 100644 --- a/packages/cli/src/modules/insights/__tests__/insights.controller.test.ts +++ b/packages/cli/src/modules/insights/__tests__/insights.controller.test.ts @@ -58,7 +58,7 @@ describe('InsightsController', () => { expect(response).toEqual({ total: { deviation: null, unit: 'count', value: 30 }, failed: { deviation: null, unit: 'count', value: 10 }, - failureRate: { deviation: null, unit: 'ratio', value: 0.33 }, + failureRate: { deviation: null, unit: 'ratio', value: 0.333 }, averageRunTime: { deviation: null, unit: 'time', value: 10 }, timeSaved: { deviation: null, unit: 'time', value: 10 }, }); @@ -84,7 +84,7 @@ describe('InsightsController', () => { expect(response).toEqual({ total: { deviation: 10, unit: 'count', value: 30 }, failed: { deviation: 6, unit: 'count', value: 10 }, - failureRate: { deviation: 0.33 - 0.2, unit: 'ratio', value: 0.33 }, + failureRate: { deviation: 0.333 - 0.2, unit: 'ratio', value: 0.333 }, averageRunTime: { deviation: 300 / 30 - 40 / 20, unit: 'time', value: 10 }, timeSaved: { deviation: 5, unit: 'time', value: 10 }, }); diff --git a/packages/cli/src/modules/insights/__tests__/insights.service.test.ts b/packages/cli/src/modules/insights/__tests__/insights.service.test.ts index 5796ed0945..26c31224d3 100644 --- a/packages/cli/src/modules/insights/__tests__/insights.service.test.ts +++ b/packages/cli/src/modules/insights/__tests__/insights.service.test.ts @@ -754,7 +754,7 @@ describe('getInsightsSummary', () => { }); await createCompactedInsightsEvent(workflow, { type: 'failure', - value: 2, + value: 1, periodUnit: 'day', periodStart: DateTime.utc(), }); @@ -778,10 +778,10 @@ describe('getInsightsSummary', () => { // ASSERT expect(summary).toEqual({ averageRunTime: { deviation: -123, unit: 'time', value: 0 }, - failed: { deviation: 2, unit: 'count', value: 2 }, - failureRate: { deviation: 0.5, unit: 'ratio', value: 0.5 }, + failed: { deviation: 1, unit: 'count', value: 1 }, + failureRate: { deviation: 0.333, unit: 'ratio', value: 0.333 }, timeSaved: { deviation: 0, unit: 'time', value: 0 }, - total: { deviation: 3, unit: 'count', value: 4 }, + total: { deviation: 2, unit: 'count', value: 3 }, }); }); diff --git a/packages/cli/src/modules/insights/insights.service.ts b/packages/cli/src/modules/insights/insights.service.ts index d2838b1eb2..1445998ec4 100644 --- a/packages/cli/src/modules/insights/insights.service.ts +++ b/packages/cli/src/modules/insights/insights.service.ts @@ -250,9 +250,9 @@ export class InsightsService { const previousTotal = previousSuccesses + previousFailures; const currentFailureRate = - currentTotal > 0 ? Math.round((currentFailures / currentTotal) * 100) / 100 : 0; + currentTotal > 0 ? Math.round((currentFailures / currentTotal) * 1000) / 1000 : 0; const previousFailureRate = - previousTotal > 0 ? Math.round((previousFailures / previousTotal) * 100) / 100 : 0; + previousTotal > 0 ? Math.round((previousFailures / previousTotal) * 1000) / 1000 : 0; const currentTotalRuntime = getValueByType('current', 'runtime_ms') ?? 0; const previousTotalRuntime = getValueByType('previous', 'runtime_ms') ?? 0;