fix(API): Insights - round failure rate to 3 decimals (#14325)

This commit is contained in:
Guillaume Jacquart
2025-04-01 17:23:08 +02:00
committed by GitHub
parent 08450b20af
commit cf37ee3ced
3 changed files with 8 additions and 8 deletions

View File

@@ -58,7 +58,7 @@ describe('InsightsController', () => {
expect(response).toEqual({ expect(response).toEqual({
total: { deviation: null, unit: 'count', value: 30 }, total: { deviation: null, unit: 'count', value: 30 },
failed: { deviation: null, unit: 'count', value: 10 }, 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 }, averageRunTime: { deviation: null, unit: 'time', value: 10 },
timeSaved: { deviation: null, unit: 'time', value: 10 }, timeSaved: { deviation: null, unit: 'time', value: 10 },
}); });
@@ -84,7 +84,7 @@ describe('InsightsController', () => {
expect(response).toEqual({ expect(response).toEqual({
total: { deviation: 10, unit: 'count', value: 30 }, total: { deviation: 10, unit: 'count', value: 30 },
failed: { deviation: 6, unit: 'count', value: 10 }, 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 }, averageRunTime: { deviation: 300 / 30 - 40 / 20, unit: 'time', value: 10 },
timeSaved: { deviation: 5, unit: 'time', value: 10 }, timeSaved: { deviation: 5, unit: 'time', value: 10 },
}); });

View File

@@ -754,7 +754,7 @@ describe('getInsightsSummary', () => {
}); });
await createCompactedInsightsEvent(workflow, { await createCompactedInsightsEvent(workflow, {
type: 'failure', type: 'failure',
value: 2, value: 1,
periodUnit: 'day', periodUnit: 'day',
periodStart: DateTime.utc(), periodStart: DateTime.utc(),
}); });
@@ -778,10 +778,10 @@ describe('getInsightsSummary', () => {
// ASSERT // ASSERT
expect(summary).toEqual({ expect(summary).toEqual({
averageRunTime: { deviation: -123, unit: 'time', value: 0 }, averageRunTime: { deviation: -123, unit: 'time', value: 0 },
failed: { deviation: 2, unit: 'count', value: 2 }, failed: { deviation: 1, unit: 'count', value: 1 },
failureRate: { deviation: 0.5, unit: 'ratio', value: 0.5 }, failureRate: { deviation: 0.333, unit: 'ratio', value: 0.333 },
timeSaved: { deviation: 0, unit: 'time', value: 0 }, timeSaved: { deviation: 0, unit: 'time', value: 0 },
total: { deviation: 3, unit: 'count', value: 4 }, total: { deviation: 2, unit: 'count', value: 3 },
}); });
}); });

View File

@@ -250,9 +250,9 @@ export class InsightsService {
const previousTotal = previousSuccesses + previousFailures; const previousTotal = previousSuccesses + previousFailures;
const currentFailureRate = const currentFailureRate =
currentTotal > 0 ? Math.round((currentFailures / currentTotal) * 100) / 100 : 0; currentTotal > 0 ? Math.round((currentFailures / currentTotal) * 1000) / 1000 : 0;
const previousFailureRate = 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 currentTotalRuntime = getValueByType('current', 'runtime_ms') ?? 0;
const previousTotalRuntime = getValueByType('previous', 'runtime_ms') ?? 0; const previousTotalRuntime = getValueByType('previous', 'runtime_ms') ?? 0;