1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-28 17:55:15 +02:00

feat: application missing strategies (#6334)

Now also showing missing strategies, that SDK sends, but do not exist in
Unleash.
This commit is contained in:
Jaanus Sellin 2024-02-26 12:59:50 +02:00 committed by GitHub
parent 89d113f1ff
commit 3b7b816b44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 13 deletions

View File

@ -27,6 +27,12 @@ const TABLE = 'client_applications';
const TABLE_USAGE = 'client_applications_usage'; const TABLE_USAGE = 'client_applications_usage';
const DEPRECATED_STRATEGIES = [
'gradualRolloutRandom',
'gradualRolloutSessionId',
'gradualRolloutUserId',
];
const mapRow: (any) => IClientApplication = (row) => ({ const mapRow: (any) => IClientApplication = (row) => ({
appName: row.app_name, appName: row.app_name,
createdAt: row.created_at, createdAt: row.created_at,
@ -294,6 +300,7 @@ export default class ClientApplicationsStore
'ci.instance_id', 'ci.instance_id',
'ci.sdk_version', 'ci.sdk_version',
'ci.last_seen', 'ci.last_seen',
'a.strategies',
]) ])
.from({ a: 'client_applications' }) .from({ a: 'client_applications' })
.leftJoin('client_metrics_env as cme', 'cme.app_name', 'a.app_name') .leftJoin('client_metrics_env as cme', 'cme.app_name', 'a.app_name')
@ -311,12 +318,20 @@ export default class ClientApplicationsStore
throw new NotFoundError(`Could not find appName=${appName}`); throw new NotFoundError(`Could not find appName=${appName}`);
} }
return this.mapApplicationOverviewData(rows); const existingStrategies: string[] = await this.db
.select('name')
.from('strategies')
.pluck('name');
return this.mapApplicationOverviewData(rows, existingStrategies);
} }
mapApplicationOverviewData(rows: any[]): IApplicationOverview { mapApplicationOverviewData(
rows: any[],
existingStrategies: string[],
): IApplicationOverview {
const featureCount = new Set(rows.map((row) => row.feature_name)).size; const featureCount = new Set(rows.map((row) => row.feature_name)).size;
const missingFeatures: Set<string> = new Set(); const missingFeatures: Set<string> = new Set();
const missingStrategies: Set<string> = new Set();
const environments = rows.reduce((acc, row) => { const environments = rows.reduce((acc, row) => {
const { const {
@ -326,6 +341,7 @@ export default class ClientApplicationsStore
last_seen, last_seen,
project, project,
feature_name, feature_name,
strategies,
} = row; } = row;
if (!environment) return acc; if (!environment) return acc;
@ -334,6 +350,15 @@ export default class ClientApplicationsStore
missingFeatures.add(feature_name); missingFeatures.add(feature_name);
} }
strategies.forEach((strategy) => {
if (
!DEPRECATED_STRATEGIES.includes(strategy) &&
!existingStrategies.includes(strategy)
) {
missingStrategies.add(strategy);
}
});
let env = acc.find((e) => e.name === environment); let env = acc.find((e) => e.name === environment);
if (!env) { if (!env) {
env = { env = {
@ -366,15 +391,19 @@ export default class ClientApplicationsStore
env.sdks.sort(); env.sdks.sort();
}); });
const issues: ApplicationOverviewIssuesSchema[] = const issues: ApplicationOverviewIssuesSchema[] = [];
missingFeatures.size > 0 if (missingFeatures.size > 0) {
? [ issues.push({
{ type: 'missingFeatures',
type: 'missingFeatures', items: [...missingFeatures],
items: [...missingFeatures], });
}, }
] if (missingStrategies.size > 0) {
: []; issues.push({
type: 'missingStrategies',
items: [...missingStrategies],
});
}
return { return {
projects: [ projects: [

View File

@ -136,13 +136,13 @@ test('should show correct number of total', async () => {
expect(body).toMatchObject(expected); expect(body).toMatchObject(expected);
}); });
test('should show missing features', async () => { test('should show missing features and strategies', async () => {
await Promise.all([ await Promise.all([
app.createFeature('toggle-name-1'), app.createFeature('toggle-name-1'),
app.request.post('/api/client/register').send({ app.request.post('/api/client/register').send({
appName: metrics.appName, appName: metrics.appName,
instanceId: metrics.instanceId, instanceId: metrics.instanceId,
strategies: ['default'], strategies: ['my-special-strategy'],
sdkVersion: 'unleash-client-test', sdkVersion: 'unleash-client-test',
started: Date.now(), started: Date.now(),
interval: 10, interval: 10,
@ -168,6 +168,10 @@ test('should show missing features', async () => {
type: 'missingFeatures', type: 'missingFeatures',
items: ['toggle-name-2', 'toggle-name-3'], items: ['toggle-name-2', 'toggle-name-3'],
}, },
{
type: 'missingStrategies',
items: ['my-special-strategy'],
},
], ],
environments: [ environments: [
{ {