1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

fix: remove proxy return all toggles functionality (#3331)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
This PR removes the return all toggles functionality. Removes the flag
as well
## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #
[1-778](https://linear.app/unleash/issue/1-778/remove-proxyalltoggles-functionality)

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
andreas-unleash 2023-03-16 14:00:18 +02:00 committed by GitHub
parent 04d1de88a6
commit edd12709ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 117 additions and 82 deletions

View File

@ -85,7 +85,6 @@ exports[`should create default config 1`] = `
"projectScopedSegments": false,
"projectScopedStickiness": false,
"projectStatusApi": false,
"proxyReturnAllToggles": false,
"responseTimeWithAppNameKillSwitch": false,
"showProjectApiAccess": false,
"strictSchemaValidation": false,
@ -111,7 +110,6 @@ exports[`should create default config 1`] = `
"projectScopedSegments": false,
"projectScopedStickiness": false,
"projectStatusApi": false,
"proxyReturnAllToggles": false,
"responseTimeWithAppNameKillSwitch": false,
"showProjectApiAccess": false,
"strictSchemaValidation": false,

View File

@ -144,18 +144,10 @@ export default class ProxyController extends Controller {
req: ApiUserRequest,
res: Response<ProxyFeaturesSchema>,
) {
let toggles;
if (this.flagResolver.isEnabled('proxyReturnAllToggles')) {
toggles = await this.services.proxyService.getAllProxyFeatures(
req.user,
ProxyController.createContext(req),
);
} else {
toggles = await this.services.proxyService.getProxyFeatures(
req.user,
ProxyController.createContext(req),
);
}
const toggles = await this.services.proxyService.getProxyFeatures(
req.user,
ProxyController.createContext(req),
);
res.set('Cache-control', 'public, max-age=2');

View File

@ -77,21 +77,6 @@ export class ProxyService {
}));
}
async getAllProxyFeatures(
token: ApiUser,
context: Context,
): Promise<ProxyFeatureSchema[]> {
const client = await this.clientForProxyToken(token);
const definitions = client.getFeatureToggleDefinitions() || [];
return definitions.map((feature) => ({
name: feature.name,
enabled: Boolean(feature.enabled),
variant: client.forceGetVariant(feature.name, context),
impressionData: Boolean(feature.impressionData),
}));
}
async registerProxyMetrics(
token: ApiUser,
metrics: ClientMetricsSchema,

View File

@ -26,10 +26,6 @@ const flags = {
process.env.UNLEASH_RESPONSE_TIME_WITH_APP_NAME_KILL_SWITCH,
false,
),
proxyReturnAllToggles: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_PROXY_RETURN_ALL_TOGGLES,
false,
),
maintenanceMode: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_MAINTENANCE_MODE,
false,

View File

@ -936,55 +936,6 @@ test('Should not recursively set off timers on events', async () => {
jest.useRealTimers();
});
test('should return all features when specified', async () => {
app.config.experimental!.flags.proxyReturnAllToggles = true;
const frontendToken = await createApiToken(ApiTokenType.FRONTEND);
await createFeatureToggle({
name: 'enabledFeature1',
enabled: true,
strategies: [{ name: 'default', constraints: [], parameters: {} }],
});
await createFeatureToggle({
name: 'enabledFeature2',
enabled: true,
strategies: [{ name: 'default', constraints: [], parameters: {} }],
});
await createFeatureToggle({
name: 'disabledFeature',
enabled: false,
strategies: [{ name: 'default', constraints: [], parameters: {} }],
});
await app.request
.get('/api/frontend')
.set('Authorization', frontendToken.secret)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
expect(res.body).toEqual({
toggles: [
{
name: 'enabledFeature1',
enabled: true,
impressionData: false,
variant: { enabled: false, name: 'disabled' },
},
{
name: 'enabledFeature2',
enabled: true,
impressionData: false,
variant: { enabled: false, name: 'disabled' },
},
{
name: 'disabledFeature',
enabled: false,
impressionData: false,
variant: { enabled: false, name: 'disabled' },
},
],
});
});
});
test('should return maxAge header on options call', async () => {
await app.request
.options('/api/frontend')
@ -1038,3 +989,116 @@ test('should terminate data polling when stop is called', async () => {
'Shutting down data polling for proxy repository',
);
});
test('should evaluate strategies when returning toggles', async () => {
const frontendToken = await createApiToken(ApiTokenType.FRONTEND);
await createFeatureToggle({
name: 'enabledFeature',
enabled: true,
strategies: [
{
name: 'flexibleRollout',
constraints: [],
parameters: {
rollout: '100',
stickiness: 'default',
groupId: 'some-new',
},
},
],
});
await createFeatureToggle({
name: 'disabledFeature',
enabled: true,
strategies: [
{
name: 'flexibleRollout',
constraints: [],
parameters: {
rollout: '0',
stickiness: 'default',
groupId: 'some-new',
},
},
],
});
await app.request
.get('/api/frontend')
.set('Authorization', frontendToken.secret)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
expect(res.body).toEqual({
toggles: [
{
name: 'enabledFeature',
enabled: true,
impressionData: false,
variant: { enabled: false, name: 'disabled' },
},
],
});
});
});
test('should not return all features', async () => {
const frontendToken = await createApiToken(ApiTokenType.FRONTEND);
await createFeatureToggle({
name: 'enabledFeature1',
enabled: true,
strategies: [{ name: 'default', constraints: [], parameters: {} }],
});
await createFeatureToggle({
name: 'enabledFeature2',
enabled: true,
strategies: [
{
name: 'flexibleRollout',
constraints: [],
parameters: {
rollout: '100',
stickiness: 'default',
groupId: 'some-new',
},
},
],
});
await createFeatureToggle({
name: 'disabledFeature',
enabled: true,
strategies: [
{
name: 'flexibleRollout',
constraints: [],
parameters: {
rollout: '0',
stickiness: 'default',
groupId: 'some-new',
},
},
],
});
await app.request
.get('/api/frontend')
.set('Authorization', frontendToken.secret)
.expect('Content-Type', /json/)
.expect(200)
.expect((res) => {
expect(res.body).toEqual({
toggles: [
{
name: 'enabledFeature1',
enabled: true,
impressionData: false,
variant: { enabled: false, name: 'disabled' },
},
{
name: 'enabledFeature2',
enabled: true,
impressionData: false,
variant: { enabled: false, name: 'disabled' },
},
],
});
});
});