-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing selective loading for stein (#8900)
- Loading branch information
Showing
27 changed files
with
522 additions
and
592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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.Collections.Immutable; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Script.Description; | ||
using Microsoft.Azure.WebJobs.Script.Workers.Rpc; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.WebHost | ||
{ | ||
internal class FunctionMetadataProvider : IFunctionMetadataProvider | ||
{ | ||
private readonly IEnvironment _environment; | ||
private readonly ILogger<FunctionMetadataProvider> _logger; | ||
private IWorkerFunctionMetadataProvider _workerFunctionMetadataProvider; | ||
private IHostFunctionMetadataProvider _hostFunctionMetadataProvider; | ||
|
||
public FunctionMetadataProvider(ILogger<FunctionMetadataProvider> logger, IWorkerFunctionMetadataProvider workerFunctionMetadataProvider, IHostFunctionMetadataProvider hostFunctionMetadataProvider) | ||
{ | ||
_logger = logger; | ||
_workerFunctionMetadataProvider = workerFunctionMetadataProvider; | ||
_hostFunctionMetadataProvider = hostFunctionMetadataProvider; | ||
_environment = SystemEnvironment.Instance; | ||
} | ||
|
||
public ImmutableDictionary<string, ImmutableArray<string>> FunctionErrors { get; private set; } | ||
|
||
public async Task<ImmutableArray<FunctionMetadata>> GetFunctionMetadataAsync(IEnumerable<RpcWorkerConfig> workerConfigs, IEnvironment environment, bool forceRefresh = false) | ||
{ | ||
bool workerIndexing = Utility.CanWorkerIndex(workerConfigs, _environment); | ||
if (!workerIndexing) | ||
{ | ||
return await GetMetadataFromHostProvider(workerConfigs, environment, forceRefresh); | ||
} | ||
|
||
_logger.LogInformation("Worker indexing is enabled"); | ||
|
||
FunctionMetadataResult functionMetadataResult = await _workerFunctionMetadataProvider?.GetFunctionMetadataAsync(workerConfigs, SystemEnvironment.Instance, forceRefresh); | ||
FunctionErrors = _workerFunctionMetadataProvider.FunctionErrors; | ||
|
||
if (functionMetadataResult.UseDefaultMetadataIndexing) | ||
{ | ||
_logger.LogDebug("Fallback to host indexing as worker denied indexing"); | ||
return await GetMetadataFromHostProvider(workerConfigs, environment, forceRefresh); | ||
} | ||
|
||
return functionMetadataResult.Functions; | ||
} | ||
|
||
private async Task<ImmutableArray<FunctionMetadata>> GetMetadataFromHostProvider(IEnumerable<RpcWorkerConfig> workerConfigs, IEnvironment environment, bool forceRefresh = false) | ||
{ | ||
var functions = await _hostFunctionMetadataProvider?.GetFunctionMetadataAsync(workerConfigs, environment, forceRefresh); | ||
FunctionErrors = _hostFunctionMetadataProvider.FunctionErrors; | ||
return functions; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Immutable; | ||
using Microsoft.Azure.WebJobs.Script.Description; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script | ||
{ | ||
internal class FunctionMetadataResult | ||
{ | ||
public FunctionMetadataResult(bool useDefaultMetadataIndexing, ImmutableArray<FunctionMetadata> functions) | ||
{ | ||
this.UseDefaultMetadataIndexing = useDefaultMetadataIndexing; | ||
this.Functions = functions; | ||
} | ||
|
||
public bool UseDefaultMetadataIndexing { get; private set; } | ||
|
||
public ImmutableArray<FunctionMetadata> Functions { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Script.Description; | ||
using Microsoft.Azure.WebJobs.Script.Workers.Rpc; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script | ||
{ | ||
/// <summary> | ||
/// Defines an interface for fetching function metadata from function.json files | ||
/// </summary> | ||
internal interface IHostFunctionMetadataProvider | ||
{ | ||
ImmutableDictionary<string, ImmutableArray<string>> FunctionErrors { get; } | ||
|
||
/// <summary> | ||
/// Reads function metadata from function.json files present along with each function | ||
/// </summary> | ||
Task<ImmutableArray<FunctionMetadata>> GetFunctionMetadataAsync(IEnumerable<RpcWorkerConfig> workerConfigs, IEnvironment environment, bool forceRefresh = false); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/WebJobs.Script/Host/IWorkerFunctionMetadataProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Script.Workers.Rpc; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script | ||
{ | ||
/// <summary> | ||
/// Defines an interface for fetching function metadata from Out-of-Proc language workers | ||
/// </summary> | ||
internal interface IWorkerFunctionMetadataProvider | ||
{ | ||
ImmutableDictionary<string, ImmutableArray<string>> FunctionErrors { get; } | ||
|
||
/// <summary> | ||
/// Attempts to get function metadata from Out-of-Proc language workers | ||
/// </summary> | ||
/// <returns>FunctionMetadataResult that either contains the function metadata or indicates that a fall back option for fetching metadata should be used</returns> | ||
Task<FunctionMetadataResult> GetFunctionMetadataAsync(IEnumerable<RpcWorkerConfig> workerConfigs, IEnvironment environment, bool forceRefresh = false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.