mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-29 01:15:48 +02:00
fix: ft overview last seen at (#5212)
Fixes an issue where the query in the feature toggle overview would return excess rows
This commit is contained in:
parent
b69f275372
commit
28c72ec957
@ -343,11 +343,17 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
|
|||||||
let selectColumns = ['features_view.*'] as (string | Raw<any>)[];
|
let selectColumns = ['features_view.*'] as (string | Raw<any>)[];
|
||||||
|
|
||||||
if (this.flagResolver.isEnabled('useLastSeenRefactor')) {
|
if (this.flagResolver.isEnabled('useLastSeenRefactor')) {
|
||||||
query.leftJoin(
|
query.leftJoin('last_seen_at_metrics', function () {
|
||||||
'last_seen_at_metrics',
|
this.on(
|
||||||
'last_seen_at_metrics.environment',
|
'last_seen_at_metrics.environment',
|
||||||
'features_view.environment_name',
|
'=',
|
||||||
);
|
'features_view.environment_name',
|
||||||
|
).andOn(
|
||||||
|
'last_seen_at_metrics.feature_name',
|
||||||
|
'=',
|
||||||
|
'features_view.name',
|
||||||
|
);
|
||||||
|
});
|
||||||
// Override feature view for now
|
// Override feature view for now
|
||||||
selectColumns.push(
|
selectColumns.push(
|
||||||
'last_seen_at_metrics.last_seen_at as env_last_seen_at',
|
'last_seen_at_metrics.last_seen_at as env_last_seen_at',
|
||||||
|
@ -154,3 +154,53 @@ test('response should include last seen at per environment for multiple environm
|
|||||||
expect(production.name).toBe('production');
|
expect(production.name).toBe('production');
|
||||||
expect(production.lastSeenAt).toEqual('2023-10-01T12:34:56.000Z');
|
expect(production.lastSeenAt).toEqual('2023-10-01T12:34:56.000Z');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('response should include last seen at per environment correctly for a single toggle /api/admin/project/:projectId/features/:featureName', async () => {
|
||||||
|
const featureName = 'multiple-environment-last-seen-at-single-toggle';
|
||||||
|
await app.createFeature(featureName);
|
||||||
|
await setupLastSeenAtTest(`${featureName}1`);
|
||||||
|
await setupLastSeenAtTest(`${featureName}2`);
|
||||||
|
await setupLastSeenAtTest(`${featureName}3`);
|
||||||
|
await setupLastSeenAtTest(`${featureName}4`);
|
||||||
|
await setupLastSeenAtTest(`${featureName}5`);
|
||||||
|
|
||||||
|
await insertLastSeenAt(
|
||||||
|
featureName,
|
||||||
|
db.rawDatabase,
|
||||||
|
'default',
|
||||||
|
'2023-08-01 12:30:56',
|
||||||
|
);
|
||||||
|
|
||||||
|
await insertLastSeenAt(
|
||||||
|
featureName,
|
||||||
|
db.rawDatabase,
|
||||||
|
'development',
|
||||||
|
'2023-08-01 12:30:56',
|
||||||
|
);
|
||||||
|
|
||||||
|
await insertLastSeenAt(
|
||||||
|
featureName,
|
||||||
|
db.rawDatabase,
|
||||||
|
'production',
|
||||||
|
'2023-08-01 12:30:56',
|
||||||
|
);
|
||||||
|
|
||||||
|
const { body } = await app.request
|
||||||
|
.get(`/api/admin/projects/default/features/${featureName}`)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(body.environments).toMatchObject([
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
lastSeenAt: '2023-08-01T12:30:56.000Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'development',
|
||||||
|
lastSeenAt: '2023-08-01T12:30:56.000Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'production',
|
||||||
|
lastSeenAt: '2023-08-01T12:30:56.000Z',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
@ -346,10 +346,15 @@ export const insertLastSeenAt = async (
|
|||||||
environment: string = 'default',
|
environment: string = 'default',
|
||||||
date: string = '2023-10-01 12:34:56',
|
date: string = '2023-10-01 12:34:56',
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
await db.raw(`INSERT INTO last_seen_at_metrics (feature_name, environment, last_seen_at)
|
try {
|
||||||
|
await db.raw(`INSERT INTO last_seen_at_metrics (feature_name, environment, last_seen_at)
|
||||||
VALUES ('${featureName}', '${environment}', '${date}');`);
|
VALUES ('${featureName}', '${environment}', '${date}');`);
|
||||||
|
|
||||||
return date;
|
return date;
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
return Promise.resolve('');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const insertFeatureEnvironmentsLastSeen = async (
|
export const insertFeatureEnvironmentsLastSeen = async (
|
||||||
|
Loading…
Reference in New Issue
Block a user