Skip to content

Commit 4bf7d25

Browse files
authored
Verify feature flag and enable prior to deployment (#3653)
* Verify feature flag and enable prior to deployment * PR feedback
1 parent eb4ea30 commit 4bf7d25

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

src/commands/deploy/deploy.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function deploy(actionContext: IActionContext, arg1: vscode.Uri | string |
6060
expectedChildContextValue: expectedContextValue
6161
}));
6262

63-
const { language, version } = await verifyInitForVSCode(context, context.effectiveDeployFsPath);
63+
const { language, languageModel, version } = await verifyInitForVSCode(context, context.effectiveDeployFsPath);
6464

6565
context.telemetry.properties.projectLanguage = language;
6666
context.telemetry.properties.projectRuntime = version;
@@ -121,7 +121,16 @@ async function deploy(actionContext: IActionContext, arg1: vscode.Uri | string |
121121
}
122122

123123
if (isZipDeploy) {
124-
await verifyAppSettings(context, node, context.projectPath, version, language, { doRemoteBuild, isConsumption }, durableStorageType);
124+
await verifyAppSettings({
125+
context,
126+
node,
127+
projectPath: context.projectPath,
128+
version,
129+
language,
130+
languageModel,
131+
bools: { doRemoteBuild, isConsumption },
132+
durableStorageType
133+
});
125134
}
126135

127136
await node.runWithTemporaryDescription(

src/commands/deploy/verifyAppSettings.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import type { StringDictionary } from '@azure/arm-appservice';
77
import type { ParsedSite } from '@microsoft/vscode-azext-azureappservice';
88
import { IActionContext } from '@microsoft/vscode-azext-utils';
99
import * as vscode from 'vscode';
10-
import { ConnectionKey, ConnectionKeyValues, DurableBackend, DurableBackendValues, extensionVersionKey, ProjectLanguage, runFromPackageKey, workerRuntimeKey } from '../../constants';
10+
import { azureWebJobsFeatureFlags, ConnectionKey, ConnectionKeyValues, DurableBackend, DurableBackendValues, extensionVersionKey, ProjectLanguage, runFromPackageKey, workerRuntimeKey } from '../../constants';
1111
import { ext } from '../../extensionVariables';
1212
import { FuncVersion, tryParseFuncVersion } from '../../FuncVersion';
1313
import { localize } from '../../localize';
1414
import { SlotTreeItem } from '../../tree/SlotTreeItem';
15+
import { isNodeV4Plus, isPythonV2Plus } from '../../utils/programmingModelUtils';
1516
import { isKnownWorkerRuntime, promptToUpdateDotnetRuntime, tryGetFunctionsWorkerRuntimeForProject } from '../../vsCodeConfig/settings';
1617
import { ISetConnectionSettingContext } from '../appSettings/connectionSettings/ISetConnectionSettingContext';
1718

@@ -20,7 +21,18 @@ import { ISetConnectionSettingContext } from '../appSettings/connectionSettings/
2021
*/
2122
type VerifyAppSettingBooleans = { doRemoteBuild: boolean | undefined; isConsumption: boolean };
2223

23-
export async function verifyAppSettings(context: IActionContext, node: SlotTreeItem, projectPath: string | undefined, version: FuncVersion, language: ProjectLanguage, bools: VerifyAppSettingBooleans, durableStorageType: DurableBackendValues | undefined): Promise<void> {
24+
export async function verifyAppSettings(options: {
25+
context: IActionContext,
26+
node: SlotTreeItem,
27+
projectPath: string | undefined,
28+
version: FuncVersion,
29+
language: ProjectLanguage,
30+
languageModel: number | undefined,
31+
bools: VerifyAppSettingBooleans,
32+
durableStorageType: DurableBackendValues | undefined
33+
}): Promise<void> {
34+
35+
const { context, node, projectPath, version, language, bools, durableStorageType } = options;
2436
const client = await node.site.createClient(context);
2537
const appSettings: StringDictionary = await client.listApplicationSettings();
2638
if (appSettings.properties) {
@@ -36,6 +48,10 @@ export async function verifyAppSettings(context: IActionContext, node: SlotTreeI
3648
updateAppSettings ||= verifyRunFromPackage(context, node.site, appSettings.properties);
3749
}
3850

51+
if (isNodeV4Plus(options) || isPythonV2Plus(options.language, options.languageModel)) {
52+
updateAppSettings ||= verifyFeatureFlagSetting(context, node.site, appSettings.properties);
53+
}
54+
3955
const updatedRemoteConnection: boolean = await verifyAndUpdateAppConnectionStrings(context, durableStorageType, appSettings.properties);
4056
updateAppSettings ||= updatedRemoteConnection;
4157

@@ -168,3 +184,21 @@ function verifyLinuxRemoteBuildSettings(context: IActionContext, remotePropertie
168184
return hasChanged;
169185
}
170186

187+
function verifyFeatureFlagSetting(context: IActionContext, site: ParsedSite, remoteProperties: { [propertyName: string]: string }): boolean {
188+
const featureFlagString = remoteProperties[azureWebJobsFeatureFlags] || '';
189+
190+
// Feature flags are comma-delimited lists of beta features
191+
// https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings#azurewebjobsfeatureflags
192+
const featureFlagArray = !featureFlagString ? [] : featureFlagString.split(',');
193+
const enableWorkerIndexingValue = 'EnableWorkerIndexing';
194+
const shouldAddSetting: boolean = !featureFlagArray.includes(enableWorkerIndexingValue);
195+
196+
if (shouldAddSetting) {
197+
featureFlagArray.push(enableWorkerIndexingValue);
198+
ext.outputChannel.appendLog(localize('addedFeatureFlag', 'Added feature flag "{0}" because it is required for the new programming model', enableWorkerIndexingValue), { resourceName: site.fullName });
199+
remoteProperties[azureWebJobsFeatureFlags] = featureFlagArray.join(',');
200+
}
201+
202+
context.telemetry.properties.addedFeatureFlagSetting = String(shouldAddSetting);
203+
return shouldAddSetting;
204+
}

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export const extensionVersionKey: string = 'FUNCTIONS_EXTENSION_VERSION';
151151
export const runFromPackageKey: string = 'WEBSITE_RUN_FROM_PACKAGE';
152152
export const contentConnectionStringKey: string = 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING';
153153
export const contentShareKey: string = 'WEBSITE_CONTENTSHARE';
154+
export const azureWebJobsFeatureFlags: string = 'AzureWebJobsFeatureFlags';
154155

155156
/**
156157
* The "current" Node.js model is 3 (and assumed, if the number is omitted).

0 commit comments

Comments
 (0)