Skip to content

Commit

Permalink
chore: remove new frontend api feature flag (#6906)
Browse files Browse the repository at this point in the history
The flag has been 100% for a bit now, we need to prepare for GA.
  • Loading branch information
sjaanus committed Apr 24, 2024
1 parent bf33664 commit d578dea
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 466 deletions.
2 changes: 0 additions & 2 deletions src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ exports[`should create default config 1`] = `
},
},
"filterInvalidClientMetrics": false,
"globalFrontendApiCache": false,
"googleAuthEnabled": false,
"inMemoryScheduledChangeRequests": false,
"maintenanceMode": false,
Expand All @@ -144,7 +143,6 @@ exports[`should create default config 1`] = `
"queryMissingTokens": false,
"responseTimeMetricsFix": false,
"responseTimeWithAppNameKillSwitch": false,
"returnGlobalFrontendApiCache": false,
"scimApi": false,
"showInactiveUsers": false,
"signals": false,
Expand Down
70 changes: 4 additions & 66 deletions src/lib/features/frontend-api/frontend-api-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
emptyResponse,
getStandardResponses,
type FrontendApiClientSchema,
type FrontendApiFeatureSchema,
frontendApiFeaturesSchema,
type FrontendApiFeaturesSchema,
} from '../../openapi';
Expand All @@ -21,8 +20,6 @@ import NotImplementedError from '../../error/not-implemented-error';
import NotFoundError from '../../error/notfound-error';
import rateLimit from 'express-rate-limit';
import { minutesToMilliseconds } from 'date-fns';
import isEqual from 'lodash.isequal';
import { diff } from 'json-diff';
import metricsHelper from '../../util/metrics-helper';
import { FUNCTION_TIME } from '../../metric-events';

Expand Down Expand Up @@ -186,48 +183,11 @@ export default class FrontendAPIController extends Controller {
if (!this.config.flagResolver.isEnabled('embedProxy')) {
throw new NotFoundError();
}
let toggles: FrontendApiFeatureSchema[];
let newToggles: FrontendApiFeatureSchema[] = [];
if (this.config.flagResolver.isEnabled('globalFrontendApiCache')) {
const context = FrontendAPIController.createContext(req);
[toggles, newToggles] = await Promise.all([
this.getTimedFrontendApiFeatures(req, context),
this.getTimedNewFrontendApiFeatures(req, context),
]);
const sortedToggles = toggles.sort((a, b) =>
a.name.localeCompare(b.name),
);
const sortedNewToggles = newToggles.sort((a, b) =>
a.name.localeCompare(b.name),
const toggles =
await this.services.frontendApiService.getFrontendApiFeatures(
req.user,
FrontendAPIController.createContext(req),
);
if (!isEqual(sortedToggles, sortedNewToggles)) {
this.logger.warn(
`old features and new features are different. Old count ${
toggles.length
}, new count ${newToggles.length}, projects ${
req.user.projects
}, environment ${
req.user.environment
}, diff ${JSON.stringify(
diff(sortedToggles, sortedNewToggles),
)}`,
);
}
} else if (
this.config.flagResolver.isEnabled('returnGlobalFrontendApiCache')
) {
toggles =
await this.services.frontendApiService.getNewFrontendApiFeatures(
req.user,
FrontendAPIController.createContext(req),
);
} else {
toggles =
await this.services.frontendApiService.getFrontendApiFeatures(
req.user,
FrontendAPIController.createContext(req),
);
}

res.set('Cache-control', 'no-cache');

Expand All @@ -239,28 +199,6 @@ export default class FrontendAPIController extends Controller {
);
}

private async getTimedFrontendApiFeatures(req, context) {
const stopTimer = this.timer('getFrontendApiFeatures');
const features =
await this.services.frontendApiService.getFrontendApiFeatures(
req.user,
context,
);
stopTimer();
return features;
}

private async getTimedNewFrontendApiFeatures(req, context) {
const stopTimer = this.timer('getNewFrontendApiFeatures');
const features =
await this.services.frontendApiService.getNewFrontendApiFeatures(
req.user,
context,
);
stopTimer();
return features;
}

private async registerFrontendApiMetrics(
req: ApiUserRequest<unknown, unknown, ClientMetricsSchema>,
res: Response,
Expand Down
1 change: 0 additions & 1 deletion src/lib/features/frontend-api/frontend-api-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class FrontendApiRepository
}

getToggle(name: string): FeatureInterface {
//@ts-ignore (we must update the node SDK to allow undefined)
return this.globalFrontendApiCache.getToggle(name, this.token);
}

Expand Down
155 changes: 0 additions & 155 deletions src/lib/features/frontend-api/frontend-api-service.e2e.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/features/frontend-api/frontend-api-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('frontend api service fetching features from global cache', async () => {
globalFrontendApiCache,
);

const features = await frontendApiService.getNewFrontendApiFeatures(
const features = await frontendApiService.getFrontendApiFeatures(
{
projects: ['irrelevant'],
environment: 'irrelevant',
Expand Down
Loading

0 comments on commit d578dea

Please sign in to comment.