mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-24 17:51:14 +02:00
Merge branch 'main' into chore/unleash-ai-filterflagstoarchive-flag-cleanup
This commit is contained in:
commit
c5ddb3e1be
@ -178,6 +178,9 @@ export const CreationArchiveChart: FC<ICreationArchiveChartProps> = ({
|
||||
display: true,
|
||||
text: 'Number of flags',
|
||||
},
|
||||
ticks: {
|
||||
stepSize: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
@ -13,10 +13,7 @@ function getCurrentArchiveRatio(
|
||||
InstanceInsightsSchema['creationArchiveTrends']
|
||||
>,
|
||||
) {
|
||||
if (
|
||||
!groupedCreationArchiveData ||
|
||||
Object.keys(groupedCreationArchiveData).length === 0
|
||||
) {
|
||||
if (!groupedCreationArchiveData) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -24,7 +21,7 @@ function getCurrentArchiveRatio(
|
||||
let totalCreated = 0;
|
||||
|
||||
Object.values(groupedCreationArchiveData).forEach((projectData) => {
|
||||
const latestData = projectData[projectData.length - 1];
|
||||
const latestData = projectData[0];
|
||||
if (latestData) {
|
||||
totalArchived += latestData.archivedFlags || 0;
|
||||
const createdSum = latestData.createdFlags
|
||||
|
@ -351,10 +351,9 @@ export default class FeatureController extends Controller {
|
||||
}
|
||||
|
||||
async calculateMeta(query: IFeatureToggleQuery): Promise<IMeta> {
|
||||
const etagByEnvEnabled = this.flagResolver.isEnabled('etagByEnv');
|
||||
const revisionId =
|
||||
await this.configurationRevisionService.getMaxRevisionId(
|
||||
etagByEnvEnabled ? query.environment : undefined,
|
||||
query.environment,
|
||||
);
|
||||
|
||||
const queryHash = hashSum(query);
|
||||
|
@ -60,6 +60,7 @@ export type IFlagKey =
|
||||
| 'addConfiguration'
|
||||
| 'fetchMode'
|
||||
| 'etagByEnv';
|
||||
| 'fetchMode';
|
||||
|
||||
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
|
||||
|
||||
|
@ -40,10 +40,8 @@ const allEnvsTokenSecret = validTokens[2].secret;
|
||||
|
||||
async function setup({
|
||||
etagVariant,
|
||||
etagByEnvEnabled,
|
||||
}: {
|
||||
etagVariant: string | undefined;
|
||||
etagByEnvEnabled: boolean;
|
||||
}): Promise<{ app: IUnleashTest; db: ITestDb }> {
|
||||
const db = await dbInit(`ignored`, getLogger);
|
||||
|
||||
@ -63,7 +61,6 @@ async function setup({
|
||||
enabled: etagVariant !== undefined,
|
||||
feature_enabled: etagVariant !== undefined,
|
||||
},
|
||||
etagByEnv: etagByEnvEnabled,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -178,28 +175,21 @@ async function validateInitialState({
|
||||
describe.each([
|
||||
{
|
||||
etagVariant: undefined,
|
||||
etagByEnvEnabled: false,
|
||||
},
|
||||
{
|
||||
etagVariant: 'v2',
|
||||
etagByEnvEnabled: false,
|
||||
},
|
||||
{
|
||||
etagVariant: 'v2',
|
||||
etagByEnvEnabled: true,
|
||||
},
|
||||
])(
|
||||
'feature 304 api client (etag variant = $etagVariant)',
|
||||
({ etagVariant, etagByEnvEnabled }) => {
|
||||
({ etagVariant }) => {
|
||||
let app: IUnleashTest;
|
||||
let db: ITestDb;
|
||||
const etagVariantEnabled = etagVariant !== undefined;
|
||||
const etagVariantName = etagVariant ?? 'disabled';
|
||||
const expectedDevEventId = etagByEnvEnabled ? 13 : 15;
|
||||
const expectedDevEventId = 13;
|
||||
beforeAll(async () => {
|
||||
({ app, db } = await setup({
|
||||
etagVariant,
|
||||
etagByEnvEnabled,
|
||||
}));
|
||||
await initialize({ app, db });
|
||||
await validateInitialState({ app, db });
|
||||
@ -279,132 +269,62 @@ describe.each([
|
||||
);
|
||||
});
|
||||
|
||||
test.runIf(!etagByEnvEnabled)(
|
||||
'production environment gets same event id in etag than development',
|
||||
async () => {
|
||||
const { headers: prodHeaders } = await app.request
|
||||
.get('/api/client/features?bla=1')
|
||||
.set('Authorization', prodTokenSecret)
|
||||
.expect(200);
|
||||
test('production environment gets a different etag than development', async () => {
|
||||
const { headers: prodHeaders } = await app.request
|
||||
.get('/api/client/features?bla=1')
|
||||
.set('Authorization', prodTokenSecret)
|
||||
.expect(200);
|
||||
|
||||
expect(prodHeaders.etag).toEqual(
|
||||
`"67e24428:15${etagVariantEnabled ? `:${etagVariantName}` : ''}"`,
|
||||
);
|
||||
expect(prodHeaders.etag).toEqual(
|
||||
`"67e24428:15${etagVariantEnabled ? `:${etagVariantName}` : ''}"`,
|
||||
);
|
||||
|
||||
const { headers: devHeaders } = await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', devTokenSecret)
|
||||
.expect(200);
|
||||
const { headers: devHeaders } = await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', devTokenSecret)
|
||||
.expect(200);
|
||||
|
||||
expect(devHeaders.etag).toEqual(
|
||||
`"76d8bb0e:15${etagVariantEnabled ? `:${etagVariantName}` : ''}"`,
|
||||
);
|
||||
},
|
||||
);
|
||||
expect(devHeaders.etag).toEqual(
|
||||
`"76d8bb0e:13${etagVariantEnabled ? `:${etagVariantName}` : ''}"`,
|
||||
);
|
||||
});
|
||||
|
||||
test.runIf(!etagByEnvEnabled)(
|
||||
'modifying dev environment also invalidates prod tokens',
|
||||
async () => {
|
||||
const currentDevEtag = `"76d8bb0e:${expectedDevEventId}${etagVariantEnabled ? `:${etagVariantName}` : ''}"`;
|
||||
const currentProdEtag = `"67e24428:15${etagVariantEnabled ? `:${etagVariantName}` : ''}"`;
|
||||
await app.request
|
||||
.get('/api/client/features')
|
||||
.set('if-none-match', currentProdEtag)
|
||||
.set('Authorization', prodTokenSecret)
|
||||
.expect(304);
|
||||
test('modifying dev environment should only invalidate dev tokens', async () => {
|
||||
const currentDevEtag = `"76d8bb0e:13${etagVariantEnabled ? `:${etagVariantName}` : ''}"`;
|
||||
const currentProdEtag = `"67e24428:15${etagVariantEnabled ? `:${etagVariantName}` : ''}"`;
|
||||
await app.request
|
||||
.get('/api/client/features')
|
||||
.set('if-none-match', currentProdEtag)
|
||||
.set('Authorization', prodTokenSecret)
|
||||
.expect(304);
|
||||
|
||||
await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', devTokenSecret)
|
||||
.set('if-none-match', currentDevEtag)
|
||||
.expect(304);
|
||||
await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', devTokenSecret)
|
||||
.set('if-none-match', currentDevEtag)
|
||||
.expect(304);
|
||||
|
||||
await app.enableFeature('X', DEFAULT_ENV);
|
||||
await app.services.configurationRevisionService.updateMaxRevisionId();
|
||||
await app.enableFeature('X', DEFAULT_ENV);
|
||||
await app.services.configurationRevisionService.updateMaxRevisionId();
|
||||
|
||||
await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', prodTokenSecret)
|
||||
.set('if-none-match', currentProdEtag)
|
||||
.expect(200);
|
||||
await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', prodTokenSecret)
|
||||
.set('if-none-match', currentProdEtag)
|
||||
.expect(304);
|
||||
|
||||
const { headers: devHeaders } = await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', devTokenSecret)
|
||||
.set('if-none-match', currentDevEtag)
|
||||
.expect(200);
|
||||
const { headers: devHeaders } = await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', devTokenSecret)
|
||||
.set('if-none-match', currentDevEtag)
|
||||
.expect(200);
|
||||
|
||||
// Note: this test yields a different result if run in isolation
|
||||
// this is because the id 19 depends on a previous test adding a feature
|
||||
// otherwise the id will be 18
|
||||
expect(devHeaders.etag).toEqual(
|
||||
`"76d8bb0e:19${etagVariantEnabled ? `:${etagVariantName}` : ''}"`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test.runIf(etagByEnvEnabled)(
|
||||
'production environment gets a different etag than development',
|
||||
async () => {
|
||||
const { headers: prodHeaders } = await app.request
|
||||
.get('/api/client/features?bla=1')
|
||||
.set('Authorization', prodTokenSecret)
|
||||
.expect(200);
|
||||
|
||||
expect(prodHeaders.etag).toEqual(
|
||||
`"67e24428:15${etagVariantEnabled ? `:${etagVariantName}` : ''}"`,
|
||||
);
|
||||
|
||||
const { headers: devHeaders } = await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', devTokenSecret)
|
||||
.expect(200);
|
||||
|
||||
expect(devHeaders.etag).toEqual(
|
||||
`"76d8bb0e:13${etagVariantEnabled ? `:${etagVariantName}` : ''}"`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test.runIf(etagByEnvEnabled)(
|
||||
'modifying dev environment should only invalidate dev tokens',
|
||||
async () => {
|
||||
const currentDevEtag = `"76d8bb0e:13${etagVariantEnabled ? `:${etagVariantName}` : ''}"`;
|
||||
const currentProdEtag = `"67e24428:15${etagVariantEnabled ? `:${etagVariantName}` : ''}"`;
|
||||
await app.request
|
||||
.get('/api/client/features')
|
||||
.set('if-none-match', currentProdEtag)
|
||||
.set('Authorization', prodTokenSecret)
|
||||
.expect(304);
|
||||
|
||||
await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', devTokenSecret)
|
||||
.set('if-none-match', currentDevEtag)
|
||||
.expect(304);
|
||||
|
||||
await app.enableFeature('X', DEFAULT_ENV);
|
||||
await app.services.configurationRevisionService.updateMaxRevisionId();
|
||||
|
||||
await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', prodTokenSecret)
|
||||
.set('if-none-match', currentProdEtag)
|
||||
.expect(304);
|
||||
|
||||
const { headers: devHeaders } = await app.request
|
||||
.get('/api/client/features')
|
||||
.set('Authorization', devTokenSecret)
|
||||
.set('if-none-match', currentDevEtag)
|
||||
.expect(200);
|
||||
|
||||
// Note: this test yields a different result if run in isolation
|
||||
// this is because the id 19 depends on a previous test adding a feature
|
||||
// otherwise the id will be 18
|
||||
expect(devHeaders.etag).toEqual(
|
||||
`"76d8bb0e:19${etagVariantEnabled ? `:${etagVariantName}` : ''}"`,
|
||||
);
|
||||
},
|
||||
);
|
||||
// Note: this test yields a different result if run in isolation
|
||||
// this is because the id 19 depends on a previous test adding a feature
|
||||
// otherwise the id will be 18
|
||||
expect(devHeaders.etag).toEqual(
|
||||
`"76d8bb0e:19${etagVariantEnabled ? `:${etagVariantName}` : ''}"`,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user