Skip to content

Commit

Permalink
Enabling worker indexing by default
Browse files Browse the repository at this point in the history
  • Loading branch information
soninaren committed Nov 1, 2023
1 parent 6ae170c commit 7e293dc
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 53 deletions.
3 changes: 2 additions & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
- Limit dotnet-isolated specialization to 64 bit host process (#9548)
- Sending command line arguments to language workers with `functions-` prefix to prevent conflicts (#9514)
- Adding code to simulate placeholder and specilization locally (#9618)
- Enable worker indexing by default without the need for hosting config (#9574)
- Delaying execution of `LogWorkerMetadata` method until after coldstart is done. (#9627)
- Update PowerShell Worker 7.2 to 4.0.3070 [Release Note](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.3070)
- Update PowerShell Worker 7.4 to 4.0.3030 [Release Note](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.3030)
- Update Node.js Worker Version to [3.9.0](https://github.com/Azure/azure-functions-nodejs-worker/releases/tag/v3.9.0)
- Update Node.js Worker Version to [3.9.0](https://github.com/Azure/azure-functions-nodejs-worker/releases/tag/v3.9.0)
21 changes: 13 additions & 8 deletions src/WebJobs.Script/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -995,17 +995,22 @@ public static void ValidateRetryOptions(RetryOptions
}
}

// EnableWorkerIndexing set through AzureWebjobsFeatuerFlag always take precdence
// if AzureWebjobsFeatuerFlag is not set then WORKER_INDEXING_ENABLED hosting config controls stamplevel enablement
// if WORKER_INDEXING_ENABLED is set and WORKER_INDEXING_DISABLED contains the customers app name worker indexing is then disabled for that customer only
// Also Worker indexing is disabled for Logic apps
// Worker indexing is disabled for Logic apps
// EnableWorkerIndexing set through AzureWebjobsFeatureFlag always take precedence
// If AzureWebjobsFeatureFlag is not set and
// WORKER_INDEXING_DISABLED contains the customers app name worker indexing is then disabled for that customer only
public static bool CanWorkerIndex(IEnumerable<RpcWorkerConfig> workerConfigs, IEnvironment environment, FunctionsHostingConfigOptions functionsHostingConfigOptions)
{
string appName = environment.GetAzureWebsiteUniqueSlotName();
bool workerIndexingEnabled = FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagEnableWorkerIndexing, environment)
|| (functionsHostingConfigOptions.WorkerIndexingEnabled
&& !functionsHostingConfigOptions.WorkerIndexingDisabledApps.ToLowerInvariant().Split("|").Contains(appName)
&& !environment.IsLogicApp());

if (environment.IsLogicApp())
{
return false;
}

bool workerIndexingFeatureFlagSet = FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagEnableWorkerIndexing, environment);
bool workerIndexingDisabledViaHostingConfig = functionsHostingConfigOptions.WorkerIndexingDisabledApps.ToLowerInvariant().Split("|").Contains(appName);
bool workerIndexingEnabled = workerIndexingFeatureFlagSet || !workerIndexingDisabledViaHostingConfig;

if (!workerIndexingEnabled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host.Storage;
using Microsoft.Azure.WebJobs.Script;
using Microsoft.Azure.WebJobs.Script.Description;
using Microsoft.Azure.WebJobs.Script.Diagnostics;
using Microsoft.Azure.WebJobs.Script.Grpc;
using Microsoft.Azure.WebJobs.Script.Tests;
Expand Down Expand Up @@ -99,9 +103,12 @@ public static IServiceCollection AddMockedSingleton<T>(IServiceCollection servic

private static IServiceCollection AddFunctionMetadataManager(this IServiceCollection services)
{
AddMockedSingleton<IWorkerFunctionMetadataProvider>(services);
var workerMetadataProvider = new Mock<IWorkerFunctionMetadataProvider>();
workerMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(It.IsAny<IEnumerable<RpcWorkerConfig>>(), false)).Returns(Task.FromResult(new FunctionMetadataResult(true, ImmutableArray<FunctionMetadata>.Empty)));

services.AddSingleton<IHostFunctionMetadataProvider, HostFunctionMetadataProvider>();
services.AddSingleton<IFunctionMetadataProvider, FunctionMetadataProvider>();
services.AddSingleton<IWorkerFunctionMetadataProvider>(workerMetadataProvider.Object);

services.AddSingleton<IScriptHostManager>(s =>
{
Expand Down
9 changes: 7 additions & 2 deletions test/WebJobs.Script.Tests/FunctionMetadataProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Azure.WebJobs.Script.Description;
using Microsoft.Azure.WebJobs.Script.WebHost;
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
Expand Down Expand Up @@ -85,7 +86,11 @@ public void GetFunctionMetadataAsync_HostIndexing()
environment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime, "node");
environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebJobsFeatureFlags, string.Empty);
var optionsMonitor = TestHelpers.CreateOptionsMonitor(new FunctionsHostingConfigOptions());
var defaultProvider = new FunctionMetadataProvider(_logger, _workerFunctionMetadataProvider.Object, _hostFunctionMetadataProvider.Object, new OptionsWrapper<FunctionsHostingConfigOptions>(new FunctionsHostingConfigOptions()), SystemEnvironment.Instance);

var workerMetadataProvider = new Mock<IWorkerFunctionMetadataProvider>();
workerMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(It.IsAny<IEnumerable<RpcWorkerConfig>>(), false)).Returns(Task.FromResult(new FunctionMetadataResult(true, ImmutableArray<FunctionMetadata>.Empty)));

var defaultProvider = new FunctionMetadataProvider(_logger, workerMetadataProvider.Object, _hostFunctionMetadataProvider.Object, new OptionsWrapper<FunctionsHostingConfigOptions>(new FunctionsHostingConfigOptions()), SystemEnvironment.Instance);

FunctionMetadataResult result = new FunctionMetadataResult(true, functionMetadataCollection.ToImmutableArray());
_hostFunctionMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(workerConfigs, environment, false)).Returns(Task.FromResult(functionMetadataCollection.ToImmutableArray()));
Expand All @@ -97,7 +102,7 @@ public void GetFunctionMetadataAsync_HostIndexing()
Assert.Equal(1, functions.Length);
var traces = _logger.GetLogMessages();
var functionLoadLogs = traces.Where(m => string.Equals(m.FormattedMessage, "Fallback to host indexing as worker denied indexing"));
Assert.False(functionLoadLogs.Any());
Assert.True(functionLoadLogs.Any());
}

private static RawFunctionMetadata GetTestRawFunctionMetadata(bool useDefaultMetadataIndexing)
Expand Down
72 changes: 31 additions & 41 deletions test/WebJobs.Script.Tests/UtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ public void GetFunctionAppContentEditingState_Returns_Expected(bool isFileSystem
}

[Theory]
[InlineData(false, true, false)]
[InlineData(false, true, true)]
[InlineData(false, false, false)]
[InlineData(true, false, false)]
[InlineData(true, true, true)]
Expand All @@ -886,57 +886,51 @@ public void VerifyWorkerIndexingDecisionLogic(bool workerIndexingFeatureFlag, bo
}

[Theory]
[InlineData(true, true, false, "", true)]
[InlineData(true, true, true, "NonApp", true)]
[InlineData(true, true, true, "AppName", true)]
[InlineData(true, true, false, "NonApp", true)]
[InlineData(true, true, false, "AppName", true)]
public void VerifyWorkerIndexingFeatureFlagTakesPrecedence(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, bool enabledHostingConfig, string disabledHostingConfig, bool expected)
[InlineData(true, true, "", true)]
[InlineData(true, true, "NonApp", true)]
[InlineData(true, true, "AppName", true)]
public void VerifyWorkerIndexingFeatureFlagTakesPrecedence(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, string disabledHostingConfig, bool expected)
{
VerifyCanWorkerIndexUtility(workerIndexingFeatureFlag, workerIndexingConfigProperty, enabledHostingConfig, disabledHostingConfig, expected);
VerifyCanWorkerIndexUtility(workerIndexingFeatureFlag, workerIndexingConfigProperty, disabledHostingConfig, expected);
}

[Theory]
[InlineData(true, false, false, "", false)]
[InlineData(true, false, true, "NonApp", false)]
[InlineData(true, false, true, "AppName", false)]
[InlineData(true, false, false, "NonApp", false)]
[InlineData(true, false, false, "AppName", false)]
[InlineData(true, true, false, "AppName", true)]
public void VerifyWorkerConfigTakesPrecedence(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, bool enabledHostingConfig, string disabledHostingConfig, bool expected)
[InlineData(true, false, "", false)]
[InlineData(true, false, "NonApp", false)]
[InlineData(true, false, "AppName", false)]
[InlineData(true, true, "AppName", true)]
public void VerifyWorkerConfigTakesPrecedence(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, string disabledHostingConfig, bool expected)
{
VerifyCanWorkerIndexUtility(workerIndexingFeatureFlag, workerIndexingConfigProperty, enabledHostingConfig, disabledHostingConfig, expected);
VerifyCanWorkerIndexUtility(workerIndexingFeatureFlag, workerIndexingConfigProperty, disabledHostingConfig, expected);
}

[Theory]
[InlineData(false, true, true, "", true)]
[InlineData(false, true, true, "NonApp", true)]
[InlineData(false, true, false, "NonApp", false)]
[InlineData(false, false, false, "NonApp", false)]
public void VerifyStampLevelHostingConfigHonored(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, bool enabledHostingConfig, string disabledHostingConfig, bool expected)
[InlineData(false, true, "", true)]
[InlineData(false, true, "NonApp", true)]
[InlineData(false, false, "NonApp", false)]
public void VerifyStampLevelHostingConfigHonored(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, string disabledHostingConfig, bool expected)
{
VerifyCanWorkerIndexUtility(workerIndexingFeatureFlag, workerIndexingConfigProperty, enabledHostingConfig, disabledHostingConfig, expected);
VerifyCanWorkerIndexUtility(workerIndexingFeatureFlag, workerIndexingConfigProperty, disabledHostingConfig, expected);
}

[Theory]
[InlineData(false, true, true, "", true)]
[InlineData(false, true, true, "NonApp|AppName", false)]
[InlineData(false, true, true, "NonApp|AnotherAppName", true)]
[InlineData(false, true, true, "nonapp|AppName", false)]
[InlineData(false, true, true, "appname", false)]
[InlineData(false, true, true, "nonapp|appname", false)]
[InlineData(false, true, true, "NonApp|anotherAppname", true)]
[InlineData(false, false, true, "NonApp", false)]
[InlineData(false, false, true, "AppName", false)]
[InlineData(false, false, false, "Appname", false)]
[InlineData(false, true, false, "AppName", false)]
[InlineData(false, true, true, "AppName", false)]
public void VerifyDisabledAppConfigHonored(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, bool enabledHostingConfig, string disabledHostingConfig, bool expected)
[InlineData(false, true, "", true)]
[InlineData(false, true, "NonApp|AppName", false)]
[InlineData(false, true, "NonApp|AnotherAppName", true)]
[InlineData(false, true, "nonapp|AppName", false)]
[InlineData(false, true, "appname", false)]
[InlineData(false, true, "nonapp|appname", false)]
[InlineData(false, true, "NonApp|anotherAppname", true)]
[InlineData(false, false, "NonApp", false)]
[InlineData(false, false, "AppName", false)]
[InlineData(false, false, "Appname", false)]
[InlineData(false, true, "AppName", false)]
public void VerifyDisabledAppConfigHonored(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, string disabledHostingConfig, bool expected)
{
VerifyCanWorkerIndexUtility(workerIndexingFeatureFlag, workerIndexingConfigProperty, enabledHostingConfig, disabledHostingConfig, expected);
VerifyCanWorkerIndexUtility(workerIndexingFeatureFlag, workerIndexingConfigProperty, disabledHostingConfig, expected);
}

private void VerifyCanWorkerIndexUtility(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, bool enabledHostingConfig, string disabledHostingConfig, bool expected)
private void VerifyCanWorkerIndexUtility(bool workerIndexingFeatureFlag, bool workerIndexingConfigProperty, string disabledHostingConfig, bool expected)
{
var testEnv = new TestEnvironment();
testEnv.SetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime, RpcWorkerConstants.PythonLanguageWorkerName);
Expand All @@ -950,10 +944,6 @@ private void VerifyCanWorkerIndexUtility(bool workerIndexingFeatureFlag, bool wo

RpcWorkerConfig workerConfig = new RpcWorkerConfig() { Description = TestHelpers.GetTestWorkerDescription("python", "none", workerIndexingConfigProperty) };
var hostingOptions = new FunctionsHostingConfigOptions();
if (enabledHostingConfig)
{
hostingOptions.Features.Add(RpcWorkerConstants.WorkerIndexingEnabled, "1");
}

hostingOptions.Features.Add(RpcWorkerConstants.WorkerIndexingDisabledApps, disabledHostingConfig);

Expand Down

0 comments on commit 7e293dc

Please sign in to comment.