mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +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 { ALL_PROJECTS, parseStrictSemVer } from '../../../util';
|
||||
import { Logger } from '../../../logger';
|
||||
import { findOutdatedSDKs } from './findOutdatedSdks';
|
||||
|
||||
export default class ClientInstanceService {
|
||||
apps = {};
|
||||
@ -219,7 +220,18 @@ export default class ClientInstanceService {
|
||||
async getApplicationOverview(
|
||||
appName: string,
|
||||
): 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(
|
||||
|
@ -9,7 +9,7 @@ export const applicationOverviewIssuesSchema = {
|
||||
properties: {
|
||||
type: {
|
||||
type: 'string',
|
||||
enum: ['missingFeatures', 'missingStrategies'],
|
||||
enum: ['missingFeatures', 'missingStrategies', 'outdatedSdks'],
|
||||
description: 'The name of this action.',
|
||||
},
|
||||
items: {
|
||||
|
@ -159,7 +159,7 @@ test('should show missing features and strategies', async () => {
|
||||
appName: metrics.appName,
|
||||
instanceId: metrics.instanceId,
|
||||
strategies: ['my-special-strategy'],
|
||||
sdkVersion: 'unleash-client-test',
|
||||
sdkVersion: 'unleash-client-node:1.0.0',
|
||||
started: Date.now(),
|
||||
interval: 10,
|
||||
}),
|
||||
@ -188,12 +188,16 @@ test('should show missing features and strategies', async () => {
|
||||
type: 'missingStrategies',
|
||||
items: ['my-special-strategy'],
|
||||
},
|
||||
{
|
||||
type: 'outdatedSdks',
|
||||
items: ['unleash-client-node:1.0.0'],
|
||||
},
|
||||
],
|
||||
environments: [
|
||||
{
|
||||
instanceCount: 1,
|
||||
name: 'default',
|
||||
sdks: ['unleash-client-test'],
|
||||
sdks: ['unleash-client-node:1.0.0'],
|
||||
},
|
||||
],
|
||||
featureCount: 3,
|
||||
|
Loading…
Reference in New Issue
Block a user