mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-04 13:48:56 +02:00
feat: outdated sdk detection (#6381)
This commit is contained in:
parent
a958797a8a
commit
1acb4bbb36
59
src/lib/features/metrics/instance/findOutdatedSdks.test.ts
Normal file
59
src/lib/features/metrics/instance/findOutdatedSdks.test.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import { findOutdatedSDKs } from './findOutdatedSdks';
|
||||||
|
|
||||||
|
describe('findOutdatedSDKs', () => {
|
||||||
|
it('should return an empty array when all SDKs are up to date', () => {
|
||||||
|
const sdkVersions = [
|
||||||
|
'unleash-client-node:6.0.0',
|
||||||
|
'unleash-client-php:2.0.0',
|
||||||
|
];
|
||||||
|
const result = findOutdatedSDKs(sdkVersions);
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an array with outdated SDKs', () => {
|
||||||
|
const sdkVersions = [
|
||||||
|
'unleash-client-node:3.9.9',
|
||||||
|
'unleash-client-php:0.9.9',
|
||||||
|
];
|
||||||
|
const result = findOutdatedSDKs(sdkVersions);
|
||||||
|
expect(result).toEqual([
|
||||||
|
'unleash-client-node:3.9.9',
|
||||||
|
'unleash-client-php:0.9.9',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore SDKs not in the config', () => {
|
||||||
|
const sdkVersions = ['unleash-client-pony:2.0.0'];
|
||||||
|
const result = findOutdatedSDKs(sdkVersions);
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle and remove duplicate SDK versions', () => {
|
||||||
|
const sdkVersions = [
|
||||||
|
'unleash-client-node:3.8.0',
|
||||||
|
'unleash-client-node:3.8.0',
|
||||||
|
'unleash-client-php:0.9.0',
|
||||||
|
'unleash-client-php:0.9.0',
|
||||||
|
];
|
||||||
|
const result = findOutdatedSDKs(sdkVersions);
|
||||||
|
expect(result).toEqual([
|
||||||
|
'unleash-client-node:3.8.0',
|
||||||
|
'unleash-client-php:0.9.0',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correctly handle semver versions', () => {
|
||||||
|
const sdkVersions = [
|
||||||
|
'unleash-client-node:6.1.0',
|
||||||
|
'unleash-client-php:1.20.3-beta.0',
|
||||||
|
];
|
||||||
|
const result = findOutdatedSDKs(sdkVersions);
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore invalid SDK versions', () => {
|
||||||
|
const sdkVersions = ['unleash-client-node', '1.2.3'];
|
||||||
|
const result = findOutdatedSDKs(sdkVersions);
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
30
src/lib/features/metrics/instance/findOutdatedSdks.ts
Normal file
30
src/lib/features/metrics/instance/findOutdatedSdks.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import semver from 'semver';
|
||||||
|
|
||||||
|
type SDKConfig = {
|
||||||
|
[key: string]: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const config: SDKConfig = {
|
||||||
|
'unleash-client-node': '5.3.2',
|
||||||
|
'unleash-client-java': '9.0.0',
|
||||||
|
'unleash-client-go': '4.1.0',
|
||||||
|
'unleash-client-python': '5.9.2',
|
||||||
|
'unleash-client-ruby': '5.0.0',
|
||||||
|
'unleash-client-dotnet': '4.1.3',
|
||||||
|
'unleash-client-php': '1.13.1',
|
||||||
|
};
|
||||||
|
|
||||||
|
export function findOutdatedSDKs(sdkVersions: string[]): string[] {
|
||||||
|
const uniqueSdkVersions = Array.from(new Set(sdkVersions));
|
||||||
|
const outdatedSDKs: string[] = [];
|
||||||
|
|
||||||
|
return uniqueSdkVersions.filter((sdkVersion) => {
|
||||||
|
const result = sdkVersion.split(':');
|
||||||
|
if (result.length !== 2) return false;
|
||||||
|
const [sdkName, version] = result;
|
||||||
|
const minVersion = config[sdkName];
|
||||||
|
if (!minVersion) return false;
|
||||||
|
if (semver.lt(version, minVersion)) return true;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
@ -22,6 +22,7 @@ import { IPrivateProjectChecker } from '../../private-project/privateProjectChec
|
|||||||
import { IFlagResolver, SYSTEM_USER } from '../../../types';
|
import { IFlagResolver, SYSTEM_USER } from '../../../types';
|
||||||
import { ALL_PROJECTS, parseStrictSemVer } from '../../../util';
|
import { ALL_PROJECTS, parseStrictSemVer } from '../../../util';
|
||||||
import { Logger } from '../../../logger';
|
import { Logger } from '../../../logger';
|
||||||
|
import { findOutdatedSDKs } from './findOutdatedSdks';
|
||||||
|
|
||||||
export default class ClientInstanceService {
|
export default class ClientInstanceService {
|
||||||
apps = {};
|
apps = {};
|
||||||
@ -219,7 +220,18 @@ export default class ClientInstanceService {
|
|||||||
async getApplicationOverview(
|
async getApplicationOverview(
|
||||||
appName: string,
|
appName: string,
|
||||||
): Promise<IApplicationOverview> {
|
): Promise<IApplicationOverview> {
|
||||||
return this.clientApplicationsStore.getApplicationOverview(appName);
|
const result =
|
||||||
|
await this.clientApplicationsStore.getApplicationOverview(appName);
|
||||||
|
|
||||||
|
const sdks = result.environments.flatMap(
|
||||||
|
(environment) => environment.sdks,
|
||||||
|
);
|
||||||
|
const outdatedSdks = findOutdatedSDKs(sdks);
|
||||||
|
if (outdatedSdks.length > 0) {
|
||||||
|
result.issues.push({ type: 'outdatedSdks', items: outdatedSdks });
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getApplicationEnvironmentInstances(
|
async getApplicationEnvironmentInstances(
|
||||||
|
@ -9,7 +9,7 @@ export const applicationOverviewIssuesSchema = {
|
|||||||
properties: {
|
properties: {
|
||||||
type: {
|
type: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
enum: ['missingFeatures', 'missingStrategies'],
|
enum: ['missingFeatures', 'missingStrategies', 'outdatedSdks'],
|
||||||
description: 'The name of this action.',
|
description: 'The name of this action.',
|
||||||
},
|
},
|
||||||
items: {
|
items: {
|
||||||
|
@ -159,7 +159,7 @@ test('should show missing features and strategies', async () => {
|
|||||||
appName: metrics.appName,
|
appName: metrics.appName,
|
||||||
instanceId: metrics.instanceId,
|
instanceId: metrics.instanceId,
|
||||||
strategies: ['my-special-strategy'],
|
strategies: ['my-special-strategy'],
|
||||||
sdkVersion: 'unleash-client-test',
|
sdkVersion: 'unleash-client-node:1.0.0',
|
||||||
started: Date.now(),
|
started: Date.now(),
|
||||||
interval: 10,
|
interval: 10,
|
||||||
}),
|
}),
|
||||||
@ -188,12 +188,16 @@ test('should show missing features and strategies', async () => {
|
|||||||
type: 'missingStrategies',
|
type: 'missingStrategies',
|
||||||
items: ['my-special-strategy'],
|
items: ['my-special-strategy'],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: 'outdatedSdks',
|
||||||
|
items: ['unleash-client-node:1.0.0'],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
environments: [
|
environments: [
|
||||||
{
|
{
|
||||||
instanceCount: 1,
|
instanceCount: 1,
|
||||||
name: 'default',
|
name: 'default',
|
||||||
sdks: ['unleash-client-test'],
|
sdks: ['unleash-client-node:1.0.0'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
featureCount: 3,
|
featureCount: 3,
|
||||||
|
Loading…
Reference in New Issue
Block a user