1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

chore: minor cleanup of project health and status (#8806)

This PR:
- conditionally deprecates the project health report endpoint. We only
use this for technical debt dashboard that we're removing. Now it's
deprecated once you turn the simplifiy flag on.
- extracts the calculate project health function into the project health
functions file in the appropriate domain folder. That same function is
now shared by the project health service and the project status service.

For the last point, it's a little outside of how we normally do things,
because it takes its stores as arguments, but it slots in well in that
file. An option would be to make a project health read model and then
wire that up in a couple places. It's more code, but probably closer to
how we do things in general. That said, I wanted to suggest this because
it's quick and easy (why do much work when little work do trick?).
This commit is contained in:
Thomas Heartman 2024-11-20 13:59:44 +01:00 committed by GitHub
parent 61df153a5b
commit a59a031362
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 27 deletions

View File

@ -1,6 +1,13 @@
import { hoursToMilliseconds } from 'date-fns';
import type { IProjectHealthReport } from '../../types';
import type { IFeatureType } from '../../types/stores/feature-type-store';
import type {
IFeatureToggleStore,
IProject,
IProjectHealthReport,
} from '../../types';
import type {
IFeatureType,
IFeatureTypeStore,
} from '../../types/stores/feature-type-store';
type IPartialFeatures = Array<{
stale?: boolean;
@ -58,3 +65,19 @@ export const calculateHealthRating = (
return rating;
};
export const calculateProjectHealthRating =
(
featureTypeStore: IFeatureTypeStore,
featureToggleStore: IFeatureToggleStore,
) =>
async ({ id }: Pick<IProject, 'id'>): Promise<number> => {
const featureTypes = await featureTypeStore.getAll();
const toggles = await featureToggleStore.getAll({
project: id,
archived: false,
});
return calculateHealthRating(toggles, featureTypes);
};

View File

@ -1,4 +1,4 @@
import { calculateHealthRating } from '../../domain/project-health/project-health';
import { calculateProjectHealthRating } from '../../domain/project-health/project-health';
import type { ProjectStatusSchema } from '../../openapi';
import type {
IApiTokenStore,
@ -52,17 +52,6 @@ export class ProjectStatusService {
this.featureToggleStore = featureToggleStore;
}
private async calculateHealthRating(projectId: string): Promise<number> {
const featureTypes = await this.featureTypeStore.getAll();
const toggles = await this.featureToggleStore.getAll({
project: projectId,
archived: false,
});
return calculateHealthRating(toggles, featureTypes);
}
async getProjectStatus(projectId: string): Promise<ProjectStatusSchema> {
const [
members,
@ -77,7 +66,10 @@ export class ProjectStatusService {
this.apiTokenStore.countProjectTokens(projectId),
this.segmentStore.getProjectSegmentCount(projectId),
this.eventStore.getProjectRecentEventActivity(projectId),
this.calculateHealthRating(projectId),
calculateProjectHealthRating(
this.featureTypeStore,
this.featureToggleStore,
)({ id: projectId }),
this.projectLifecycleSummaryReadModel.getProjectLifecycleSummary(
projectId,
),

View File

@ -42,6 +42,9 @@ export default class ProjectHealthReport extends Controller {
middleware: [
openApiService.validPath({
tags: ['Projects'],
deprecated: config.flagResolver.isEnabled(
'simplifyProjectOverview',
),
operationId: 'getProjectHealthReport',
summary: 'Get a health report for a project.',
description:

View File

@ -7,8 +7,8 @@ import type { IFeatureTypeStore } from '../types/stores/feature-type-store';
import type { IProjectStore } from '../features/project/project-store-type';
import type ProjectService from '../features/project/project-service';
import {
calculateHealthRating,
calculateProjectHealth,
calculateProjectHealthRating,
} from '../domain/project-health/project-health';
export default class ProjectHealthService {
@ -22,6 +22,8 @@ export default class ProjectHealthService {
private projectService: ProjectService;
calculateHealthRating: (project: IProject) => Promise<number>;
constructor(
{
projectStore,
@ -40,6 +42,10 @@ export default class ProjectHealthService {
this.featureToggleStore = featureToggleStore;
this.projectService = projectService;
this.calculateHealthRating = calculateProjectHealthRating(
this.featureTypeStore,
this.featureToggleStore,
);
}
async getProjectHealthReport(
@ -64,17 +70,6 @@ export default class ProjectHealthService {
};
}
async calculateHealthRating(project: IProject): Promise<number> {
const featureTypes = await this.featureTypeStore.getAll();
const toggles = await this.featureToggleStore.getAll({
project: project.id,
archived: false,
});
return calculateHealthRating(toggles, featureTypes);
}
async setHealthRating(): Promise<void> {
const projects = await this.projectStore.getAll();