Skip to content

Commit

Permalink
[EVOL]: add dateStart and dateEnd fields to AuditType and AuditModelType
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël AUBERT committed Feb 18, 2025
1 parent 76ecaab commit 9cc4b97
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import ServerConfig from '../commons/ServerConfig.ts';
import { AuditCommonsType } from './types/AuditCommonsType.ts';

const { forkWorker } = WorkerHelper;
const { getCurrentConfig } = ServerConfig;
const { currentConfig } = ServerConfig;

const startDevOpsAudit = async ({ applicationId }: AuditCommonsType) => {
try {
AppLogger.info('[DevOpsAuditorManager - startDevOpsAudit] applicationId: ', applicationId);

// Start audits in a worker thread to prevent blocking the main thread
const currentConfig = getCurrentConfig();
const workerConfig = {
...currentConfig,
applicationId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { auditStatus } from '@v6y/core-logic';
import { devOpsCategories, devOpsType } from '@v6y/core-logic/src/config/DevOpsConfig.ts';
import { describe, expect, it } from 'vitest';

import DoraMetricsUtils from './DoraMetricsUtils.ts';
Expand All @@ -19,79 +21,64 @@ describe('DoraMetricsUtils', () => {
expect(result).not.toBeNull();
const expectedResults = [
{
type: 'DORA_Metrics',
category: 'deployment_frequency',
status: 'info',
extraInfos:
'Number of deployments per day. Date range: ' +
mockDateRange.dateStart +
' - ' +
mockDateRange.dateEnd,
dateStart: new Date(mockDateRange.dateStart),
dateEnd: new Date(mockDateRange.dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.DEPLOYMENT_FREQUENCY,
status: auditStatus.info,
module: {
appId: 1,
},
score: 0.3333333333333333,
scoreUnit: 'deployments/day',
},
{
type: 'DORA_Metrics',
category: 'lead_review_time',
status: 'info',
extraInfos:
'Time between the opening and the merge of a MR. Date range: ' +
mockDateRange.dateStart +
' - ' +
mockDateRange.dateEnd,
dateStart: new Date(mockDateRange.dateStart),
dateEnd: new Date(mockDateRange.dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.LEAD_REVIEW_TIME,
status: auditStatus.info,
module: {
appId: 1,
},
score: 1.4602633333333332,
scoreUnit: 'hours',
},
{
category: 'lead_time_for_changes',
extraInfos:
'Time between the creation of a change and the deployment. Date range: ' +
mockDateRange.dateStart +
' - ' +
mockDateRange.dateEnd,
dateStart: new Date(mockDateRange.dateStart),
dateEnd: new Date(mockDateRange.dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.LEAD_TIME_FOR_CHANGES,
score: 1.493859074074074,
scoreUnit: 'hours',
status: auditStatus.info,
module: {
appId: 1,
},
score: 1.493859074074074,
scoreUnit: 'hours',
status: 'info',
type: 'DORA_Metrics',
},
{
extraInfos:
'Percentage of failed deployments. Date range: ' +
mockDateRange.dateStart +
' - ' +
mockDateRange.dateEnd,
category: 'change_failure_rate',
dateStart: new Date(mockDateRange.dateStart),
dateEnd: new Date(mockDateRange.dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.CHANGE_FAILURE_RATE,
module: {
appId: 1,
},
score: 0,
scoreUnit: 'percentage',
status: 'error',
type: 'DORA_Metrics',
status: auditStatus.error,
},
{
type: 'DORA_Metrics',
category: 'mean_time_to_restore_service',
status: 'error',
extraInfos:
'Time to restore service after a failure. Date range: ' +
mockDateRange.dateStart +
' - ' +
mockDateRange.dateEnd,
dateStart: new Date(mockDateRange.dateStart),
dateEnd: new Date(mockDateRange.dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.MEAN_TIME_TO_RESTORE_SERVICE,
status: auditStatus.error,
score: 0,
scoreUnit: 'hours',
module: {
appId: 1,
},
score: 0,
scoreUnit: 'hours',
},
];
expect(result).not.toBeNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppLogger, AuditType, Matcher, auditStatus } from '@v6y/core-logic';
import { devOpsCategories, devOpsType } from '@v6y/core-logic/src/config/DevOpsConfig.ts';

import {
DeploymentFrequencyParamsType,
Expand Down Expand Up @@ -29,7 +30,7 @@ const calculateDeploymentFrequency = ({

if (!deployments || deployments.length === 0) {
AppLogger.info(`[DoraMetricsUtils - calculateDeploymentFrequency] deployments is empty`);
return { status: 'failure', value: 0 };
return { status: auditStatus.error, value: 0 };
}

const start = new Date(dateStart);
Expand All @@ -45,7 +46,7 @@ const calculateDeploymentFrequency = ({
AppLogger.info(
`[DoraMetricsUtils - calculateDeploymentFrequency] no successful deployments in date range`,
);
return { status: 'failure', value: 0 };
return { status: auditStatus.error, value: 0 };
}

const timePeriod = (end.getTime() - start.getTime()) / (MSTOHOURS * 24);
Expand Down Expand Up @@ -88,7 +89,7 @@ const calculateLeadReviewTime = ({

if (!mergeRequests || mergeRequests.length === 0) {
AppLogger.info(`[DoraMetricsUtils - calculateLeadReviewTime] mergeRequests is empty`);
return { status: 'failure', value: 0 };
return { status: auditStatus.error, value: 0 };
}

const start = new Date(dateStart);
Expand Down Expand Up @@ -153,7 +154,7 @@ const calculateLeadTimeForChanges = ({
AppLogger.info(
`[DoraMetricsUtils - calculateLeadTimeForChanges] deployments or leadReviewTime is empty`,
);
return { status: 'failure', value: 0 };
return { status: auditStatus.error, value: 0 };
}

const start = new Date(dateStart);
Expand Down Expand Up @@ -216,7 +217,7 @@ const calculateChangeFailureRate = (): DoraMetricType => {
)
.otherwise(() => auditStatus.warning); // Above 30%

status = 'error';
status = auditStatus.error;

return { status: status as string, value };
};
Expand All @@ -233,19 +234,19 @@ const calculateMeanTimeToRestoreService = (): DoraMetricType => {
let status = Matcher()
.on(
() => value < 1,
() => 'success', // Elite Performers: Less than 1 hour
() => auditStatus.success, // Elite Performers: Less than 1 hour
)
.on(
() => value < 24,
() => 'info', // High Performers: Less than 1 day
() => auditStatus.info, // High Performers: Less than 1 day
)
.on(
() => value < 24 * 7,
() => 'warning', // Medium Performers: 1 day to 1 week
() => auditStatus.warning, // Medium Performers: 1 day to 1 week
)
.otherwise(() => 'warning'); // Low Performers: Over 6 months
.otherwise(() => auditStatus.warning); // Low Performers: Over 6 months

status = 'error';
status = auditStatus.error;

return { status: status as string, value };
};
Expand Down Expand Up @@ -278,8 +279,8 @@ const analyseDoraMetrics = ({
});

const leadTimeForChanges =
leadReviewTime.status === 'failure'
? { status: 'failure', value: 0 }
leadReviewTime.status === auditStatus.error
? { status: auditStatus.error, value: 0 }
: calculateLeadTimeForChanges({
leadReviewTime: leadReviewTime.value,
deployments,
Expand All @@ -292,73 +293,65 @@ const analyseDoraMetrics = ({
const auditReports: AuditType[] = [];

auditReports.push({
type: 'DORA_Metrics',
category: 'deployment_frequency',
dateStart: new Date(dateStart),
dateEnd: new Date(dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.DEPLOYMENT_FREQUENCY,
status: deploymentFrequency.status,
score: deploymentFrequency.value,
scoreUnit: 'deployments/day',
extraInfos: 'Number of deployments per day. Date range: ' + dateStart + ' - ' + dateEnd,
module: {
appId: application?._id,
},
});

auditReports.push({
type: 'DORA_Metrics',
category: 'lead_review_time',
dateStart: new Date(dateStart),
dateEnd: new Date(dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.LEAD_REVIEW_TIME,
status: leadReviewTime.status,
score: leadReviewTime.value,
scoreUnit: 'hours',
extraInfos:
'Time between the opening and the merge of a MR. Date range: ' +
dateStart +
' - ' +
dateEnd,
module: {
appId: application?._id,
},
});

auditReports.push({
type: 'DORA_Metrics',
category: 'lead_time_for_changes',
dateStart: new Date(dateStart),
dateEnd: new Date(dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.LEAD_TIME_FOR_CHANGES,
status: leadTimeForChanges.status,
score: leadTimeForChanges.value,
scoreUnit: 'hours',
extraInfos:
'Time between the creation of a change and the deployment. Date range: ' +
dateStart +
' - ' +
dateEnd,
module: {
appId: application?._id,
},
});

auditReports.push({
type: 'DORA_Metrics',
category: 'change_failure_rate',
dateStart: new Date(dateStart),
dateEnd: new Date(dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.CHANGE_FAILURE_RATE,
status: changeFailureRate.status,
score: changeFailureRate.value,
scoreUnit: 'percentage',
extraInfos:
'Percentage of failed deployments. Date range: ' + dateStart + ' - ' + dateEnd,
module: {
appId: application?._id,
},
});

auditReports.push({
type: 'DORA_Metrics',
category: 'mean_time_to_restore_service',
dateStart: new Date(dateStart),
dateEnd: new Date(dateEnd),
type: devOpsType.DORA,
category: devOpsCategories.MEAN_TIME_TO_RESTORE_SERVICE,
status: meanTimeToRestoreService.status,
score: meanTimeToRestoreService.value,
scoreUnit: 'hours',
extraInfos:
'Time to restore service after a failure. Date range: ' +
dateStart +
' - ' +
dateEnd,
module: {
appId: application?._id,
},
Expand Down
Loading

0 comments on commit 9cc4b97

Please sign in to comment.