Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion apps/api/src/app/metrics/resolvers/dora-metrics.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export default /* GraphQL */ `
"The lead time in milliseconds for the current period"
currentAmount: BigInt!

"The date range for the current period"
currentPeriod: DateTimeRangeValue!

"The date range for the previous period"
previousPeriod: DateTimeRangeValue!

"The lead time in milliseconds before the current period"
previousAmount: BigInt!

Expand All @@ -47,12 +53,55 @@ export default /* GraphQL */ `

"The amounts over time for the chart"
data: [BigInt!]!

"Breakdown of lead time by development stages"
breakdown: LeadTimeBreakdown!
}

type LeadTimeBreakdown {
"Time spent coding (first commit to PR creation)"
codingTime: BreakdownStage!

"The date range for the current period"
currentPeriod: DateTimeRangeValue!

"The date range for the previous period"
previousPeriod: DateTimeRangeValue!

"Time waiting for first review"
timeToFirstReview: BreakdownStage!

"Time from first review to approval"
timeToApprove: BreakdownStage!

"Time from approval to merge"
timeToMerge: BreakdownStage!

"Time from merge to deploy"
timeToDeploy: BreakdownStage!
}

type BreakdownStage {
"Average time in milliseconds for current period"
currentAmount: BigInt!

"Average time in milliseconds for previous period"
previousAmount: BigInt!

"Percentage change from previous period"
change: Float!
}

type ChangeFailureRateMetric {
"The change failure rate for the current period"
currentAmount: Float!

"The date range for the current period"
currentPeriod: DateTimeRangeValue!

"The date range for the previous period"
previousPeriod: DateTimeRangeValue!

"The change failure rate before the current period"
previousAmount: Float!

Expand All @@ -63,13 +112,19 @@ export default /* GraphQL */ `
columns: [DateTime!]!

"The amounts over time for the chart"
data: [BigInt!]!
data: [Float!]!
}

type DeploymentFrequencyMetric {
"The amount of deployments for the current period"
currentAmount: BigInt!

"The date range for the current period"
currentPeriod: DateTimeRangeValue!

"The date range for the previous period"
previousPeriod: DateTimeRangeValue!

"The average number of deployments per day"
avg: Float!

Expand All @@ -90,6 +145,12 @@ export default /* GraphQL */ `
"The mean time to recover in milliseconds for the current period"
currentAmount: BigInt!

"The date range for the current period"
currentPeriod: DateTimeRangeValue!

"The date range for the previous period"
previousPeriod: DateTimeRangeValue!

"The mean time to recover in milliseconds before the current period"
previousAmount: BigInt!

Expand Down
15 changes: 10 additions & 5 deletions apps/api/src/app/metrics/resolvers/queries/dora-metrics.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { createFieldResolver } from "../../../../lib/graphql";
import { logger } from "../../../../lib/logger";
import { ResourceNotFoundException } from "../../../errors/exceptions/resource-not-found.exception";
import {
getLeadTimeMetric,
getChangeFailureRateMetric,
getDeploymentFrequencyMetric,
getLeadTimeMetric,
getMeanTimeToRecoverMetric,
} from "../../services/dora-metrics.service";
import {
transformLeadTimeMetric,
transformChangeFailureRateMetric,
transformDeploymentFrequencyMetric,
transformLeadTimeMetric,
transformMeanTimeToRecoverMetric,
} from "../transformers/dora-metrics.transformer";

Expand All @@ -26,7 +26,7 @@ export const doraMetricsQuery = createFieldResolver("DoraMetrics", {
throw new ResourceNotFoundException("Workspace not found");
}

const result = await getLeadTimeMetric({
const filters = {
workspaceId: context.workspaceId,
dateRange: {
from: input.dateRange.from ?? thirtyDaysAgo().toISOString(),
Expand All @@ -37,9 +37,14 @@ export const doraMetricsQuery = createFieldResolver("DoraMetrics", {
applicationIds: input.applicationIds ?? undefined,
environmentIds: input.environmentIds ?? undefined,
repositoryIds: input.repositoryIds ?? undefined,
});
};

const result = await getLeadTimeMetric(filters);

return transformLeadTimeMetric(result);
return {
...transformLeadTimeMetric(result),
doraFilters: filters,
};
},
changeFailureRate: async (_, { input }, context) => {
logger.info("query.metrics.dora.changeFailureRate", {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createFieldResolver } from "../../../../lib/graphql";
import { logger } from "../../../../lib/logger";
import { getLeadTimeBreakdown } from "../../services/lead-time-breakdown.service";
import { GetLeadTimeBreakdownArgs } from "../../services/lead-time-breakdown.types";
import { transformLeadTimeBreakdown } from "../transformers/lead-time-breakdown.transformer";

export const leadTimeBreakdownQuery = createFieldResolver("LeadTimeMetric", {
breakdown: async (parent, _, context) => {
logger.info("query.metrics.dora.leadTime.breakdown", {
workspaceId: context.workspaceId,
});

const args = parent["doraFilters"] as GetLeadTimeBreakdownArgs;
const result = await getLeadTimeBreakdown(args);

return transformLeadTimeBreakdown(result);
},
});
Original file line number Diff line number Diff line change
@@ -1,45 +1,77 @@
import {
LeadTimeMetric,
ChangeFailureRateMetric,
DeploymentFrequencyMetric,
LeadTimeMetric,
MeanTimeToRecoverMetric,
} from "../../../../graphql-types";

export const transformLeadTimeMetric = (
metric: LeadTimeMetric
): LeadTimeMetric => {
metric: Omit<LeadTimeMetric, "breakdown">
): Omit<LeadTimeMetric, "breakdown"> => {
return {
...metric,
change: parseFloat(metric.change.toFixed(2)),
currentPeriod: {
from: metric.currentPeriod.from,
to: metric.currentPeriod.to,
},
previousPeriod: {
from: metric.previousPeriod.from,
to: metric.previousPeriod.to,
},
};
};

export const transformChangeFailureRateMetric = (
metric: ChangeFailureRateMetric
): ChangeFailureRateMetric => {
metric: Omit<ChangeFailureRateMetric, "breakdown">
): Omit<ChangeFailureRateMetric, "breakdown"> => {
return {
...metric,
currentAmount: parseFloat(metric.currentAmount.toFixed(2)),
previousAmount: parseFloat(metric.previousAmount.toFixed(2)),
change: parseFloat(metric.change.toFixed(1)),
change: parseFloat(metric.change.toFixed(2)),
currentPeriod: {
from: metric.currentPeriod.from,
to: metric.currentPeriod.to,
},
previousPeriod: {
from: metric.previousPeriod.from,
to: metric.previousPeriod.to,
},
};
};

export const transformDeploymentFrequencyMetric = (
metric: DeploymentFrequencyMetric
): DeploymentFrequencyMetric => {
metric: Omit<DeploymentFrequencyMetric, "breakdown">
): Omit<DeploymentFrequencyMetric, "breakdown"> => {
return {
...metric,
avg: parseFloat(metric.avg.toFixed(2)),
change: parseFloat(metric.change.toFixed(2)),
currentPeriod: {
from: metric.currentPeriod.from,
to: metric.currentPeriod.to,
},
previousPeriod: {
from: metric.previousPeriod.from,
to: metric.previousPeriod.to,
},
};
};

export const transformMeanTimeToRecoverMetric = (
metric: MeanTimeToRecoverMetric
): MeanTimeToRecoverMetric => {
metric: Omit<MeanTimeToRecoverMetric, "breakdown">
): Omit<MeanTimeToRecoverMetric, "breakdown"> => {
return {
...metric,
change: parseFloat(metric.change.toFixed(2)),
currentPeriod: {
from: metric.currentPeriod.from,
to: metric.currentPeriod.to,
},
previousPeriod: {
from: metric.previousPeriod.from,
to: metric.previousPeriod.to,
},
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { BreakdownStage, LeadTimeBreakdown } from "../../../../graphql-types";
import {
LeadTimeBreakdownResult,
StageResult,
} from "../../services/lead-time-breakdown.types";

const transformStage = (stage: StageResult): BreakdownStage => {
return {
currentAmount: stage.currentAmount,
previousAmount: stage.previousAmount,
change: parseFloat(stage.change.toFixed(2)),
};
};

export const transformLeadTimeBreakdown = (
breakdown: LeadTimeBreakdownResult
): LeadTimeBreakdown => {
return {
codingTime: transformStage(breakdown.codingTime),
timeToFirstReview: transformStage(breakdown.timeToFirstReview),
timeToApprove: transformStage(breakdown.timeToApprove),
timeToMerge: transformStage(breakdown.timeToMerge),
timeToDeploy: transformStage(breakdown.timeToDeploy),
currentPeriod: {
from: breakdown.currentPeriod.from,
to: breakdown.currentPeriod.to,
},
previousPeriod: {
from: breakdown.previousPeriod.from,
to: breakdown.previousPeriod.to,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -1032,8 +1032,8 @@ describe("DORA Metrics", () => {
expect(result.currentAmount).toBeCloseTo(10, 1);
// Previous: 20% (2/10)
expect(result.previousAmount).toBeCloseTo(20, 1);
// Change: (10 - 20) / 20 * 100 = -50% (improvement)
expect(result.change).toBeCloseTo(-50, 1);
// Change: 10 - 20 = -10 percentage points (improvement)
expect(result.change).toBeCloseTo(-10, 1);
});

it("handles 100% failure rate correctly", async () => {
Expand Down
Loading
Loading