mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
fix: add getSeenAppsForFeatureToggle to client-store-v2
This commit is contained in:
parent
944e74af52
commit
e62ad931f0
@ -114,4 +114,16 @@ export class ClientMetricsStoreV2 implements IClientMetricsStoreV2 {
|
||||
.andWhereRaw(`timestamp >= NOW() - INTERVAL '${hoursBack} hours'`);
|
||||
return rows.map(fromRow);
|
||||
}
|
||||
|
||||
async getSeenAppsForFeatureToggle(
|
||||
featureName: string,
|
||||
hoursBack: number = 24,
|
||||
): Promise<string[]> {
|
||||
return this.db<ClientMetricsEnvTable>(TABLE)
|
||||
.distinct()
|
||||
.where({ feature_name: featureName })
|
||||
.andWhereRaw(`timestamp >= NOW() - INTERVAL '${hoursBack} hours'`)
|
||||
.pluck('app_name')
|
||||
.orderBy('app_name');
|
||||
}
|
||||
}
|
||||
|
@ -19,4 +19,8 @@ export interface IClientMetricsStoreV2
|
||||
featureName: string,
|
||||
hoursBack?: number,
|
||||
): Promise<IClientMetricsEnv[]>;
|
||||
getSeenAppsForFeatureToggle(
|
||||
featureName: string,
|
||||
hoursBack?: number,
|
||||
): Promise<string[]>;
|
||||
}
|
||||
|
@ -214,3 +214,37 @@ test('Should insert 1500 feature toggle metrics', async () => {
|
||||
|
||||
expect(savedMetrics).toHaveLength(1500);
|
||||
});
|
||||
|
||||
test('Should return seen applications using a feature toggle', async () => {
|
||||
const metrics: IClientMetricsEnv[] = [
|
||||
{
|
||||
featureName: 'demo',
|
||||
appName: 'web',
|
||||
environment: 'dev',
|
||||
timestamp: new Date(),
|
||||
yes: 2,
|
||||
no: 2,
|
||||
},
|
||||
{
|
||||
featureName: 'demo',
|
||||
appName: 'backend-api',
|
||||
environment: 'dev',
|
||||
timestamp: new Date(),
|
||||
yes: 1,
|
||||
no: 3,
|
||||
},
|
||||
{
|
||||
featureName: 'demo',
|
||||
appName: 'backend-api',
|
||||
environment: 'dev',
|
||||
timestamp: new Date(),
|
||||
yes: 1,
|
||||
no: 3,
|
||||
},
|
||||
];
|
||||
await clientMetricsStore.batchInsertMetrics(metrics);
|
||||
const apps = await clientMetricsStore.getSeenAppsForFeatureToggle('demo');
|
||||
|
||||
expect(apps).toHaveLength(2);
|
||||
expect(apps).toStrictEqual(['backend-api', 'web']);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user