Skip to content

Commit ca8eecf

Browse files
Implementing a resolver that resolves worker configurations from specified probing paths (#11258)
1 parent 9614ca4 commit ca8eecf

File tree

39 files changed

+2593
-673
lines changed

39 files changed

+2593
-673
lines changed

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Emit diagnostic warning for deprecated Azure Functions Proxies usage (#11405)
77
- Update Python Worker Version to [4.40.2](https://github.com/Azure/azure-functions-python-worker/releases/tag/4.40.2)
88
- Add JitTrace Files for v4.1044
9+
- Implementing a resolver that resolves worker configurations from specified probing paths (#11258)
910
- Remove duplicate function names from sync triggers payload(#11371)
1011
- Avoid emitting empty tag values for health check metrics (#11393)
1112
- Run health checks from the active ScriptHost (#11410)

src/WebJobs.Script.WebHost/WebHostServiceCollectionExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi
238238
// Refresh WorkerConfigurationResolverOptions and LanguageWorkerOptions when HostBuiltChangeTokenSource is triggered.
239239
services.ConfigureOptionsWithChangeTokenSource<WorkerConfigurationResolverOptions, WorkerConfigurationResolverOptionsSetup, HostBuiltChangeTokenSource<WorkerConfigurationResolverOptions>>();
240240
services.ConfigureOptionsWithChangeTokenSource<LanguageWorkerOptions, LanguageWorkerOptionsSetup, HostBuiltChangeTokenSource<LanguageWorkerOptions>>();
241+
services.AddSingleton(SystemRuntimeInformation.Instance);
242+
services.AddSingleton<IWorkerConfigurationResolver, WorkerConfigurationResolver>();
243+
services.AddSingleton<IWorkerConfigurationProvider, DefaultWorkerConfigurationProvider>();
244+
services.AddSingleton<IWorkerConfigurationProvider, DynamicWorkerConfigurationProvider>();
245+
services.AddSingleton<IWorkerConfigurationProvider, ExplicitWorkerConfigurationProvider>();
241246

242-
services.AddSingleton<IWorkerConfigurationResolver, DefaultWorkerConfigurationResolver>();
243247
services.TryAddSingleton<IDependencyValidator, DependencyValidator>();
244248
services.TryAddSingleton<IJobHostMiddlewarePipeline>(s => DefaultMiddlewarePipeline.Empty);
245249

src/WebJobs.Script/Config/FunctionsHostingConfigOptions.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ internal string WorkerIndexingDisabledApps
7070
}
7171
}
7272

73+
/// <summary>
74+
/// Gets a string delimited by '|' that contains the names of the language workers available through probing paths outside of the Host.
75+
/// </summary>
76+
internal string WorkersAvailableForDynamicResolution
77+
{
78+
get
79+
{
80+
return GetFeature(RpcWorkerConstants.WorkersAvailableForDynamicResolution) ?? string.Empty;
81+
}
82+
}
83+
84+
/// <summary>
85+
/// Gets a string delimited by '|' that contains the versions of language workers to be ignored during probing outside of the Host.
86+
/// Example value: "Worker1Name:Version1|Worker1Name:Version2|Worker2Name:Version1|Worker3Name:Version1".
87+
/// </summary>
88+
internal string IgnoredWorkerVersions
89+
{
90+
get
91+
{
92+
return GetFeature(RpcWorkerConstants.IgnoredWorkerVersions) ?? string.Empty;
93+
}
94+
}
95+
7396
/// <summary>
7497
/// Gets a value indicating whether Linux Log Backoff is disabled in the hosting config.
7598
/// </summary>

src/WebJobs.Script/Diagnostics/Extensions/LoggerExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;

src/WebJobs.Script/Environment/EnvironmentExtensions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@ public static bool IsWindowsElasticPremium(this IEnvironment environment)
278278
return string.Equals(value, ScriptConstants.ElasticPremiumSku, StringComparison.OrdinalIgnoreCase);
279279
}
280280

281+
/// <summary>
282+
/// Gets a value indicating whether the application is running in a Windows App Service environment.
283+
/// </summary>
284+
/// <param name="environment">The environment to verify.</param>
285+
/// <returns><see cref="true"/> if running in a Windows App Service app; otherwise, false.</returns>
286+
public static bool IsHostedWindowsEnvironment(this IEnvironment environment)
287+
{
288+
return environment.IsWindowsAzureManagedHosting() || environment.IsWindowsConsumption() || environment.IsWindowsElasticPremium();
289+
}
290+
281291
public static bool IsDynamicSku(this IEnvironment environment)
282292
{
283293
return environment.IsConsumptionSku() || environment.IsWindowsElasticPremium();
@@ -696,6 +706,16 @@ public static bool IsInProc(this IEnvironment environment, string workerRuntime
696706
return string.IsNullOrEmpty(workerRuntime) || string.Equals(workerRuntime, RpcWorkerConstants.DotNetLanguageWorkerName, StringComparison.OrdinalIgnoreCase);
697707
}
698708

709+
/// <summary>
710+
/// Returns the Antares platform release channel specified by the environment variable.
711+
/// Value of this setting could be "LATEST", "STANDARD" or "EXTENDED".
712+
/// If the environment variable is not set, the method returns the default value "LATEST".
713+
/// </summary>
714+
public static string GetPlatformReleaseChannel(this IEnvironment environment)
715+
{
716+
return environment.GetEnvironmentVariable(AntaresPlatformReleaseChannel) ?? ScriptConstants.LatestPlatformChannelNameUpper;
717+
}
718+
699719
public static bool IsApplicationInsightsAgentEnabled(this IEnvironment environment)
700720
{
701721
// cache the value of the environment variable

src/WebJobs.Script/Environment/EnvironmentSettingNames.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static class EnvironmentSettingNames
3535
public const string AppInsightsAgent = "APPLICATIONINSIGHTS_ENABLE_AGENT";
3636
public const string FunctionsExtensionVersion = "FUNCTIONS_EXTENSION_VERSION";
3737
public const string FunctionWorkerRuntime = "FUNCTIONS_WORKER_RUNTIME";
38+
public const string WorkerProbingPaths = "WORKER_PROBING_PATHS";
3839
public const string ContainerName = "CONTAINER_NAME";
3940
public const string WebsitePodName = "WEBSITE_POD_NAME";
4041
public const string LegionServiceHost = "LEGION_SERVICE_HOST";

src/WebJobs.Script/JsonSerializerOptionsProvider.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public static class JsonSerializerOptionsProvider
1919
/// </summary>
2020
public static readonly JsonSerializerOptions Options = CreateJsonOptions();
2121

22+
/// <summary>
23+
/// Shared Json serializer with the following setting:
24+
/// - PropertyNameCaseInsensitive: true.
25+
/// </summary>
26+
public static readonly JsonSerializerOptions CaseInsensitiveJsonSerializerOptions = CreateCaseInsensitiveJsonOptions();
27+
2228
private static JsonSerializerOptions CreateJsonOptions()
2329
{
2430
var options = new JsonSerializerOptions
@@ -32,5 +38,10 @@ private static JsonSerializerOptions CreateJsonOptions()
3238

3339
return options;
3440
}
41+
42+
private static JsonSerializerOptions CreateCaseInsensitiveJsonOptions()
43+
{
44+
return new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
45+
}
3546
}
36-
}
47+
}

src/WebJobs.Script/ScriptConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Collections.Immutable;
67
using NuGet.Versioning;
78

@@ -133,6 +134,7 @@ public static class ScriptConstants
133134
public const string FeatureFlagDisableWebHostLogForwarding = "DisableWebHostLogForwarding";
134135
public const string FeatureFlagDisableMergedWebHostScriptHostConfiguration = "DisableMergedConfiguration";
135136
public const string FeatureFlagEnableWorkerIndexing = "EnableWorkerIndexing";
137+
public const string FeatureFlagDisableDynamicWorkerResolution = "DisableDynamicWorkerResolution";
136138
public const string FeatureFlagEnableDebugTracing = "EnableDebugTracing";
137139
public const string FeatureFlagEnableProxies = "EnableProxies";
138140
public const string FeatureFlagStrictHISModeEnabled = "StrictHISModeEnabled";
@@ -251,6 +253,7 @@ public static class ScriptConstants
251253
public static readonly long DefaultMaxRequestBodySize = 104857600;
252254

253255
public static readonly ImmutableArray<string> SystemLogCategoryPrefixes = ImmutableArray.Create("Microsoft.Azure.WebJobs.", "Function.", "Worker.", "Host.");
256+
public static readonly IReadOnlySet<string> HostCapabilities = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
254257

255258
public static readonly string FunctionMetadataDirectTypeKey = "DirectType";
256259
public static readonly string LiveLogsSessionAIKey = "#AzFuncLiveLogsSessionId";
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO.Abstractions;
7+
using Microsoft.Azure.WebJobs.Script.Diagnostics;
8+
using Microsoft.Azure.WebJobs.Script.Diagnostics.Extensions;
9+
using Microsoft.Azure.WebJobs.Script.Workers.Profiles;
10+
using Microsoft.Extensions.Logging;
11+
using Microsoft.Extensions.Options;
12+
13+
namespace Microsoft.Azure.WebJobs.Script.Workers.Rpc.Configuration
14+
{
15+
/// <summary>
16+
/// This class resolves worker configurations by scanning the "workers" directory within the Host for worker config files.
17+
/// </summary>
18+
internal sealed class DefaultWorkerConfigurationProvider : WorkerConfigurationProviderBase
19+
{
20+
private readonly IFileSystem _fileSystem;
21+
private readonly ILogger _logger;
22+
23+
public DefaultWorkerConfigurationProvider(
24+
ILoggerFactory loggerFactory,
25+
IMetricsLogger metricsLogger,
26+
IFileSystem fileSystem,
27+
IWorkerProfileManager workerProfileManager,
28+
ISystemRuntimeInformation systemRuntimeInformation,
29+
IOptionsMonitor<WorkerConfigurationResolverOptions> workerConfigurationResolverOptions)
30+
: base(metricsLogger, workerProfileManager, systemRuntimeInformation, workerConfigurationResolverOptions)
31+
{
32+
ArgumentNullException.ThrowIfNull(loggerFactory);
33+
_logger = loggerFactory.CreateLogger(ScriptConstants.LogCategoryWorkerConfig);
34+
_fileSystem = fileSystem;
35+
}
36+
37+
public override ILogger Logger { get => _logger; }
38+
39+
public override int Priority { get => 2; }
40+
41+
public override void PopulateWorkerConfigs(Dictionary<string, RpcWorkerConfig> workerRuntimeToConfigMap)
42+
{
43+
Logger.DefaultWorkersDirectoryPath(WorkerResolverOptions.WorkersRootDirPath);
44+
45+
// Resolves worker configurations by scanning the "workers" directory within the Host.
46+
foreach (var workerPath in _fileSystem.Directory.EnumerateDirectories(WorkerResolverOptions.WorkersRootDirPath))
47+
{
48+
var workerDirName = _fileSystem.Path.GetFileName(workerPath);
49+
AddProvider(WorkerResolverOptions, workerDirName, workerPath, workerRuntimeToConfigMap);
50+
}
51+
}
52+
}
53+
}

src/WebJobs.Script/Workers/Rpc/Configuration/DefaultWorkerConfigurationResolver.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)