-
Notifications
You must be signed in to change notification settings - Fork 469
Implementing a resolver that resolves worker configurations from specified probing paths #11258
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
base: dev
Are you sure you want to change the base?
Changes from 77 commits
e18fe94
60d4414
5b2d5ff
37ad909
b4ca3db
5bc50ee
e2349e9
c86e2e7
1e9301d
56d7918
21cfe06
d6883ab
3417d99
c8ec8bf
4b344e4
61db33b
12c95da
15bbd31
47d86f1
7ce1414
17c4209
1cbc0a7
74d77b2
6f3cb9e
d389a5e
a467a6e
5186c44
0e2056a
3b5428c
e91d86a
adb8980
8887ee1
27d80d6
236ec49
8e91769
3b1cfde
b964261
2afb262
a680663
5f84d9c
d38d1c3
7002a14
669473e
16b42fa
b0b9e49
80515a3
2109535
b3cce91
a311bf6
f9504a9
dfb1272
2c2a864
3434013
13f6cd2
6bb42af
2047ec3
c7ec15e
c8982d0
f4e1bf0
e2ffc91
cac9a74
d59514c
7271f23
a155b2f
21efd93
bc583bf
8903b5b
951f7e5
919db25
829a480
4274fd5
c8195f1
43f2176
386fb90
9d06b5f
3ea50ea
401553e
febfc3c
d082fd9
a7a76bb
61f981b
f331b38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,7 +239,18 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi | |
services.ConfigureOptionsWithChangeTokenSource<WorkerConfigurationResolverOptions, WorkerConfigurationResolverOptionsSetup, HostBuiltChangeTokenSource<WorkerConfigurationResolverOptions>>(); | ||
services.ConfigureOptionsWithChangeTokenSource<LanguageWorkerOptions, LanguageWorkerOptionsSetup, HostBuiltChangeTokenSource<LanguageWorkerOptions>>(); | ||
|
||
services.AddSingleton<IWorkerConfigurationResolver, DefaultWorkerConfigurationResolver>(); | ||
services.AddSingleton<IWorkerConfigurationResolver>(p => | ||
{ | ||
var workerConfigurationResolverOptions = p.GetService<IOptionsMonitor<WorkerConfigurationResolverOptions>>(); | ||
var workerProfileManager = p.GetService<IWorkerProfileManager>(); | ||
var loggerFactory = p.GetService<ILoggerFactory>(); | ||
var metricsLogger = p.GetService<IMetricsLogger>(); | ||
|
||
return workerConfigurationResolverOptions?.CurrentValue?.IsDynamicWorkerResolutionEnabled is true ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
new DynamicWorkerConfigurationResolver(loggerFactory, metricsLogger, FileUtility.Instance, workerProfileManager, SystemRuntimeInformation.Instance, workerConfigurationResolverOptions) : | ||
new DefaultWorkerConfigurationResolver(loggerFactory, metricsLogger, FileUtility.Instance, workerProfileManager, SystemRuntimeInformation.Instance, workerConfigurationResolverOptions); | ||
}); | ||
|
||
services.TryAddSingleton<IDependencyValidator, DependencyValidator>(); | ||
services.TryAddSingleton<IJobHostMiddlewarePipeline>(s => DefaultMiddlewarePipeline.Empty); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ public static class ScriptConstants | |
public const string FeatureFlagDisableWebHostLogForwarding = "DisableWebHostLogForwarding"; | ||
public const string FeatureFlagDisableMergedWebHostScriptHostConfiguration = "DisableMergedConfiguration"; | ||
public const string FeatureFlagEnableWorkerIndexing = "EnableWorkerIndexing"; | ||
public const string FeatureFlagDisableDynamicWorkerResolution = "DisableDynamicWorkerResolution"; | ||
public const string FeatureFlagEnableDebugTracing = "EnableDebugTracing"; | ||
public const string FeatureFlagEnableProxies = "EnableProxies"; | ||
public const string FeatureFlagStrictHISModeEnabled = "StrictHISModeEnabled"; | ||
|
@@ -248,6 +249,7 @@ public static class ScriptConstants | |
public static readonly long DefaultMaxRequestBodySize = 104857600; | ||
|
||
public static readonly ImmutableArray<string> SystemLogCategoryPrefixes = ImmutableArray.Create("Microsoft.Azure.WebJobs.", "Function.", "Worker.", "Host."); | ||
public static readonly ImmutableHashSet<string> HostCapabilities = ImmutableHashSet.Create<string>(StringComparer.OrdinalIgnoreCase); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is immutable, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Today, we don't have any capability that requires negotiation. But if in future, we introduce a capability then we can add in this structure? For example, there is a new feature "feature1" and during worker probing we want to make sure that host supports "feature1" then we can add as follows in that Host version. HostCapabilities = ImmutableHashSet.Create<string>("feature1", "feature2"); |
||
|
||
public static readonly string FunctionMetadataDirectTypeKey = "DirectType"; | ||
public static readonly string LiveLogsSessionAIKey = "#AzFuncLiveLogsSessionId"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.IO.Abstractions; | ||
using Microsoft.Azure.WebJobs.Script.Diagnostics; | ||
using Microsoft.Azure.WebJobs.Script.Diagnostics.Extensions; | ||
using Microsoft.Azure.WebJobs.Script.Workers.Profiles; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
|
@@ -15,36 +18,75 @@ internal sealed class DefaultWorkerConfigurationResolver : IWorkerConfigurationR | |
{ | ||
private readonly ILogger _logger; | ||
private readonly IOptionsMonitor<WorkerConfigurationResolverOptions> _workerConfigurationResolverOptions; | ||
private readonly IMetricsLogger _metricsLogger; | ||
private readonly IWorkerProfileManager _profileManager; | ||
private readonly IFileSystem _fileSystem; | ||
private readonly ISystemRuntimeInformation _systemRuntimeInformation; | ||
|
||
public DefaultWorkerConfigurationResolver(ILoggerFactory loggerFactory, | ||
IMetricsLogger metricsLogger, | ||
IFileSystem fileSystem, | ||
IWorkerProfileManager workerProfileManager, | ||
ISystemRuntimeInformation systemRuntimeInformation, | ||
IOptionsMonitor<WorkerConfigurationResolverOptions> workerConfigurationResolverOptions) | ||
{ | ||
ArgumentNullException.ThrowIfNull(loggerFactory); | ||
_logger = loggerFactory.CreateLogger(ScriptConstants.LogCategoryWorkerConfig); | ||
_workerConfigurationResolverOptions = workerConfigurationResolverOptions ?? throw new ArgumentNullException(nameof(workerConfigurationResolverOptions)); | ||
_metricsLogger = metricsLogger ?? throw new ArgumentNullException(nameof(metricsLogger)); | ||
|
||
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); | ||
_profileManager = workerProfileManager ?? throw new ArgumentNullException(nameof(workerProfileManager)); | ||
_systemRuntimeInformation = systemRuntimeInformation ?? throw new ArgumentNullException(nameof(systemRuntimeInformation)); | ||
ArgumentNullException.ThrowIfNull(_workerConfigurationResolverOptions.CurrentValue); | ||
} | ||
|
||
public WorkerConfigurationInfo GetConfigurationInfo() | ||
public Dictionary<string, RpcWorkerConfig> GetWorkerConfigs() | ||
{ | ||
var workersRootDirPath = _workerConfigurationResolverOptions.CurrentValue.WorkersRootDirPath; | ||
_logger.DefaultWorkersDirectoryPath(workersRootDirPath); | ||
_logger.DefaultWorkersDirectoryPath(_workerConfigurationResolverOptions.CurrentValue.WorkersRootDirPath); | ||
|
||
var workerConfigPaths = new List<string>(); | ||
return ResolveWorkerConfigsFromWithinHost(_workerConfigurationResolverOptions.CurrentValue, | ||
_logger, | ||
_fileSystem, | ||
_metricsLogger, | ||
_systemRuntimeInformation, | ||
_profileManager); | ||
} | ||
|
||
internal static Dictionary<string, RpcWorkerConfig> ResolveWorkerConfigsFromWithinHost(WorkerConfigurationResolverOptions resolverOptions, | ||
surgupta-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
ILogger logger, | ||
IFileSystem fileSystem, | ||
IMetricsLogger metricsLogger, | ||
ISystemRuntimeInformation systemRuntimeInformation, | ||
IWorkerProfileManager profileManager, | ||
Dictionary<string, RpcWorkerConfig> availableRuntimeToConfigMap = null) | ||
{ | ||
// `availableRuntimeToConfigMap` could be partially filled by DynamicWorkerConfigurationResolver, which searches for worker configs in probing paths. | ||
// This applies to scenarios such as multi-language worker environment and placeholder mode where some worker configs are found in probing paths, while remaining configs will be loaded from the default path within the Host. | ||
availableRuntimeToConfigMap = availableRuntimeToConfigMap ?? new Dictionary<string, RpcWorkerConfig>(StringComparer.OrdinalIgnoreCase); | ||
surgupta-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
foreach (var workerDir in _fileSystem.Directory.EnumerateDirectories(workersRootDirPath)) | ||
foreach (var workerPath in fileSystem.Directory.EnumerateDirectories(resolverOptions.WorkersRootDirPath)) | ||
{ | ||
string workerConfigPath = _fileSystem.Path.Combine(workerDir, RpcWorkerConstants.WorkerConfigFileName); | ||
var workerDir = Path.GetFileName(workerPath); | ||
|
||
if (availableRuntimeToConfigMap.ContainsKey(workerDir) || WorkerConfigurationHelper.ShouldSkipWorkerDirectory(resolverOptions.WorkerRuntime, workerDir, resolverOptions.IsMultiLanguageWorkerEnvironment, resolverOptions.IsPlaceholderModeEnabled)) | ||
surgupta-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
continue; | ||
} | ||
|
||
(var workerDescription, var workerConfigJson) = WorkerConfigurationHelper.GetWorkerDescriptionAndConfig(workerPath, profileManager, resolverOptions.WorkerDescriptionOverrides, logger); | ||
if (workerDescription is null || WorkerConfigurationHelper.IsWorkerDescriptionDisabled(workerDescription, logger)) | ||
{ | ||
continue; | ||
} | ||
|
||
if (_fileSystem.File.Exists(workerConfigPath)) | ||
var workerConfig = WorkerConfigurationHelper.BuildWorkerConfig(resolverOptions, workerPath, workerConfigJson, workerDescription, metricsLogger, logger, systemRuntimeInformation); | ||
surgupta-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (workerConfig is not null) | ||
{ | ||
workerConfigPaths.Add(workerDir); | ||
availableRuntimeToConfigMap[workerDir] = workerConfig; | ||
surgupta-msft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
return new WorkerConfigurationInfo(_workerConfigurationResolverOptions.CurrentValue.WorkersRootDirPath, workerConfigPaths); | ||
return availableRuntimeToConfigMap; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.