Skip to content

Commit 740e92d

Browse files
Francisco-Gaminoazfuncghkshyju
authored
4.9.300 Hotfix in-proc (#11005)
* Update version to 4.39.300 * Clear release notes * Fixes circular dependency when resolving LinuxContainerLegionMetricsPublisher (#11000) (#11002) --------- Co-authored-by: Azure Functions Release <[email protected]> Co-authored-by: Shyju Krishnankutty <[email protected]>
1 parent a9edc9b commit 740e92d

File tree

9 files changed

+99
-59
lines changed

9 files changed

+99
-59
lines changed

release_notes.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
<!-- Please add your release notes in the following format:
44
- My change description (#PR)
5-
-->
6-
- Add JitTrace Files for v4.39
5+
-->

src/Directory.Version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>4.$(MinorVersionPrefix)39.200</VersionPrefix>
3+
<VersionPrefix>4.$(MinorVersionPrefix)39.300</VersionPrefix>
44
<UpdateBuildNumber>true</UpdateBuildNumber>
55
</PropertyGroup>
66
</Project>

src/WebJobs.Script.WebHost/Metrics/LinuxContainerLegionMetricsPublisher.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Azure.Functions.Platform.Metrics.LinuxConsumption;
1010
using Microsoft.Azure.WebJobs.Script.Diagnostics;
1111
using Microsoft.Azure.WebJobs.Script.WebHost.Configuration;
12+
using Microsoft.Extensions.DependencyInjection;
1213
using Microsoft.Extensions.Logging;
1314
using Microsoft.Extensions.Options;
1415

@@ -24,7 +25,7 @@ public sealed class LinuxContainerLegionMetricsPublisher : IMetricsPublisher, ID
2425
private readonly IDisposable _standbyOptionsOnChangeSubscription;
2526
private readonly IEnvironment _environment;
2627
private readonly ILogger _logger;
27-
private readonly IScriptHostManager _scriptHostManager;
28+
private readonly IServiceProvider _serviceProvider;
2829
private readonly string _containerName;
2930

3031
private IMetricsLogger _metricsLogger;
@@ -36,14 +37,14 @@ public sealed class LinuxContainerLegionMetricsPublisher : IMetricsPublisher, ID
3637

3738
public LinuxContainerLegionMetricsPublisher(IEnvironment environment, IOptionsMonitor<StandbyOptions> standbyOptions,
3839
IOptions<LinuxConsumptionLegionMetricsPublisherOptions> options, ILogger<LinuxContainerLegionMetricsPublisher> logger,
39-
IFileSystem fileSystem, ILinuxConsumptionMetricsTracker metricsTracker, IScriptHostManager scriptHostManager,
40+
IFileSystem fileSystem, ILinuxConsumptionMetricsTracker metricsTracker, IServiceProvider serviceProvider,
4041
int? metricsPublishIntervalMS = null)
4142
{
4243
_standbyOptions = standbyOptions ?? throw new ArgumentNullException(nameof(standbyOptions));
4344
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
4445
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
4546
_metricsTracker = metricsTracker ?? throw new ArgumentNullException(nameof(metricsTracker));
46-
_scriptHostManager = scriptHostManager ?? throw new ArgumentNullException(nameof(scriptHostManager));
47+
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
4748
_containerName = options.Value.ContainerName;
4849

4950
// Set this to 15 minutes worth of files
@@ -67,21 +68,7 @@ public LinuxContainerLegionMetricsPublisher(IEnvironment environment, IOptionsMo
6768
}
6869
}
6970

70-
public IMetricsLogger MetricsLogger
71-
{
72-
get
73-
{
74-
if (_metricsLogger == null)
75-
{
76-
if (!Utility.TryGetHostService<IMetricsLogger>(_scriptHostManager, out _metricsLogger))
77-
{
78-
throw new InvalidOperationException($"Unable to resolve {nameof(IMetricsLogger)} service.");
79-
}
80-
}
81-
82-
return _metricsLogger;
83-
}
84-
}
71+
private IMetricsLogger MetricsLogger => _metricsLogger ??= _serviceProvider.GetRequiredService<IMetricsLogger>();
8572

8673
public void Initialize()
8774
{

src/WebJobs.Script.WebHost/WebHostServiceCollectionExtensions.cs

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

4+
using System;
45
using System.IO.Abstractions;
56
using System.Net.Http;
67
using System.Runtime.InteropServices;
@@ -285,8 +286,8 @@ private static void AddLinuxContainerServices(this IServiceCollection services)
285286
var logger = s.GetService<ILogger<LinuxContainerLegionMetricsPublisher>>();
286287
var metricsTracker = s.GetService<ILinuxConsumptionMetricsTracker>();
287288
var standbyOptions = s.GetService<IOptionsMonitor<StandbyOptions>>();
288-
var scriptHostManager = s.GetService<IScriptHostManager>();
289-
return new LinuxContainerLegionMetricsPublisher(environment, standbyOptions, options, logger, new FileSystem(), metricsTracker, scriptHostManager);
289+
var serviceProvider = s.GetService<IServiceProvider>();
290+
return new LinuxContainerLegionMetricsPublisher(environment, standbyOptions, options, logger, new FileSystem(), metricsTracker, serviceProvider);
290291
}
291292
else if (environment.IsLinuxMetricsPublishingEnabled())
292293
{

test/WebJobs.Script.Tests.Integration/Host/StandbyManager/StandbyManagerE2ETestBase.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Web.Http;
1313
using Microsoft.AspNetCore.Hosting;
1414
using Microsoft.AspNetCore.TestHost;
15+
using Microsoft.Azure.Functions.Platform.Metrics.LinuxConsumption;
1516
using Microsoft.Azure.WebJobs.Extensions.Http;
1617
using Microsoft.Azure.WebJobs.Host.Executors;
1718
using Microsoft.Azure.WebJobs.Script.Diagnostics;
@@ -73,6 +74,7 @@ protected async Task<IWebHostBuilder> CreateWebHostBuilderAsync(string testDirNa
7374
environment.SetEnvironmentVariable(EnvironmentSettingNames.AzureWebsiteName, websiteSiteName);
7475
}
7576

77+
var testMetricsTracker = new TestMetricsTracker();
7678
var webHostBuilder = Program.CreateWebHostBuilder()
7779
.ConfigureAppConfiguration(c =>
7880
{
@@ -102,6 +104,7 @@ protected async Task<IWebHostBuilder> CreateWebHostBuilderAsync(string testDirNa
102104

103105
c.AddSingleton<IEnvironment>(_ => environment);
104106
c.AddSingleton<IMetricsLogger>(_ => _metricsLogger);
107+
c.AddSingleton<ILinuxConsumptionMetricsTracker>(_ => testMetricsTracker);
105108
})
106109
.ConfigureScriptHostLogging(b =>
107110
{
@@ -121,9 +124,9 @@ protected async Task<IWebHostBuilder> CreateWebHostBuilderAsync(string testDirNa
121124
return webHostBuilder;
122125
}
123126

124-
protected async Task InitializeTestHostAsync(string testDirName, IEnvironment environment, string websiteSiteName = TestSiteName)
127+
protected async Task<IWebHost> InitializeTestHostAsync(string testDirName, IEnvironment environment, string websiteSiteName = TestSiteName)
125128
{
126-
var webHostBuilder = await CreateWebHostBuilderAsync(testDirName, environment, websiteSiteName);
129+
IWebHostBuilder webHostBuilder = await CreateWebHostBuilderAsync(testDirName, environment, websiteSiteName);
127130
_httpServer = new TestServer(webHostBuilder);
128131
_httpClient = _httpServer.CreateClient();
129132
_httpClient.BaseAddress = new Uri("https://localhost/");
@@ -135,6 +138,8 @@ protected async Task InitializeTestHostAsync(string testDirName, IEnvironment en
135138
Assert.NotNull(traces.Single(p => p.FormattedMessage.StartsWith("Host is in standby mode")));
136139

137140
_expectedHostId = await _httpServer.Host.Services.GetService<IHostIdProvider>().GetHostIdAsync(CancellationToken.None);
141+
142+
return _httpServer.Host;
138143
}
139144

140145

test/WebJobs.Script.Tests.Integration/Host/StandbyManager/StandbyManagerE2ETests_Linux.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.Azure.WebJobs.Script.Tests.Integration.Fixtures;
1414
using Microsoft.Azure.WebJobs.Script.WebHost;
1515
using Microsoft.Azure.WebJobs.Script.WebHost.Authentication;
16+
using Microsoft.Azure.WebJobs.Script.WebHost.Metrics;
1617
using Microsoft.Azure.WebJobs.Script.WebHost.Models;
1718
using Microsoft.Azure.WebJobs.Script.WebHost.Security;
1819
using Microsoft.Azure.WebJobs.Script.Workers;
@@ -32,6 +33,43 @@ namespace Microsoft.Azure.WebJobs.Script.Tests
3233
[Trait(TestTraits.Group, TestTraits.StandbyModeTestsLinux)]
3334
public class StandbyManagerE2ETests_Linux(AzuriteFixture azurite) : StandbyManagerE2ETestBase, IClassFixture<AzuriteFixture>
3435
{
36+
[Fact]
37+
public async Task StandbyModeE2E_LinuxConsumptionOnLegion()
38+
{
39+
var vars = new Dictionary<string, string>
40+
{
41+
{ EnvironmentSettingNames.AzureWebsitePlaceholderMode, "1" },
42+
{ EnvironmentSettingNames.ContainerName, "testContainer" },
43+
{ EnvironmentSettingNames.AzureWebsiteHostName, "testapp.azurewebsites.net" },
44+
{ EnvironmentSettingNames.AzureWebsiteName, "TestApp" },
45+
{ EnvironmentSettingNames.ContainerEncryptionKey, Convert.ToBase64String(TestHelpers.GenerateKeyBytes()) },
46+
{ EnvironmentSettingNames.AzureWebsiteContainerReady, null },
47+
{ EnvironmentSettingNames.AzureWebsiteSku, "Dynamic" },
48+
{ EnvironmentSettingNames.AzureWebsiteZipDeployment, null },
49+
{ EnvironmentSettingNames.AzureWebJobsFeatureFlags, ScriptConstants.FeatureFlagEnableProxies },
50+
{ "AzureWebEncryptionKey", "0F75CA46E7EBDD39E4CA6B074D1F9A5972B849A55F91A248" },
51+
{ EnvironmentSettingNames.FunctionsTimeZone, "Europe/Berlin" },
52+
{ EnvironmentSettingNames.FunctionWorkerRuntime, "dotnet" },
53+
{ EnvironmentSettingNames.LegionServiceHost, "1"}
54+
};
55+
56+
var environment = new TestEnvironment(vars);
57+
58+
Assert.True(environment.IsLinuxConsumptionOnLegion());
59+
Assert.True(environment.IsAnyLinuxConsumption());
60+
61+
var webHost = await InitializeTestHostAsync("Linux", environment);
62+
63+
// verify the expected startup logs
64+
var logEntries = _loggerProvider.GetAllLogMessages().Where(p => p.FormattedMessage != null).ToList();
65+
Assert.True(logEntries.Any(m => m.Category == "Host.Startup" && m.FormattedMessage.Contains("Host is in standby mode")));
66+
Assert.True(logEntries.Any(cat => cat.Category == "Microsoft.Azure.WebJobs.Script.WebHost.StandbyManager"));
67+
Assert.True(logEntries.Any(cat => cat.Category == "Host.Triggers.Warmup"));
68+
69+
// verify that the expected (legion specific) implementations are resolved
70+
Assert.Equal(typeof(LinuxContainerLegionMetricsPublisher), webHost.Services.GetRequiredService<IMetricsPublisher>().GetType());
71+
}
72+
3573
[Fact]
3674
public async Task StandbyModeE2E_LinuxContainer()
3775
{
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 Microsoft.Azure.Functions.Platform.Metrics.LinuxConsumption;
7+
8+
namespace Microsoft.Azure.WebJobs.Script.Tests
9+
{
10+
public class TestMetricsTracker : ILinuxConsumptionMetricsTracker
11+
{
12+
public event EventHandler<DiagnosticEventArgs> OnDiagnosticEvent;
13+
14+
public List<FunctionActivity> FunctionActivities { get; } = new List<FunctionActivity>();
15+
16+
public List<MemoryActivity> MemoryActivities { get; } = new List<MemoryActivity>();
17+
18+
public Queue<LinuxConsumptionMetrics> MetricsQueue { get; } = new Queue<LinuxConsumptionMetrics>();
19+
20+
public void AddFunctionActivity(FunctionActivity activity)
21+
{
22+
FunctionActivities.Add(activity);
23+
}
24+
25+
public void AddMemoryActivity(MemoryActivity activity)
26+
{
27+
MemoryActivities.Add(activity);
28+
}
29+
30+
public bool TryGetMetrics(out LinuxConsumptionMetrics metrics)
31+
{
32+
return MetricsQueue.TryDequeue(out metrics);
33+
}
34+
35+
public void LogEvent(string eventName)
36+
{
37+
OnDiagnosticEvent?.Invoke(this, new DiagnosticEventArgs(eventName));
38+
}
39+
}
40+
}

test/WebJobs.Script.Tests.Shared/WebJobs.Script.Tests.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<Compile Include="$(MSBuildThisFileDirectory)TestFunctionMetadataManager.cs" />
2525
<Compile Include="$(MSBuildThisFileDirectory)TestHostBuilderExtensions.cs" />
2626
<Compile Include="$(MSBuildThisFileDirectory)TestHostExtensions.cs" />
27+
<Compile Include="$(MSBuildThisFileDirectory)TestMetricsTracker.cs" />
2728
<Compile Include="$(MSBuildThisFileDirectory)TestOutputHelperLogger.cs" />
2829
<Compile Include="$(MSBuildThisFileDirectory)TestOutputHelperLoggerProvider.cs" />
2930
<Compile Include="$(MSBuildThisFileDirectory)TestMetricsLogger.cs" />

test/WebJobs.Script.Tests/Metrics/LinuxContainerLegionMetricsPublisherTests.cs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class LinuxContainerLegionMetricsPublisherTests
3232
private readonly Random _random = new Random();
3333
private readonly TestLogger<LinuxContainerLegionMetricsPublisher> _logger;
3434
private readonly TestMetricsLogger _testMetricsLogger;
35-
private readonly IScriptHostManager _scriptHostManager;
35+
private readonly IServiceProvider _serviceProvider;
3636

3737
private IOptions<LinuxConsumptionLegionMetricsPublisherOptions> _options;
3838
private StandbyOptions _standbyOptions;
@@ -44,7 +44,7 @@ public LinuxContainerLegionMetricsPublisherTests()
4444
_environment = new TestEnvironment();
4545
_logger = new TestLogger<LinuxContainerLegionMetricsPublisher>();
4646
_testMetricsLogger = new TestMetricsLogger();
47-
_scriptHostManager = new TestScriptHostManager(_testMetricsLogger);
47+
_serviceProvider = new TestScriptHostManager(_testMetricsLogger);
4848

4949
_environment.SetEnvironmentVariable(EnvironmentSettingNames.FunctionsMetricsPublishPath, _metricsFilePath);
5050

@@ -62,7 +62,7 @@ private LinuxContainerLegionMetricsPublisher CreatePublisher(int? metricsPublish
6262
MetricsFilePath = _metricsFilePath
6363
});
6464

65-
return new LinuxContainerLegionMetricsPublisher(_environment, _standbyOptionsMonitor, _options, _logger, new FileSystem(), _testMetricsTracker, _scriptHostManager, metricsPublishInterval);
65+
return new LinuxContainerLegionMetricsPublisher(_environment, _standbyOptionsMonitor, _options, _logger, new FileSystem(), _testMetricsTracker, _serviceProvider, metricsPublishInterval);
6666
}
6767

6868
[Fact]
@@ -237,37 +237,6 @@ private static FileInfo[] GetMetricsFilesSafe(string path)
237237
return new FileInfo[0];
238238
}
239239

240-
private class TestMetricsTracker : ILinuxConsumptionMetricsTracker
241-
{
242-
public event EventHandler<DiagnosticEventArgs> OnDiagnosticEvent;
243-
244-
public List<FunctionActivity> FunctionActivities { get; } = new List<FunctionActivity>();
245-
246-
public List<MemoryActivity> MemoryActivities { get; } = new List<MemoryActivity>();
247-
248-
public Queue<LinuxConsumptionMetrics> MetricsQueue { get; } = new Queue<LinuxConsumptionMetrics>();
249-
250-
public void AddFunctionActivity(FunctionActivity activity)
251-
{
252-
FunctionActivities.Add(activity);
253-
}
254-
255-
public void AddMemoryActivity(MemoryActivity activity)
256-
{
257-
MemoryActivities.Add(activity);
258-
}
259-
260-
public bool TryGetMetrics(out LinuxConsumptionMetrics metrics)
261-
{
262-
return MetricsQueue.TryDequeue(out metrics);
263-
}
264-
265-
public void LogEvent(string eventName)
266-
{
267-
OnDiagnosticEvent?.Invoke(this, new DiagnosticEventArgs(eventName));
268-
}
269-
}
270-
271240
private class TestScriptHostManager : IServiceProvider, IScriptHostManager
272241
{
273242
private readonly IMetricsLogger _metricsLogger;

0 commit comments

Comments
 (0)