Skip to content

Commit

Permalink
[Gitar] Cleaning up stale feature flag: applicationOverviewNewQuery w…
Browse files Browse the repository at this point in the history
…ith value true (#6956)



---------

Co-authored-by: Gitar Bot <noreply@gitar.co>
Co-authored-by: sjaanus <sellinjaanus@gmail.com>
  • Loading branch information
3 people committed Apr 29, 2024
1 parent d1cad6e commit 010c4ee
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 150 deletions.
1 change: 0 additions & 1 deletion src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ exports[`should create default config 1`] = `
"experiments": {
"adminTokenKillSwitch": false,
"anonymiseEventLog": false,
"applicationOverviewNewQuery": false,
"automatedActions": false,
"caseInsensitiveInOperators": false,
"celebrateUnleash": false,
Expand Down
141 changes: 0 additions & 141 deletions src/lib/db/client-applications-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ export default class ClientApplicationsStore
async getApplicationOverview(
appName: string,
): Promise<IApplicationOverview> {
if (!this.flagResolver.isEnabled('applicationOverviewNewQuery')) {
return this.getOldApplicationOverview(appName);
}
const stopTimer = this.timer('getApplicationOverview');
const query = this.db
.with('metrics', (qb) => {
Expand Down Expand Up @@ -351,58 +348,10 @@ export default class ClientApplicationsStore
return this.mapApplicationOverviewData(rows, existingStrategies);
}

async getOldApplicationOverview(
appName: string,
): Promise<IApplicationOverview> {
const stopTimer = this.timer('getApplicationOverviewOld');
const query = this.db
.with('metrics', (qb) => {
qb.distinct(
'cme.app_name',
'cme.environment',
'cme.feature_name',
).from('client_metrics_env as cme');
})
.select([
'f.project',
'cme.environment',
'cme.feature_name',
'ci.instance_id',
'ci.sdk_version',
'ci.last_seen',
'a.strategies',
])
.from({ a: 'client_applications' })
.leftJoin('metrics as cme', 'cme.app_name', 'a.app_name')
.leftJoin('features as f', 'cme.feature_name', 'f.name')
.leftJoin('client_instances as ci', function () {
this.on('ci.app_name', '=', 'cme.app_name').andOn(
'ci.environment',
'=',
'cme.environment',
);
})
.where('a.app_name', appName)
.orderBy('cme.environment', 'asc');
const rows = await query;
stopTimer();
if (!rows.length) {
throw new NotFoundError(`Could not find appName=${appName}`);
}
const existingStrategies: string[] = await this.db
.select('name')
.from('strategies')
.pluck('name');
return this.mapApplicationOverviewData(rows, existingStrategies);
}

mapApplicationOverviewData(
rows: any[],
existingStrategies: string[],
): IApplicationOverview {
if (!this.flagResolver.isEnabled('applicationOverviewNewQuery')) {
return this.mapOldApplicationOverviewData(rows, existingStrategies);
}
const featureCount = new Set(rows.flatMap((row) => row.features)).size;
const missingStrategies: Set<string> = new Set();

Expand Down Expand Up @@ -486,96 +435,6 @@ export default class ClientApplicationsStore
};
}

private mapOldApplicationOverviewData(
rows: any[],
existingStrategies: string[],
): IApplicationOverview {
const featureCount = new Set(rows.map((row) => row.feature_name)).size;
const missingStrategies: Set<string> = new Set();

const environments = rows.reduce((acc, row) => {
const {
environment,
instance_id,
sdk_version,
last_seen,
project,
feature_name,
strategies,
} = row;

if (!environment) return acc;

strategies.forEach((strategy) => {
if (
!DEPRECATED_STRATEGIES.includes(strategy) &&
!existingStrategies.includes(strategy)
) {
missingStrategies.add(strategy);
}
});

const featureDoesNotExist = !project && feature_name;

let env = acc.find((e) => e.name === environment);
if (!env) {
env = {
name: environment,
instanceCount: instance_id ? 1 : 0,
sdks: sdk_version ? [sdk_version] : [],
lastSeen: last_seen,
uniqueInstanceIds: new Set(
instance_id ? [instance_id] : [],
),
issues: {
missingFeatures: featureDoesNotExist
? [feature_name]
: [],
},
};
acc.push(env);
} else {
if (instance_id) {
env.uniqueInstanceIds.add(instance_id);
env.instanceCount = env.uniqueInstanceIds.size;
}
if (
featureDoesNotExist &&
!env.issues.missingFeatures.includes(feature_name)
) {
env.issues.missingFeatures.push(feature_name);
}
if (sdk_version && !env.sdks.includes(sdk_version)) {
env.sdks.push(sdk_version);
}
if (new Date(last_seen) > new Date(env.lastSeen)) {
env.lastSeen = last_seen;
}
}

return acc;
}, []);
environments.forEach((env) => {
delete env.uniqueInstanceIds;
env.sdks.sort();
});

return {
projects: [
...new Set(
rows
.filter((row) => row.project != null)
.map((row) => row.project),
),
],
featureCount,
environments,
issues: {
missingStrategies: [...missingStrategies],
},
};
}

private remapUsageRow = (input) => {
if (this.flagResolver.isEnabled('parseProjectFromSession')) {
if (!input.projects || input.projects.length === 0) {
Expand Down
7 changes: 1 addition & 6 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export type IFlagKey =
| 'projectListFilterMyProjects'
| 'projectsListNewCards'
| 'parseProjectFromSession'
| 'createProjectWithEnvironmentConfig'
| 'applicationOverviewNewQuery';
| 'createProjectWithEnvironmentConfig';

export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;

Expand Down Expand Up @@ -280,10 +279,6 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_CREATE_PROJECT_WITH_ENVIRONMENT_CONFIG,
false,
),
applicationOverviewNewQuery: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_APPLICATION_OVERVIEW_NEW_QUERY,
false,
),
projectsListNewCards: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_PROJECTS_LIST_NEW_CARDS,
false,
Expand Down
1 change: 0 additions & 1 deletion src/server-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ process.nextTick(async () => {
projectsListNewCards: true,
parseProjectFromSession: true,
createProjectWithEnvironmentConfig: true,
applicationOverviewNewQuery: true,
},
},
authentication: {
Expand Down
1 change: 0 additions & 1 deletion src/test/e2e/api/admin/applications.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ beforeAll(async () => {
experimental: {
flags: {
strictSchemaValidation: true,
applicationOverviewNewQuery: true,
},
},
},
Expand Down

0 comments on commit 010c4ee

Please sign in to comment.