Skip to content

Commit 9823a46

Browse files
authored
Fixed incorrect function count in the log message when getting function metadata from providers (#10224)
* Fixed incorrect function count in the log message.(#10220) * Minor variable rename * Check DefaultOrEmpty before accessing Length of immutable array. * Fix integration test to reflect the change.
1 parent f138d7c commit 9823a46

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

release_notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
- Ensuring proxies are disabled, with a warning, when running in Flex Consumption.
1616
- Fixed an issue leading to a race when invocation responses returned prior to HTTP requests being sent in proxied scenarios.
1717
- Language worker channels will not be started during placeholder mode if we are in-process (#10161)
18-
- Ordered invocations are now the default (#10201)
18+
- Ordered invocations are now the default (#10201)
19+
- Fixed incorrect function count in the log message.(#10220)

src/WebJobs.Script/Host/FunctionMetadataManager.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ private void AddMetadataFromCustomProviders(IEnumerable<IFunctionProvider> funct
222222
functionProviderTasks.Add(functionProvider.GetFunctionMetadataAsync());
223223
}
224224

225-
var functionMetadataListArray = Task.WhenAll(functionProviderTasks).GetAwaiter().GetResult();
225+
var providerFunctionMetadataResults = Task.WhenAll(functionProviderTasks).GetAwaiter().GetResult();
226+
var totalFunctionsCount = providerFunctionMetadataResults.Where(metadataArray => !metadataArray.IsDefaultOrEmpty).Sum(metadataArray => metadataArray.Length);
226227

227228
// This is used to make sure no duplicates are registered
228229
var distinctFunctionNames = new HashSet<string>(functionMetadataList.Select(m => m.Name));
229230

230-
_logger.FunctionsReturnedByProvider(functionMetadataListArray.Length, _metadataProviderName);
231+
_logger.FunctionsReturnedByProvider(totalFunctionsCount, _metadataProviderName);
231232

232-
foreach (var metadataArray in functionMetadataListArray)
233+
foreach (var metadataArray in providerFunctionMetadataResults)
233234
{
234235
if (!metadataArray.IsDefaultOrEmpty)
235236
{

test/WebJobs.Script.Tests.Integration/ApplicationInsights/ApplicationInsightsEndToEndTestsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ await TestHelpers.Await(() =>
278278
Assert.True(traces.Length == expectedCount, $"Expected {expectedCount} messages, but found {traces.Length}. Actual logs:{Environment.NewLine}{string.Join(Environment.NewLine, traces.Select(t => t.Message))}");
279279

280280
int idx = 0;
281-
ValidateTrace(traces[idx++], "1 functions found", LogCategories.Startup);
281+
ValidateTrace(traces[idx++], "0 functions found", LogCategories.Startup);
282282
ValidateTrace(traces[idx++], "2 functions loaded", LogCategories.Startup);
283283
ValidateTrace(traces[idx++], "A function allow list has been specified", LogCategories.Startup);
284284
ValidateTrace(traces[idx++], "Found the following functions:\r\n", LogCategories.Startup);

test/WebJobs.Script.Tests/FunctionMetadataManagerTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,55 @@ public void FunctionMetadataManager_DoesNotError_MissingScriptFile_InWebHostMode
138138
Assert.False(testFunctionMetadataManager.IsScriptFileDetermined(testMetadata));
139139
}
140140

141+
[Fact]
142+
public void FunctionMetadataManager_GetsMetadata_FromMultipleFunctionProviders_Success()
143+
{
144+
var functionMetadataCollection1 = new Collection<FunctionMetadata>
145+
{
146+
GetTestFunctionMetadata("somefile.dll", name: "HelloHttp")
147+
};
148+
149+
var functionMetadataCollection2 = new Collection<FunctionMetadata>
150+
{
151+
GetTestFunctionMetadata("somefile2.dll", name: "Function1"),
152+
GetTestFunctionMetadata("somefile2.dll", name: "Function2"),
153+
GetTestFunctionMetadata("somefile2.dll", name: "Function3")
154+
};
155+
156+
var expectedTotalFunctionsCount = functionMetadataCollection1.Count + functionMetadataCollection2.Count;
157+
158+
var mockFunctionMetadataProvider = new Mock<IFunctionMetadataProvider>();
159+
mockFunctionMetadataProvider.Setup(m => m.GetFunctionMetadataAsync(It.IsAny<IEnumerable<RpcWorkerConfig>>(), It.IsAny<SystemEnvironment>(), It.IsAny<bool>()))
160+
.Returns(Task.FromResult(new Collection<FunctionMetadata>().ToImmutableArray()));
161+
mockFunctionMetadataProvider.Setup(m => m.FunctionErrors)
162+
.Returns(new Dictionary<string, ICollection<string>>().ToImmutableDictionary(kvp => kvp.Key, kvp => kvp.Value.ToImmutableArray()));
163+
164+
var mockFunctionProvider = new Mock<IFunctionProvider>();
165+
mockFunctionProvider.Setup(m => m.GetFunctionMetadataAsync()).ReturnsAsync(functionMetadataCollection1.ToImmutableArray());
166+
167+
var mockFunctionProvider2 = new Mock<IFunctionProvider>();
168+
mockFunctionProvider2.Setup(m => m.GetFunctionMetadataAsync()).ReturnsAsync(functionMetadataCollection2.ToImmutableArray());
169+
170+
var testLoggerProvider = new TestLoggerProvider();
171+
var loggerFactory = new LoggerFactory();
172+
loggerFactory.AddProvider(testLoggerProvider);
173+
174+
FunctionMetadataManager testFunctionMetadataManager = TestFunctionMetadataManager.GetFunctionMetadataManager(
175+
new OptionsWrapper<ScriptJobHostOptions>(_scriptJobHostOptions),
176+
mockFunctionMetadataProvider.Object,
177+
new List<IFunctionProvider>() { mockFunctionProvider.Object, mockFunctionProvider2.Object },
178+
new OptionsWrapper<HttpWorkerOptions>(_defaultHttpWorkerOptions),
179+
loggerFactory,
180+
new TestOptionsMonitor<LanguageWorkerOptions>(TestHelpers.GetTestLanguageWorkerOptions()));
181+
182+
var actualFunctionMetadata = testFunctionMetadataManager.LoadFunctionMetadata();
183+
184+
var traces = testLoggerProvider.GetAllLogMessages();
185+
Assert.Equal(expectedTotalFunctionsCount, actualFunctionMetadata.Length);
186+
Assert.Single(traces.Where(t => t.FormattedMessage.Contains("Reading functions metadata (Custom)")));
187+
Assert.Single(traces.Where(t => t.FormattedMessage.Contains($"{expectedTotalFunctionsCount} functions found (Custom)")));
188+
}
189+
141190
[Fact]
142191
public void FunctionMetadataManager_GetsMetadata_FromFunctionProviders()
143192
{

0 commit comments

Comments
 (0)