Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<!-- Please add your release notes in the following format:
- My change description (#PR)
-->
Add JitTrace Files for v4.46
- Refactor functions worker runtime retrieval to use `IWorkerRuntimeResolver` abstraction (#11511)
- Add JitTrace Files for v4.46
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public FunctionInvocationDispatcherFactory(IOptions<ScriptJobHostOptions> script
IRpcFunctionInvocationDispatcherLoadBalancer functionDispatcherLoadBalancer,
IOptions<WorkerConcurrencyOptions> workerConcurrencyOptions,
IOptions<FunctionsHostingConfigOptions> hostingConfigOptions,
IHostMetrics hostMetrics)
IHostMetrics hostMetrics,
IWorkerRuntimeResolver workerRuntimeResolver)
{
if (httpWorkerOptions.Value == null)
{
Expand All @@ -61,7 +62,8 @@ public FunctionInvocationDispatcherFactory(IOptions<ScriptJobHostOptions> script
functionDispatcherLoadBalancer,
workerConcurrencyOptions,
hostingConfigOptions,
hostMetrics);
hostMetrics,
workerRuntimeResolver);
}

public IFunctionInvocationDispatcher GetFunctionDispatcher() => _functionDispatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ namespace Microsoft.Azure.WebJobs.Script.Workers.Http
{
internal class HttpWorkerOptionsSetup : IConfigureOptions<HttpWorkerOptions>, IValidateOptions<HttpWorkerOptions>
{
private readonly IEnvironment _environment;
private readonly IWorkerRuntimeResolver _workerRuntimeResolver;
private IConfiguration _configuration;
private ILogger _logger;
private IMetricsLogger _metricsLogger;
private ScriptJobHostOptions _scriptJobHostOptions;
private string argumentsSectionName = $"{WorkerConstants.WorkerDescription}:arguments";
private string workerArgumentsSectionName = $"{WorkerConstants.WorkerDescription}:workerArguments";

public HttpWorkerOptionsSetup(IOptions<ScriptJobHostOptions> scriptJobHostOptions, IConfiguration configuration, ILoggerFactory loggerFactory, IMetricsLogger metricsLogger, IEnvironment environment)
public HttpWorkerOptionsSetup(
IOptions<ScriptJobHostOptions> scriptJobHostOptions,
IConfiguration configuration,
ILoggerFactory loggerFactory,
IMetricsLogger metricsLogger,
IWorkerRuntimeResolver workerRuntimeResolver)
{
ArgumentNullException.ThrowIfNull(environment);
_scriptJobHostOptions = scriptJobHostOptions.Value;
_configuration = configuration;
_metricsLogger = metricsLogger;
_logger = loggerFactory.CreateLogger<HttpWorkerOptionsSetup>();
_environment = environment;
_workerRuntimeResolver = workerRuntimeResolver;
}

public void Configure(HttpWorkerOptions options)
Expand Down Expand Up @@ -73,7 +77,7 @@ private void ConfigureWorkerDescription(HttpWorkerOptions options, IConfiguratio
{
workerSection.Bind(options);

var workerRuntime = _environment.GetFunctionsWorkerRuntime();
var workerRuntime = _workerRuntimeResolver.GetWorkerRuntime();
if (string.Equals(workerRuntime, RpcWorkerConstants.CustomHandlerLanguageWorkerName, StringComparison.OrdinalIgnoreCase))
{
options.CustomRoutesEnabled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public RpcFunctionInvocationDispatcher(IOptions<ScriptJobHostOptions> scriptHost
IRpcFunctionInvocationDispatcherLoadBalancer functionDispatcherLoadBalancer,
IOptions<WorkerConcurrencyOptions> workerConcurrencyOptions,
IOptions<FunctionsHostingConfigOptions> hostingConfigOptions,
IHostMetrics hostMetrics)
IHostMetrics hostMetrics,
IWorkerRuntimeResolver workerRuntimeResolver)
{
_metricsLogger = metricsLogger;
_scriptOptions = scriptHostOptions.Value;
Expand All @@ -95,7 +96,7 @@ public RpcFunctionInvocationDispatcher(IOptions<ScriptJobHostOptions> scriptHost
_managedDependencyOptions = managedDependencyOptions ?? throw new ArgumentNullException(nameof(managedDependencyOptions));
_logger = loggerFactory.CreateLogger<RpcFunctionInvocationDispatcher>();
_rpcWorkerChannelFactory = rpcWorkerChannelFactory;
_workerRuntime = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
_workerRuntime = workerRuntimeResolver.GetWorkerRuntime();
_functionDispatcherLoadBalancer = functionDispatcherLoadBalancer;
_workerConcurrencyOptions = workerConcurrencyOptions;
_hostingConfigOptions = hostingConfigOptions;
Expand Down Expand Up @@ -198,7 +199,7 @@ internal async Task InitializeWebhostLanguageWorkerChannel(IEnumerable<string> l

internal async void ShutdownWebhostLanguageWorkerChannels()
{
_logger.LogDebug("{workerRuntimeConstant}={value}. Will shutdown all the worker channels that started in placeholder mode", EnvironmentSettingNames.FunctionWorkerRuntime, _workerRuntime);
_logger.LogDebug("{workerRuntimeConstant}={value}. Will shutdown all the worker channels that started in placeholder mode", "Functions worker runtime", _workerRuntime);
await _webHostLanguageWorkerChannelManager?.ShutdownChannelsAsync();
}

Expand Down
14 changes: 11 additions & 3 deletions src/WebJobs.Script.Grpc/Rpc/RpcInitializationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,29 @@ internal class RpcInitializationService : IManagedHostedService
private readonly IRpcServer _rpcServer;
private readonly ILogger _logger;
private readonly IOptionsMonitor<LanguageWorkerOptions> _languageWorkerOptions;
private readonly IWorkerRuntimeResolver _workerRuntimeResolver;

private readonly string _workerRuntime;
private readonly int _rpcServerShutdownTimeoutInMilliseconds;
private HashSet<string> _placeholderLanguageWorkersList = new HashSet<string>();

public RpcInitializationService(IOptionsMonitor<ScriptApplicationHostOptions> applicationHostOptions, IEnvironment environment, IRpcServer rpcServer,
IWebHostRpcWorkerChannelManager rpcWorkerChannelManager, ILogger<RpcInitializationService> logger, IOptionsMonitor<LanguageWorkerOptions> languageWorkerOptions)
public RpcInitializationService(
IOptionsMonitor<ScriptApplicationHostOptions> applicationHostOptions,
IEnvironment environment,
IRpcServer rpcServer,
IWebHostRpcWorkerChannelManager rpcWorkerChannelManager,
ILogger<RpcInitializationService> logger,
IOptionsMonitor<LanguageWorkerOptions> languageWorkerOptions,
IWorkerRuntimeResolver workerRuntimeResolver)
{
_applicationHostOptions = applicationHostOptions ?? throw new ArgumentNullException(nameof(applicationHostOptions));
_logger = logger;
_rpcServer = rpcServer;
_environment = environment;
_rpcServerShutdownTimeoutInMilliseconds = 5000;
_webHostRpcWorkerChannelManager = rpcWorkerChannelManager ?? throw new ArgumentNullException(nameof(rpcWorkerChannelManager));
_workerRuntime = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
_workerRuntimeResolver = workerRuntimeResolver;
_workerRuntime = _workerRuntimeResolver.GetWorkerRuntime();
_placeholderLanguageWorkersList = _environment.GetLanguageWorkerListToStartInPlaceholder();
_languageWorkerOptions = languageWorkerOptions;
}
Expand Down
11 changes: 7 additions & 4 deletions src/WebJobs.Script.Grpc/Rpc/WebHostRpcWorkerChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class WebHostRpcWorkerChannelManager : IWebHostRpcWorkerChannelManager
private readonly IRpcWorkerChannelFactory _rpcWorkerChannelFactory;
private readonly IMetricsLogger _metricsLogger;
private readonly IWorkerProfileManager _profileManager;
private readonly IWorkerRuntimeResolver _workerRuntimeResolver;
private string _workerRuntime;
private Action _shutdownStandbyWorkerChannels;
private IConfiguration _config;
Expand All @@ -41,7 +42,8 @@ public WebHostRpcWorkerChannelManager(IScriptEventManager eventManager,
IConfiguration config,
IWorkerProfileManager workerProfileManager,
IOptionsMonitor<LanguageWorkerOptions> languageWorkerOptions,
IOptions<FunctionsHostingConfigOptions> hostingConfigOptions)
IOptions<FunctionsHostingConfigOptions> hostingConfigOptions,
IWorkerRuntimeResolver workerRuntimeResolver)
{
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
_config = config ?? throw new ArgumentNullException(nameof(config));
Expand All @@ -64,6 +66,7 @@ public WebHostRpcWorkerChannelManager(IScriptEventManager eventManager,

_shutdownStandbyWorkerChannels = ScheduleShutdownStandbyChannels;
_shutdownStandbyWorkerChannels = _shutdownStandbyWorkerChannels.Debounce(milliseconds: 5000);
_workerRuntimeResolver = workerRuntimeResolver;
}

public Task<IRpcWorkerChannel> InitializeChannelAsync(IEnumerable<RpcWorkerConfig> workerConfigs, string runtime)
Expand Down Expand Up @@ -126,7 +129,7 @@ public IDictionary<string, TaskCompletionSource<IRpcWorkerChannel>> GetChannels(
public async Task SpecializeAsync()
{
_logger.LogInformation("Starting language worker channel specialization");
_workerRuntime = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
_workerRuntime = _workerRuntimeResolver.GetWorkerRuntime();

IRpcWorkerChannel rpcWorkerChannel = await GetChannelAsync(_workerRuntime);

Expand All @@ -152,7 +155,7 @@ public async Task SpecializeAsync()

public async Task WorkerWarmupAsync()
{
_workerRuntime = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
_workerRuntime = _workerRuntimeResolver.GetWorkerRuntime();

if (_workerRuntime == null)
{
Expand Down Expand Up @@ -305,7 +308,7 @@ internal void ScheduleShutdownStandbyChannels()
{
using (_metricsLogger.LatencyEvent(MetricEventNames.SpecializationScheduleShutdownStandbyChannels))
{
_workerRuntime = _workerRuntime ?? _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
_workerRuntime = _workerRuntime ?? _workerRuntimeResolver.GetWorkerRuntime();
if (!string.IsNullOrEmpty(_workerRuntime))
{
var standbyWorkerChannels = _workerChannels.Where(ch => !ch.Key.Equals(_workerRuntime, StringComparison.InvariantCultureIgnoreCase));
Expand Down
12 changes: 8 additions & 4 deletions src/WebJobs.Script.Grpc/WorkerFunctionMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Script.Description;
using Microsoft.Azure.WebJobs.Script.Diagnostics.Extensions;
using Microsoft.Azure.WebJobs.Script.Workers;
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -28,6 +29,7 @@ internal class WorkerFunctionMetadataProvider : IWorkerFunctionMetadataProvider,
private readonly IEnvironment _environment;
private readonly IWebHostRpcWorkerChannelManager _channelManager;
private readonly IScriptHostManager _scriptHostManager;
private readonly IWorkerRuntimeResolver _workerRuntimeResolver;
private string _workerRuntime;
private ImmutableArray<FunctionMetadata> _functions;
private IHost _currentJobHost = null;
Expand All @@ -37,14 +39,16 @@ public WorkerFunctionMetadataProvider(
ILogger<WorkerFunctionMetadataProvider> logger,
IEnvironment environment,
IWebHostRpcWorkerChannelManager webHostRpcWorkerChannelManager,
IScriptHostManager scriptHostManager)
IScriptHostManager scriptHostManager,
IWorkerRuntimeResolver workerRuntimeResolver)
{
_scriptOptions = scriptOptions;
_logger = logger;
_environment = environment;
_channelManager = webHostRpcWorkerChannelManager;
_scriptHostManager = scriptHostManager;
_workerRuntime = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
_workerRuntimeResolver = workerRuntimeResolver;
_workerRuntime = workerRuntimeResolver.GetWorkerRuntime();

_scriptHostManager.ActiveHostChanged += OnHostChanged;
}
Expand All @@ -54,7 +58,7 @@ public ImmutableDictionary<string, ImmutableArray<string>> FunctionErrors

public async Task<FunctionMetadataResult> GetFunctionMetadataAsync(IEnumerable<RpcWorkerConfig> workerConfigs, bool forceRefresh)
{
_workerRuntime = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
_workerRuntime = _workerRuntimeResolver.GetWorkerRuntime();

_logger.LogInformation("Fetching metadata for workerRuntime: {workerRuntime}", _workerRuntime);

Expand Down Expand Up @@ -236,7 +240,7 @@ internal IEnumerable<FunctionMetadata> ValidateMetadata(IEnumerable<RawFunctionM
{
Utility.ValidateName(function.Name);

function.Language = _environment.GetEnvironmentVariable(EnvironmentSettingNames.FunctionWorkerRuntime);
function.Language = _workerRuntimeResolver.GetWorkerRuntime();

// skip function directory validation because this involves reading function.json

Expand Down
6 changes: 4 additions & 2 deletions src/WebJobs.Script.WebHost/Controllers/HostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public async Task<IActionResult> GetHostStatus([FromServices] IScriptHostManager
[HttpGet]
[Route("admin/host/processes")]
[Authorize(Policy = PolicyNames.AdminAuthLevel)]
public async Task<IActionResult> GetWorkerProcesses([FromServices] IScriptHostManager scriptHostManager)
public async Task<IActionResult> GetWorkerProcesses(
[FromServices] IScriptHostManager scriptHostManager,
[FromServices] IWorkerRuntimeResolver runtimeResolver)
{
if (!Utility.TryGetHostService(scriptHostManager, out IWebHostWorkerManager webHostWorkerManager))
{
Expand All @@ -140,7 +142,7 @@ public async Task<IActionResult> GetWorkerProcesses([FromServices] IScriptHostMa
}
};

string workerRuntime = _environment.GetFunctionsWorkerRuntime();
string workerRuntime = runtimeResolver.GetWorkerRuntime();

IEnumerable<WorkerProcessInfo> workerProcesses = null;
if (Utility.TryGetHostService(scriptHostManager, out IScriptHostWorkerManager scriptHostWorkerManager))
Expand Down
Loading