mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
1-3121: fix wrong counting for unhealthy flags (#8772)
This PR fixes the counting of unhealthy flags for the project status page. The issue was that we were looking for `archived = false`, but we don't set that flag in the db anymore. Instead, we set the `archived_at` date, which should be null if the flag is unarchived.
This commit is contained in:
parent
ec44c5b5e4
commit
20749cf771
@ -7,7 +7,8 @@ export class ProjectStaleFlagsReadModel implements IProjectStaleFlagsReadModel {
|
|||||||
async getStaleFlagCountForProject(projectId: string): Promise<number> {
|
async getStaleFlagCountForProject(projectId: string): Promise<number> {
|
||||||
const result = await this.db('features')
|
const result = await this.db('features')
|
||||||
.count()
|
.count()
|
||||||
.where({ project: projectId, archived: false })
|
.whereNull('archived_at')
|
||||||
|
.where({ project: projectId })
|
||||||
.where((builder) =>
|
.where((builder) =>
|
||||||
builder
|
builder
|
||||||
.orWhere({ stale: true })
|
.orWhere({ stale: true })
|
||||||
|
@ -264,36 +264,46 @@ test('project status includes stale flags', async () => {
|
|||||||
{} as IUser,
|
{} as IUser,
|
||||||
{} as IAuditUser,
|
{} as IAuditUser,
|
||||||
);
|
);
|
||||||
const createFlagInState = async (
|
|
||||||
name: string,
|
|
||||||
state?: Object,
|
|
||||||
projectId?: string,
|
|
||||||
) => {
|
|
||||||
await app.createFeature(name, projectId);
|
|
||||||
if (state) {
|
|
||||||
await db.rawDatabase('features').update(state).where({ name });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
await createFlagInState('stale-flag', { stale: true });
|
function cartesianProduct(...arrays: any[][]): any[][] {
|
||||||
await createFlagInState('potentially-stale-flag', {
|
return arrays.reduce(
|
||||||
potentially_stale: true,
|
(acc, array) => {
|
||||||
});
|
return acc.flatMap((accItem) =>
|
||||||
await createFlagInState('potentially-stale-and-stale-flag', {
|
array.map((item) => [...accItem, item]),
|
||||||
potentially_stale: true,
|
);
|
||||||
stale: true,
|
},
|
||||||
});
|
[[]] as any[][],
|
||||||
await createFlagInState('non-stale-flag');
|
);
|
||||||
await createFlagInState('archived-stale-flag', {
|
}
|
||||||
archived: true,
|
|
||||||
stale: true,
|
// of all 16 (2^4) permutations, only 3 are unhealthy flags in a given project.
|
||||||
});
|
const combinations = cartesianProduct(
|
||||||
await createFlagInState(
|
[false, true], // stale
|
||||||
'stale-other-project',
|
[false, true], // potentially stale
|
||||||
{ stale: true },
|
[false, true], // archived
|
||||||
otherProject.id,
|
['default', otherProject.id], // project
|
||||||
);
|
);
|
||||||
|
|
||||||
|
for (const [stale, potentiallyStale, archived, project] of combinations) {
|
||||||
|
const name = `flag-${project}-stale-${stale}-potentially-stale-${potentiallyStale}-archived-${archived}`;
|
||||||
|
await app.createFeature(
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
stale,
|
||||||
|
},
|
||||||
|
project,
|
||||||
|
);
|
||||||
|
if (potentiallyStale) {
|
||||||
|
await db
|
||||||
|
.rawDatabase('features')
|
||||||
|
.update('potentially_stale', true)
|
||||||
|
.where({ name });
|
||||||
|
}
|
||||||
|
if (archived) {
|
||||||
|
await app.archiveFeature(name, project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { body } = await app.request
|
const { body } = await app.request
|
||||||
.get('/api/admin/projects/default/status')
|
.get('/api/admin/projects/default/status')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
|
Loading…
Reference in New Issue
Block a user