Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify feature flag and enable prior to deployment #3653

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function deploy(actionContext: IActionContext, arg1: vscode.Uri | string |
expectedChildContextValue: expectedContextValue
}));

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

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

if (isZipDeploy) {
await verifyAppSettings(context, node, context.projectPath, version, language, { doRemoteBuild, isConsumption }, durableStorageType);
await verifyAppSettings({
context,
node,
projectPath: context.projectPath,
version,
language,
languageModel,
bools: { doRemoteBuild, isConsumption },
durableStorageType
});
}

await node.runWithTemporaryDescription(
Expand Down
36 changes: 34 additions & 2 deletions src/commands/deploy/verifyAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import type { StringDictionary } from '@azure/arm-appservice';
import type { ParsedSite } from '@microsoft/vscode-azext-azureappservice';
import { IActionContext } from '@microsoft/vscode-azext-utils';
import * as vscode from 'vscode';
import { ConnectionKey, ConnectionKeyValues, DurableBackend, DurableBackendValues, extensionVersionKey, ProjectLanguage, runFromPackageKey, workerRuntimeKey } from '../../constants';
import { azureWebJobsFeatureFlags, ConnectionKey, ConnectionKeyValues, DurableBackend, DurableBackendValues, extensionVersionKey, ProjectLanguage, runFromPackageKey, workerRuntimeKey } from '../../constants';
import { ext } from '../../extensionVariables';
import { FuncVersion, tryParseFuncVersion } from '../../FuncVersion';
import { localize } from '../../localize';
import { SlotTreeItem } from '../../tree/SlotTreeItem';
import { isNodeV4Plus } from '../../utils/programmingModelUtils';
import { isKnownWorkerRuntime, promptToUpdateDotnetRuntime, tryGetFunctionsWorkerRuntimeForProject } from '../../vsCodeConfig/settings';
import { ISetConnectionSettingContext } from '../appSettings/connectionSettings/ISetConnectionSettingContext';

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

export async function verifyAppSettings(context: IActionContext, node: SlotTreeItem, projectPath: string | undefined, version: FuncVersion, language: ProjectLanguage, bools: VerifyAppSettingBooleans, durableStorageType: DurableBackendValues | undefined): Promise<void> {
export async function verifyAppSettings(options: {
context: IActionContext,
node: SlotTreeItem,
projectPath: string | undefined,
version: FuncVersion,
language: ProjectLanguage,
languageModel: number | undefined,
bools: VerifyAppSettingBooleans,
durableStorageType: DurableBackendValues | undefined
}): Promise<void> {

const { context, node, projectPath, version, language, bools, durableStorageType } = options;
const client = await node.site.createClient(context);
const appSettings: StringDictionary = await client.listApplicationSettings();
if (appSettings.properties) {
Expand All @@ -32,6 +44,8 @@ export async function verifyAppSettings(context: IActionContext, node: SlotTreeI
if (node.site.isLinux) {
const remoteBuildSettingsChanged = verifyLinuxRemoteBuildSettings(context, appSettings.properties, bools);
updateAppSettings ||= remoteBuildSettingsChanged;
} else if (isNodeV4Plus(options)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also applies when isPythonV2Plus

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be its own if case instead of in an else if. The new Node.js programming model can be run on both windows and linux

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah doh, obviously.

updateAppSettings ||= verifyFeatureFlags(context, node.site, appSettings.properties);
} else {
updateAppSettings ||= verifyRunFromPackage(context, node.site, appSettings.properties);
}
Expand Down Expand Up @@ -168,3 +182,21 @@ function verifyLinuxRemoteBuildSettings(context: IActionContext, remotePropertie
return hasChanged;
}

function verifyFeatureFlags(context: IActionContext, site: ParsedSite, remoteProperties: { [propertyName: string]: string }): boolean {
const featureFlagString = remoteProperties[azureWebJobsFeatureFlags] || '';

// Feature flags are comma-delimited lists of beta features
// https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings#azurewebjobsfeatureflags
const featureFlagArray = !featureFlagString ? [] : featureFlagString.split(',');
const enableWorkerIndexingValue = 'EnableWorkerIndexing';
const shouldAddSetting: boolean = !featureFlagArray.includes(enableWorkerIndexingValue);

if (shouldAddSetting) {
featureFlagArray.push(enableWorkerIndexingValue);
ext.outputChannel.appendLog(localize('addedFeatureFlag', 'Added feature flag "{0}" because it is required for the Node v4 programming model', enableWorkerIndexingValue), { resourceName: site.fullName });
remoteProperties[azureWebJobsFeatureFlags] = featureFlagArray.join(',');
}

context.telemetry.properties.addedRunFromPackage = String(shouldAddSetting);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either remove this line or change addedRunFromPackage to something more accurate - depending if you want to track this in telemetry

return shouldAddSetting;
}
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const extensionVersionKey: string = 'FUNCTIONS_EXTENSION_VERSION';
export const runFromPackageKey: string = 'WEBSITE_RUN_FROM_PACKAGE';
export const contentConnectionStringKey: string = 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING';
export const contentShareKey: string = 'WEBSITE_CONTENTSHARE';
export const azureWebJobsFeatureFlags: string = 'AzureWebJobsFeatureFlags';

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