From b7d22330425dd62068e3eb3ff046217358f0c05f Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Mon, 14 Apr 2025 16:59:02 -0700 Subject: [PATCH 01/14] compare loaded bundle version with latest major bundle version --- .../Diagnostics/DiagnosticEventConstants.cs | 3 +++ .../ExtensionBundle/ExtensionBundleManager.cs | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/WebJobs.Script/Diagnostics/DiagnosticEventConstants.cs b/src/WebJobs.Script/Diagnostics/DiagnosticEventConstants.cs index 2669a22a6b..777b0a2bb7 100644 --- a/src/WebJobs.Script/Diagnostics/DiagnosticEventConstants.cs +++ b/src/WebJobs.Script/Diagnostics/DiagnosticEventConstants.cs @@ -34,5 +34,8 @@ internal static class DiagnosticEventConstants public const string WorkerRuntimeDoesNotMatchWithFunctionMetadataErrorCode = "AZFD0013"; public const string WorkerRuntimeDoesNotMatchWithFunctionMetadataHelpLink = "https://aka.ms/functions-invalid-worker-runtime"; + + public const string OutdatedBundlesVersionErrorCode = "AZFD0014"; + public const string OutdatedBundlesVersionHelpLink = "https://aka.ms/functions-outdated-bundles"; } } diff --git a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs index 3c3c1dd597..1080de4fb8 100644 --- a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs +++ b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.Azure.WebJobs.Script.Config; using Microsoft.Azure.WebJobs.Script.Configuration; +using Microsoft.Azure.WebJobs.Script.Diagnostics; using Microsoft.Azure.WebJobs.Script.Diagnostics.Extensions; using Microsoft.Azure.WebJobs.Script.Models; using Microsoft.Extensions.Logging; @@ -20,6 +21,7 @@ namespace Microsoft.Azure.WebJobs.Script.ExtensionBundle { public class ExtensionBundleManager : IExtensionBundleManager { + private const int _latestMajorBundleVersion = 4; private readonly IEnvironment _environment; private readonly ExtensionBundleOptions _options; private readonly FunctionsHostingConfigOptions _configOption; @@ -48,6 +50,7 @@ public async Task GetExtensionBundleDetails() } _extensionBundleVersion = _extensionBundleVersion ?? await GetLatestMatchingBundleVersionAsync(); + CompareWithLatestMajorVersion(); return new ExtensionBundleDetails() { @@ -59,6 +62,18 @@ public async Task GetExtensionBundleDetails() return null; } + private void CompareWithLatestMajorVersion() + { + string majorVersionStr = _extensionBundleVersion?.Split('.')?.FirstOrDefault() ?? string.Empty; + int majorVersion = int.TryParse(majorVersionStr, out int result) ? result : 0; + + if (majorVersion != 0 && majorVersion < _latestMajorBundleVersion) + { + string message = $"Extension bundle version {majorVersion} is outdated. The latest version range is \"[{_latestMajorBundleVersion}.*, {_latestMajorBundleVersion + 1}.0.0)\""; + DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink); + } + } + public bool IsExtensionBundleConfigured() { return !string.IsNullOrEmpty(_options.Id) && !string.IsNullOrEmpty(_options.Version?.OriginalString); From 8f062bdc7e0b6eb5d636de0d9d6b608aa5283164 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Mon, 14 Apr 2025 17:00:57 -0700 Subject: [PATCH 02/14] update message --- src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs index 1080de4fb8..77a699071f 100644 --- a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs +++ b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs @@ -69,7 +69,7 @@ private void CompareWithLatestMajorVersion() if (majorVersion != 0 && majorVersion < _latestMajorBundleVersion) { - string message = $"Extension bundle version {majorVersion} is outdated. The latest version range is \"[{_latestMajorBundleVersion}.*, {_latestMajorBundleVersion + 1}.0.0)\""; + string message = $"Extension bundle version {majorVersion} is outdated. It is strongly recommended to update the app to use the latest version range: \"[{_latestMajorBundleVersion}.*, {_latestMajorBundleVersion + 1}.0.0)\""; DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink); } } From 176ea93eb2c6192ef3c29014ae62e6277e94df29 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Mon, 14 Apr 2025 17:25:17 -0700 Subject: [PATCH 03/14] use resx --- .../ExtensionBundle/ExtensionBundleManager.cs | 3 ++- src/WebJobs.Script/Properties/Resources.Designer.cs | 9 +++++++++ src/WebJobs.Script/Properties/Resources.resx | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs index 77a699071f..b7bb5f250f 100644 --- a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs +++ b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs @@ -13,6 +13,7 @@ using Microsoft.Azure.WebJobs.Script.Diagnostics; using Microsoft.Azure.WebJobs.Script.Diagnostics.Extensions; using Microsoft.Azure.WebJobs.Script.Models; +using Microsoft.Azure.WebJobs.Script.Properties; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using NuGet.Versioning; @@ -69,7 +70,7 @@ private void CompareWithLatestMajorVersion() if (majorVersion != 0 && majorVersion < _latestMajorBundleVersion) { - string message = $"Extension bundle version {majorVersion} is outdated. It is strongly recommended to update the app to use the latest version range: \"[{_latestMajorBundleVersion}.*, {_latestMajorBundleVersion + 1}.0.0)\""; + string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, majorVersion, _latestMajorBundleVersion, _latestMajorBundleVersion + 1); DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink); } } diff --git a/src/WebJobs.Script/Properties/Resources.Designer.cs b/src/WebJobs.Script/Properties/Resources.Designer.cs index 83b6069f1b..5666a5ec1f 100644 --- a/src/WebJobs.Script/Properties/Resources.Designer.cs +++ b/src/WebJobs.Script/Properties/Resources.Designer.cs @@ -209,6 +209,15 @@ internal static string MatchingBundleNotFound { } } + /// + /// Looks up a localized string similar to Extension bundle version {0} is outdated. It is strongly recommended to update the app to use the latest version range: \"[{1}.*, {2}.0.0)\". + /// + internal static string OutdatedExtensionBundlesVersionInfoFormat { + get { + return ResourceManager.GetString("OutdatedExtensionBundlesVersionInfoFormat", resourceCulture); + } + } + /// /// Looks up a localized string similar to SAS token within '{0}' setting has expired. Please generate a new SAS token or switch to using identites instead. For more information, see https://go.microsoft.com/fwlink/?linkid=2244092.. /// diff --git a/src/WebJobs.Script/Properties/Resources.resx b/src/WebJobs.Script/Properties/Resources.resx index 84231352bf..c11815ae1a 100644 --- a/src/WebJobs.Script/Properties/Resources.resx +++ b/src/WebJobs.Script/Properties/Resources.resx @@ -179,4 +179,7 @@ The environment variables 'WEBSITE_TIME_ZONE' and 'TZ' are not supported on this platform. For more information, see https://go.microsoft.com/fwlink/?linkid=2250165. + + Extension bundle version {0} is outdated. It is strongly recommended to update the app to use the latest version range: \"[{1}.*, {2}.0.0)\" + \ No newline at end of file From 5d7b50c4727fe871a0c4231839f3e6682943360b Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Tue, 15 Apr 2025 15:52:55 -0700 Subject: [PATCH 04/14] update message --- src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs | 2 +- src/WebJobs.Script/Properties/Resources.Designer.cs | 2 +- src/WebJobs.Script/Properties/Resources.resx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs index b7bb5f250f..626b528ff9 100644 --- a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs +++ b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs @@ -70,7 +70,7 @@ private void CompareWithLatestMajorVersion() if (majorVersion != 0 && majorVersion < _latestMajorBundleVersion) { - string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, majorVersion, _latestMajorBundleVersion, _latestMajorBundleVersion + 1); + string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, _extensionBundleVersion, _latestMajorBundleVersion, _latestMajorBundleVersion + 1); DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink); } } diff --git a/src/WebJobs.Script/Properties/Resources.Designer.cs b/src/WebJobs.Script/Properties/Resources.Designer.cs index 5666a5ec1f..b59adcd6ed 100644 --- a/src/WebJobs.Script/Properties/Resources.Designer.cs +++ b/src/WebJobs.Script/Properties/Resources.Designer.cs @@ -210,7 +210,7 @@ internal static string MatchingBundleNotFound { } /// - /// Looks up a localized string similar to Extension bundle version {0} is outdated. It is strongly recommended to update the app to use the latest version range: \"[{1}.*, {2}.0.0)\". + /// Looks up a localized string similar to Extension bundle version {0} is outdated. It is strongly recommended to update the app to use the latest version range: [{1}.*, {2}.0.0). /// internal static string OutdatedExtensionBundlesVersionInfoFormat { get { diff --git a/src/WebJobs.Script/Properties/Resources.resx b/src/WebJobs.Script/Properties/Resources.resx index c11815ae1a..de9542af71 100644 --- a/src/WebJobs.Script/Properties/Resources.resx +++ b/src/WebJobs.Script/Properties/Resources.resx @@ -180,6 +180,6 @@ The environment variables 'WEBSITE_TIME_ZONE' and 'TZ' are not supported on this platform. For more information, see https://go.microsoft.com/fwlink/?linkid=2250165. - Extension bundle version {0} is outdated. It is strongly recommended to update the app to use the latest version range: \"[{1}.*, {2}.0.0)\" + Extension bundle version {0} is outdated. It is strongly recommended to update the app to use the latest version range: [{1}.*, {2}.0.0) \ No newline at end of file From 54851c08a3e6b60054447c7dbc230241ddba648b Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Thu, 17 Apr 2025 14:18:22 -0700 Subject: [PATCH 05/14] update bitness for x86 --- src/WebJobs.Script.SiteExtension/New-PrivateSiteExtension.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebJobs.Script.SiteExtension/New-PrivateSiteExtension.ps1 b/src/WebJobs.Script.SiteExtension/New-PrivateSiteExtension.ps1 index 0ef23c159c..c367526e1b 100644 --- a/src/WebJobs.Script.SiteExtension/New-PrivateSiteExtension.ps1 +++ b/src/WebJobs.Script.SiteExtension/New-PrivateSiteExtension.ps1 @@ -38,7 +38,7 @@ param ( $normalizeBitness = @{ 'x64' = '64bit' '64bit' = '64bit' - 'x86' = '64bit' + 'x86' = '32bit' '32bit' = '32bit' } From e23bf254562b05323cd41aab122e5f4ceb34e748 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Thu, 17 Apr 2025 14:34:32 -0700 Subject: [PATCH 06/14] update the message --- src/WebJobs.Script/Properties/Resources.Designer.cs | 2 +- src/WebJobs.Script/Properties/Resources.resx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WebJobs.Script/Properties/Resources.Designer.cs b/src/WebJobs.Script/Properties/Resources.Designer.cs index b59adcd6ed..78857472b9 100644 --- a/src/WebJobs.Script/Properties/Resources.Designer.cs +++ b/src/WebJobs.Script/Properties/Resources.Designer.cs @@ -210,7 +210,7 @@ internal static string MatchingBundleNotFound { } /// - /// Looks up a localized string similar to Extension bundle version {0} is outdated. It is strongly recommended to update the app to use the latest version range: [{1}.*, {2}.0.0). + /// Looks up a localized string similar to You are currently using an outdated version - {0} of the extension bundle. To ensure optimal performance and access to the latest features, please update to the latest version range: [{1}.*, {2}.0.0). /// internal static string OutdatedExtensionBundlesVersionInfoFormat { get { diff --git a/src/WebJobs.Script/Properties/Resources.resx b/src/WebJobs.Script/Properties/Resources.resx index de9542af71..7fbf1a86fe 100644 --- a/src/WebJobs.Script/Properties/Resources.resx +++ b/src/WebJobs.Script/Properties/Resources.resx @@ -180,6 +180,6 @@ The environment variables 'WEBSITE_TIME_ZONE' and 'TZ' are not supported on this platform. For more information, see https://go.microsoft.com/fwlink/?linkid=2250165. - Extension bundle version {0} is outdated. It is strongly recommended to update the app to use the latest version range: [{1}.*, {2}.0.0) + You are currently using an outdated version - {0} of the extension bundle. To ensure optimal performance and access to the latest features, please update to the latest version range: [{1}.*, {2}.0.0) \ No newline at end of file From 313a2be331bff22a9e84f9893f577c277e2192d5 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Thu, 17 Apr 2025 14:51:33 -0700 Subject: [PATCH 07/14] move to scriptstartup --- .../ScriptStartupTypeLocator.cs | 23 +++++++++++++++++-- .../ExtensionBundle/ExtensionBundleManager.cs | 17 -------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs b/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs index 547456639a..6280bdb94c 100644 --- a/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs +++ b/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs @@ -16,6 +16,7 @@ using Microsoft.Azure.WebJobs.Script.ExtensionBundle; using Microsoft.Azure.WebJobs.Script.ExtensionRequirements; using Microsoft.Azure.WebJobs.Script.Models; +using Microsoft.Azure.WebJobs.Script.Properties; using Microsoft.Azure.WebJobs.Script.Workers.Rpc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -31,7 +32,8 @@ namespace Microsoft.Azure.WebJobs.Script.DependencyInjection public class ScriptStartupTypeLocator : IWebJobsStartupTypeLocator { private const string ApplicationInsightsStartupType = "Microsoft.Azure.WebJobs.Extensions.ApplicationInsights.ApplicationInsightsWebJobsStartup, Microsoft.Azure.WebJobs.Extensions.ApplicationInsights, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9475d07f10cb09df"; - + private const int LatestMajorBundleVersion = 4; + private const string DefaultBundleVersionId = "Microsoft.Azure.Functions.ExtensionBundle"; private readonly string _rootScriptPath; private readonly ILogger _logger; private readonly IExtensionBundleManager _extensionBundleManager; @@ -84,9 +86,10 @@ public async Task> GetExtensionsStartupTypesAsync() // dotnet app precompiled -> Do not use bundles ExtensionRequirementsInfo extensionRequirements = GetExtensionRequirementsInfo(); ImmutableArray functionMetadataCollection = ImmutableArray.Empty; + ExtensionBundleDetails bundleDetails = null; if (bundleConfigured) { - ExtensionBundleDetails bundleDetails = await _extensionBundleManager.GetExtensionBundleDetails(); + bundleDetails = await _extensionBundleManager.GetExtensionBundleDetails(); ValidateBundleRequirements(bundleDetails, extensionRequirements); functionMetadataCollection = _functionMetadataManager.GetFunctionMetadata(forceRefresh: true, includeCustomProviders: false); @@ -126,6 +129,8 @@ public async Task> GetExtensionsStartupTypesAsync() } _logger.ScriptStartUpLoadingExtensionBundle(extensionsMetadataPath); + + CompareWithLatestMajorVersion(bundleDetails); } else { @@ -222,6 +227,20 @@ public async Task> GetExtensionsStartupTypesAsync() return startupTypes; } + private void CompareWithLatestMajorVersion(ExtensionBundleDetails bundle) + { + string majorVersionStr = bundle?.Version?.Split('.')?.FirstOrDefault() ?? string.Empty; + int majorVersion = int.TryParse(majorVersionStr, out int result) ? result : 0; + + if (string.Compare(bundle?.Id, DefaultBundleVersionId, StringComparison.OrdinalIgnoreCase) == 0 + && majorVersion != 0 + && majorVersion < LatestMajorBundleVersion) + { + string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, bundle.Version, LatestMajorBundleVersion, LatestMajorBundleVersion + 1); + DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink); + } + } + private ExtensionReference[] ParseExtensions(string metadataFilePath) { using (_metricsLogger.LatencyEvent(MetricEventNames.ParseExtensions)) diff --git a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs index 626b528ff9..2c5325bc5e 100644 --- a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs +++ b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs @@ -10,10 +10,8 @@ using System.Threading.Tasks; using Microsoft.Azure.WebJobs.Script.Config; using Microsoft.Azure.WebJobs.Script.Configuration; -using Microsoft.Azure.WebJobs.Script.Diagnostics; using Microsoft.Azure.WebJobs.Script.Diagnostics.Extensions; using Microsoft.Azure.WebJobs.Script.Models; -using Microsoft.Azure.WebJobs.Script.Properties; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using NuGet.Versioning; @@ -22,7 +20,6 @@ namespace Microsoft.Azure.WebJobs.Script.ExtensionBundle { public class ExtensionBundleManager : IExtensionBundleManager { - private const int _latestMajorBundleVersion = 4; private readonly IEnvironment _environment; private readonly ExtensionBundleOptions _options; private readonly FunctionsHostingConfigOptions _configOption; @@ -51,8 +48,6 @@ public async Task GetExtensionBundleDetails() } _extensionBundleVersion = _extensionBundleVersion ?? await GetLatestMatchingBundleVersionAsync(); - CompareWithLatestMajorVersion(); - return new ExtensionBundleDetails() { Id = _options.Id, @@ -63,18 +58,6 @@ public async Task GetExtensionBundleDetails() return null; } - private void CompareWithLatestMajorVersion() - { - string majorVersionStr = _extensionBundleVersion?.Split('.')?.FirstOrDefault() ?? string.Empty; - int majorVersion = int.TryParse(majorVersionStr, out int result) ? result : 0; - - if (majorVersion != 0 && majorVersion < _latestMajorBundleVersion) - { - string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, _extensionBundleVersion, _latestMajorBundleVersion, _latestMajorBundleVersion + 1); - DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink); - } - } - public bool IsExtensionBundleConfigured() { return !string.IsNullOrEmpty(_options.Id) && !string.IsNullOrEmpty(_options.Version?.OriginalString); From b6fd8d1b28ef584f1bbd0b6ecb6802db3b015f4a Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Thu, 17 Apr 2025 15:50:40 -0700 Subject: [PATCH 08/14] add test cases --- release_notes.md | 24 ++++---- .../ScriptStartupTypeDiscovererTests.cs | 61 +++++++++++++++++++ 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/release_notes.md b/release_notes.md index a8dcc49873..1281d2c94a 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,11 +1,13 @@ -### Release notes - - -- Improved memory metrics reporting using CGroup data for Linux consumption (#10968) -- Memory allocation optimizations in `RpcWorkerConfigFactory.AddProviders` (#10959) -- Fixing GrpcWorkerChannel concurrency bug (#10998) -- Avoid circular dependency when resolving LinuxContainerLegionMetricsPublisher. (#10991) -- Add 'unix' to the list of runtimes kept when importing PowerShell worker for Linux builds -- Update PowerShell 7.4 worker to 4.0.4206 +### Release notes + + +- Improved memory metrics reporting using CGroup data for Linux consumption (#10968) +- Memory allocation optimizations in `RpcWorkerConfigFactory.AddProviders` (#10959) + +- Fixing GrpcWorkerChannel concurrency bug (#10998) +- Avoid circular dependency when resolving LinuxContainerLegionMetricsPublisher. (#10991) +- Add 'unix' to the list of runtimes kept when importing PowerShell worker for Linux builds +- Update PowerShell 7.4 worker to 4.0.4206 +- Add information diagnostics event for outdated bundle version, any bundle version < 4. diff --git a/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs b/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs index d99bb6c65e..67e5cc1c74 100644 --- a/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs +++ b/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs @@ -17,6 +17,7 @@ using Microsoft.Azure.WebJobs.Script.ExtensionBundle; using Microsoft.Azure.WebJobs.Script.ExtensionRequirements; using Microsoft.Azure.WebJobs.Script.Models; +using Microsoft.Azure.WebJobs.Script.Properties; using Microsoft.Azure.WebJobs.Script.Workers.Rpc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -30,6 +31,8 @@ namespace Microsoft.Azure.WebJobs.Script.Tests { public class ScriptStartupTypeDiscovererTests { + private const int LatestMajorBundleVersion = 4; + [Fact] public async Task GetExtensionsStartupTypes_UsesDefaultMinVersion() { @@ -1095,6 +1098,64 @@ void CopyToBin(string path) } } + [Theory] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle", "3.36.0", true)] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle", "2.25.0", true)] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle", "4.22.0", false)] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle.Preview", "4.29.0", false)] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle.Preview", "3.2.0", false)] + public async Task CompareWithLatestMajorVersion_LogsExpectedDiagnosticEvents(string bundleId, string bundleVersion, bool shouldLogEvent) + { + using (var directory = GetTempDirectory()) + { + // Setup + TestMetricsLogger testMetricsLogger = new TestMetricsLogger(); + TestLoggerProvider testLoggerProvider = new TestLoggerProvider(); + LoggerFactory factory = new LoggerFactory(); + factory.AddProvider(testLoggerProvider); + var testLogger = factory.CreateLogger(); + + var binPath = Path.Combine(directory.Path, "bin"); + + var mockExtensionBundleManager = new Mock(); + mockExtensionBundleManager.Setup(e => e.IsExtensionBundleConfigured()).Returns(true); + mockExtensionBundleManager.Setup(e => e.GetExtensionBundleBinPathAsync()).Returns(Task.FromResult(binPath)); + mockExtensionBundleManager.Setup(e => e.IsLegacyExtensionBundle()).Returns(false); + mockExtensionBundleManager.Setup(e => e.GetExtensionBundleDetails()).Returns(Task.FromResult(new ExtensionBundleDetails + { + Id = bundleId, + Version = bundleVersion + })); + + var languageWorkerOptions = new TestOptionsMonitor(new LanguageWorkerOptions()); + var mockFunctionMetadataManager = GetTestFunctionMetadataManager(languageWorkerOptions); + OptionsWrapper optionsWrapper = new(new ExtensionRequirementOptions()); + var discoverer = new ScriptStartupTypeLocator(directory.Path, testLogger, mockExtensionBundleManager.Object, mockFunctionMetadataManager, testMetricsLogger, optionsWrapper); + + // Act - we just need to ensure CompareWithLatestMajorVersion is called + try + { + await discoverer.GetExtensionsStartupTypesAsync(); + } + catch (HostInitializationException) + { + // We might get this exception for certain bundle versions, but it's not relevant to this test + } + + // Assert + var traces = testLoggerProvider.GetAllLogMessages(); + string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, bundleVersion, LatestMajorBundleVersion, LatestMajorBundleVersion + 1); + + // Check for logs matching the pattern for outdated bundle version + bool hasOutdatedBundleLog = traces.Any(m => + m.Level == LogLevel.Information && + m.FormattedMessage.Contains(message) && + m.FormattedMessage.Contains(bundleVersion)); + + Assert.Equal(shouldLogEvent, hasOutdatedBundleLog); + } + } + private IFunctionMetadataManager GetTestFunctionMetadataManager(IOptionsMonitor options, ICollection metadataCollection = null, bool hasPrecompiledFunction = false, bool hasNodeFunctions = false, bool hasDotnetIsolatedFunctions = false) { var functionMetadata = new FunctionMetadata(); From 0efd9ff480b6b3dafc43487cac378a6b8f490d76 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:01:50 -0700 Subject: [PATCH 09/14] remove new line --- release_notes.md | 1 - 1 file changed, 1 deletion(-) diff --git a/release_notes.md b/release_notes.md index 1281d2c94a..8d7026b000 100644 --- a/release_notes.md +++ b/release_notes.md @@ -5,7 +5,6 @@ --> - Improved memory metrics reporting using CGroup data for Linux consumption (#10968) - Memory allocation optimizations in `RpcWorkerConfigFactory.AddProviders` (#10959) - - Fixing GrpcWorkerChannel concurrency bug (#10998) - Avoid circular dependency when resolving LinuxContainerLegionMetricsPublisher. (#10991) - Add 'unix' to the list of runtimes kept when importing PowerShell worker for Linux builds From b2f7834fff6eae302c810016e034dd0ca906b419 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:30:49 -0700 Subject: [PATCH 10/14] handle null check --- test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs b/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs index 67e5cc1c74..a51421f5c8 100644 --- a/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs +++ b/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs @@ -783,7 +783,7 @@ public async Task GetExtensionsStartupTypes_WorkerRuntimeNotSetForNodeApp_LoadsE //Assert var traces = testLoggerProvider.GetAllLogMessages(); - var traceMessage = traces.FirstOrDefault(val => val.EventId.Name.Equals("ScriptStartNotLoadingExtensionBundle")); + var traceMessage = traces.FirstOrDefault(val => string.Equals(val.EventId.Name, "ScriptStartNotLoadingExtensionBundle")); bool loadingExtensionBundle = traceMessage == null; Assert.True(loadingExtensionBundle); From ed8306dc855ca9c47172d66cf617d7e2e8e81cb3 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Wed, 14 May 2025 13:41:00 -0700 Subject: [PATCH 11/14] move the logic to extension bundle manager --- .../ScriptStartupTypeLocator.cs | 19 +------------------ .../ExtensionBundle/ExtensionBundleManager.cs | 17 +++++++++++++++++ .../IExtensionBundleManager.cs | 2 ++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs b/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs index 6280bdb94c..e1785e5d95 100644 --- a/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs +++ b/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs @@ -16,7 +16,6 @@ using Microsoft.Azure.WebJobs.Script.ExtensionBundle; using Microsoft.Azure.WebJobs.Script.ExtensionRequirements; using Microsoft.Azure.WebJobs.Script.Models; -using Microsoft.Azure.WebJobs.Script.Properties; using Microsoft.Azure.WebJobs.Script.Workers.Rpc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -32,8 +31,6 @@ namespace Microsoft.Azure.WebJobs.Script.DependencyInjection public class ScriptStartupTypeLocator : IWebJobsStartupTypeLocator { private const string ApplicationInsightsStartupType = "Microsoft.Azure.WebJobs.Extensions.ApplicationInsights.ApplicationInsightsWebJobsStartup, Microsoft.Azure.WebJobs.Extensions.ApplicationInsights, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9475d07f10cb09df"; - private const int LatestMajorBundleVersion = 4; - private const string DefaultBundleVersionId = "Microsoft.Azure.Functions.ExtensionBundle"; private readonly string _rootScriptPath; private readonly ILogger _logger; private readonly IExtensionBundleManager _extensionBundleManager; @@ -130,7 +127,7 @@ public async Task> GetExtensionsStartupTypesAsync() _logger.ScriptStartUpLoadingExtensionBundle(extensionsMetadataPath); - CompareWithLatestMajorVersion(bundleDetails); + _extensionBundleManager.CompareWithLatestMajorVersion(); } else { @@ -227,20 +224,6 @@ public async Task> GetExtensionsStartupTypesAsync() return startupTypes; } - private void CompareWithLatestMajorVersion(ExtensionBundleDetails bundle) - { - string majorVersionStr = bundle?.Version?.Split('.')?.FirstOrDefault() ?? string.Empty; - int majorVersion = int.TryParse(majorVersionStr, out int result) ? result : 0; - - if (string.Compare(bundle?.Id, DefaultBundleVersionId, StringComparison.OrdinalIgnoreCase) == 0 - && majorVersion != 0 - && majorVersion < LatestMajorBundleVersion) - { - string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, bundle.Version, LatestMajorBundleVersion, LatestMajorBundleVersion + 1); - DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink); - } - } - private ExtensionReference[] ParseExtensions(string metadataFilePath) { using (_metricsLogger.LatencyEvent(MetricEventNames.ParseExtensions)) diff --git a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs index 2c5325bc5e..9277143439 100644 --- a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs +++ b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs @@ -10,8 +10,10 @@ using System.Threading.Tasks; using Microsoft.Azure.WebJobs.Script.Config; using Microsoft.Azure.WebJobs.Script.Configuration; +using Microsoft.Azure.WebJobs.Script.Diagnostics; using Microsoft.Azure.WebJobs.Script.Diagnostics.Extensions; using Microsoft.Azure.WebJobs.Script.Models; +using Microsoft.Azure.WebJobs.Script.Properties; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using NuGet.Versioning; @@ -374,5 +376,20 @@ public async Task GetExtensionBundleBinPathAsync() // if no bin directory is present something is wrong return FileUtility.DirectoryExists(binPath) ? binPath : null; } + + public void CompareWithLatestMajorVersion() + { + string majorVersionStr = _extensionBundleVersion?.Split('.')?.FirstOrDefault() ?? string.Empty; + int majorVersion = int.TryParse(majorVersionStr, out int result) ? result : 0; + + int latestMajorVersion = ScriptConstants.ExtensionBundleV4MajorVersion; + if (string.Compare(_options?.Id, ScriptConstants.DefaultExtensionBundleId, StringComparison.OrdinalIgnoreCase) == 0 + && majorVersion != 0 + && majorVersion < latestMajorVersion) + { + string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, _extensionBundleVersion, latestMajorVersion, latestMajorVersion + 1); + DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink); + } + } } } \ No newline at end of file diff --git a/src/WebJobs.Script/ExtensionBundle/IExtensionBundleManager.cs b/src/WebJobs.Script/ExtensionBundle/IExtensionBundleManager.cs index 9a63b25a07..7ae30590cf 100644 --- a/src/WebJobs.Script/ExtensionBundle/IExtensionBundleManager.cs +++ b/src/WebJobs.Script/ExtensionBundle/IExtensionBundleManager.cs @@ -20,5 +20,7 @@ public interface IExtensionBundleManager bool IsLegacyExtensionBundle(); Task GetExtensionBundleDetails(); + + void CompareWithLatestMajorVersion(); } } \ No newline at end of file From 04226bd06f685197852cd1b8fbf35883fc7775ea Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Wed, 14 May 2025 14:51:56 -0700 Subject: [PATCH 12/14] change to warning --- src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs | 2 +- src/WebJobs.Script/Properties/Resources.resx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs index 9277143439..4806f149cc 100644 --- a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs +++ b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs @@ -388,7 +388,7 @@ public void CompareWithLatestMajorVersion() && majorVersion < latestMajorVersion) { string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, _extensionBundleVersion, latestMajorVersion, latestMajorVersion + 1); - DiagnosticEventLoggerExtensions.LogDiagnosticEventInformation(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink); + DiagnosticEventLoggerExtensions.LogDiagnosticEventWarning(_logger, DiagnosticEventConstants.OutdatedBundlesVersionErrorCode, message, DiagnosticEventConstants.OutdatedBundlesVersionHelpLink, null); } } } diff --git a/src/WebJobs.Script/Properties/Resources.resx b/src/WebJobs.Script/Properties/Resources.resx index 7fbf1a86fe..b39a1fc622 100644 --- a/src/WebJobs.Script/Properties/Resources.resx +++ b/src/WebJobs.Script/Properties/Resources.resx @@ -180,6 +180,6 @@ The environment variables 'WEBSITE_TIME_ZONE' and 'TZ' are not supported on this platform. For more information, see https://go.microsoft.com/fwlink/?linkid=2250165. - You are currently using an outdated version - {0} of the extension bundle. To ensure optimal performance and access to the latest features, please update to the latest version range: [{1}.*, {2}.0.0) + You are currently using an outdated version — {0} — of the extension bundle, which is deprecated as of 2026-05-30. To ensure optimal performance and access to the latest features, please update to a supported version in the range: [{1}.*, {2}.0.0). \ No newline at end of file From 6224309e09eaea3f70a083504393b16213d30227 Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Thu, 22 May 2025 15:25:09 -0700 Subject: [PATCH 13/14] move to function app validation service --- .../ScriptStartupTypeLocator.cs | 5 +- .../Host/FunctionAppValidationService.cs | 6 ++ .../FunctionAppValidationServiceTests.cs | 50 ++++++++++++++-- .../ExtensionBundleContentProviderTests.cs | 4 ++ .../ExtensionManagerTests.cs | 5 ++ .../ScriptStartupTypeDiscovererTests.cs | 60 ------------------- 6 files changed, 62 insertions(+), 68 deletions(-) diff --git a/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs b/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs index f556ac382b..a0b5bb1112 100644 --- a/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs +++ b/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs @@ -82,10 +82,9 @@ public async Task> GetExtensionsStartupTypesAsync() // dotnet app precompiled -> Do not use bundles ExtensionRequirementsInfo extensionRequirements = GetExtensionRequirementsInfo(); ImmutableArray functionMetadataCollection = ImmutableArray.Empty; - ExtensionBundleDetails bundleDetails = null; if (bundleConfigured) { - bundleDetails = await _extensionBundleManager.GetExtensionBundleDetails(); + ExtensionBundleDetails bundleDetails = await _extensionBundleManager.GetExtensionBundleDetails(); ValidateBundleRequirements(bundleDetails, extensionRequirements); functionMetadataCollection = _functionMetadataManager.GetFunctionMetadata(forceRefresh: true, includeCustomProviders: false); @@ -125,8 +124,6 @@ public async Task> GetExtensionsStartupTypesAsync() } _logger.ScriptStartUpLoadingExtensionBundle(extensionsMetadataPath); - - _extensionBundleManager.CompareWithLatestMajorVersion(); } else { diff --git a/src/WebJobs.Script/Host/FunctionAppValidationService.cs b/src/WebJobs.Script/Host/FunctionAppValidationService.cs index 582da52dac..9cdc300fed 100644 --- a/src/WebJobs.Script/Host/FunctionAppValidationService.cs +++ b/src/WebJobs.Script/Host/FunctionAppValidationService.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.WebJobs.Script.Diagnostics.Extensions; +using Microsoft.Azure.WebJobs.Script.ExtensionBundle; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -22,15 +23,18 @@ internal sealed class FunctionAppValidationService : BackgroundService private readonly IEnvironment _environment; private readonly ILogger _logger; private readonly IOptions _scriptOptions; + private readonly IExtensionBundleManager _extensionBundleManager; public FunctionAppValidationService( ILogger logger, IOptions scriptOptions, + IExtensionBundleManager extensionBundleManager, IEnvironment environment) { _scriptOptions = scriptOptions ?? throw new ArgumentNullException(nameof(scriptOptions)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _environment = environment ?? throw new ArgumentNullException(nameof(environment)); + _extensionBundleManager = extensionBundleManager ?? throw new ArgumentNullException(nameof(extensionBundleManager)); } protected override async Task ExecuteAsync(CancellationToken cancellationToken) @@ -41,6 +45,8 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken) Utility.ExecuteAfterColdStartDelay(_environment, Validate, cancellationToken); } + // Validate the extension bundle and throw warning for outdated bundles + _extensionBundleManager.CompareWithLatestMajorVersion(); await Task.CompletedTask; } diff --git a/test/WebJobs.Script.Tests/Description/FunctionAppValidationServiceTests.cs b/test/WebJobs.Script.Tests/Description/FunctionAppValidationServiceTests.cs index cd1848e234..4840554656 100644 --- a/test/WebJobs.Script.Tests/Description/FunctionAppValidationServiceTests.cs +++ b/test/WebJobs.Script.Tests/Description/FunctionAppValidationServiceTests.cs @@ -1,13 +1,15 @@ // 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.Immutable; using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Azure.WebJobs.Script.Config; +using Microsoft.Azure.WebJobs.Script.Configuration; using Microsoft.Azure.WebJobs.Script.Description; +using Microsoft.Azure.WebJobs.Script.ExtensionBundle; using Microsoft.Azure.WebJobs.Script.Host; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -21,8 +23,10 @@ public class FunctionAppValidationServiceTests { private readonly ILogger _testLogger; private readonly Mock> _scriptOptionsMock; + private readonly IExtensionBundleManager _extensionBundleManager; private readonly ScriptJobHostOptions _scriptJobHostOptions; private readonly TestLoggerProvider _testLoggerProvider; + private readonly ILoggerFactory _loggerFactory; public FunctionAppValidationServiceTests() { @@ -36,9 +40,10 @@ public FunctionAppValidationServiceTests() _scriptOptionsMock.Setup(o => o.Value).Returns(_scriptJobHostOptions); _testLoggerProvider = new TestLoggerProvider(); - var factory = new LoggerFactory(); - factory.AddProvider(_testLoggerProvider); - _testLogger = factory.CreateLogger(); + _loggerFactory = new LoggerFactory(); + _loggerFactory.AddProvider(_testLoggerProvider); + _testLogger = _loggerFactory.CreateLogger(); + _extensionBundleManager = new Mock().Object; } [Fact] @@ -49,6 +54,7 @@ public async Task StartAsync_NotDotnetIsolatedApp_DoesNotLogError() var service = new FunctionAppValidationService( _testLogger, _scriptOptionsMock.Object, + _extensionBundleManager, new TestEnvironment()); // Act @@ -72,6 +78,7 @@ public async Task StartAsync_PlaceholderMode_DoesNotLogError() var service = new FunctionAppValidationService( _testLogger, _scriptOptionsMock.Object, + _extensionBundleManager, environment); // Act @@ -105,6 +112,7 @@ public async Task StartAsync_NewAppWithNoPayload_DoesNotLogError() var service = new FunctionAppValidationService( _testLogger, scriptOptionsMock.Object, + _extensionBundleManager, environment); // Act @@ -136,6 +144,7 @@ public async Task StartAsync_MissingAzureFunctionsFolder_LogsWarning() var service = new FunctionAppValidationService( _testLogger, _scriptOptionsMock.Object, + _extensionBundleManager, environment); // Act @@ -147,5 +156,38 @@ await TestHelpers.Await(() => return completed > 0; }); } + + [Theory] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle", "3.36.0", true)] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle", "2.25.0", true)] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle", "4.22.0", false)] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle.Preview", "4.29.0", false)] + [InlineData("Microsoft.Azure.Functions.ExtensionBundle.Preview", "3.2.0", false)] + public void CompareWithLatestMajorVersion_LogsExpectedDiagnosticEvents(string bundleId, string bundleVersion, bool shouldLogEvent) + { + // Arrange + _testLoggerProvider.ClearAllLogMessages(); + + var options = new ExtensionBundleOptions { Id = bundleId }; + var env = new TestEnvironment(); + var config = new FunctionsHostingConfigOptions(); + var manager = new ExtensionBundleManager(options, env, _loggerFactory, config); + + // Set the private _extensionBundleVersion field using reflection + typeof(ExtensionBundleManager) + .GetField("_extensionBundleVersion", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) + .SetValue(manager, bundleVersion); + + // Act + manager.CompareWithLatestMajorVersion(); + + // Assert + var logMessages = _testLoggerProvider.GetAllLogMessages(); + bool hasOutdatedBundleLog = logMessages.Any(m => m.FormattedMessage.Contains(bundleVersion) && + m.FormattedMessage.Contains("outdated version") && + m.FormattedMessage.Contains("of the extension bundle")); + + Assert.Equal(shouldLogEvent, hasOutdatedBundleLog); + } } } \ No newline at end of file diff --git a/test/WebJobs.Script.Tests/ExtensionBundle/ExtensionBundleContentProviderTests.cs b/test/WebJobs.Script.Tests/ExtensionBundle/ExtensionBundleContentProviderTests.cs index 2d11c01efd..bdc9ec2474 100644 --- a/test/WebJobs.Script.Tests/ExtensionBundle/ExtensionBundleContentProviderTests.cs +++ b/test/WebJobs.Script.Tests/ExtensionBundle/ExtensionBundleContentProviderTests.cs @@ -142,6 +142,10 @@ public TestExtensionBundleManager(string bundlePath = null, bool isExtensionBund _isExtensionBundleConfigured = isExtensionBundleConfigured; _isLegacyExtensionBundle = isLegacyExtensionBundle; } + public void CompareWithLatestMajorVersion() + { + // No-op for test stub. This can be extended for test verifications if needed. + } public Task GetExtensionBundleBinPathAsync() { diff --git a/test/WebJobs.Script.Tests/ExtensionManagerTests.cs b/test/WebJobs.Script.Tests/ExtensionManagerTests.cs index 891ca6ffdc..cdf287e240 100644 --- a/test/WebJobs.Script.Tests/ExtensionManagerTests.cs +++ b/test/WebJobs.Script.Tests/ExtensionManagerTests.cs @@ -193,6 +193,11 @@ public TestExtensionBundleManager(string bundlePath = null, bool isExtensionBund _isLegacyExtensionBundle = isLegacyExtensionBundle; } + public void CompareWithLatestMajorVersion() + { + // No-op for test stub. This can be extended for test verifications if needed. + } + public Task GetExtensionBundleBinPathAsync() { return Task.FromResult(Path.Combine(_bundlePath, "bin")); diff --git a/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs b/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs index 6344f77e1d..cfb76c5a2d 100644 --- a/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs +++ b/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs @@ -31,8 +31,6 @@ namespace Microsoft.Azure.WebJobs.Script.Tests { public class ScriptStartupTypeDiscovererTests { - private const int LatestMajorBundleVersion = 4; - [Fact] public async Task GetExtensionsStartupTypes_UsesDefaultMinVersion() { @@ -1156,64 +1154,6 @@ void CopyToBin(string path) } } - [Theory] - [InlineData("Microsoft.Azure.Functions.ExtensionBundle", "3.36.0", true)] - [InlineData("Microsoft.Azure.Functions.ExtensionBundle", "2.25.0", true)] - [InlineData("Microsoft.Azure.Functions.ExtensionBundle", "4.22.0", false)] - [InlineData("Microsoft.Azure.Functions.ExtensionBundle.Preview", "4.29.0", false)] - [InlineData("Microsoft.Azure.Functions.ExtensionBundle.Preview", "3.2.0", false)] - public async Task CompareWithLatestMajorVersion_LogsExpectedDiagnosticEvents(string bundleId, string bundleVersion, bool shouldLogEvent) - { - using (var directory = GetTempDirectory()) - { - // Setup - TestMetricsLogger testMetricsLogger = new TestMetricsLogger(); - TestLoggerProvider testLoggerProvider = new TestLoggerProvider(); - LoggerFactory factory = new LoggerFactory(); - factory.AddProvider(testLoggerProvider); - var testLogger = factory.CreateLogger(); - - var binPath = Path.Combine(directory.Path, "bin"); - - var mockExtensionBundleManager = new Mock(); - mockExtensionBundleManager.Setup(e => e.IsExtensionBundleConfigured()).Returns(true); - mockExtensionBundleManager.Setup(e => e.GetExtensionBundleBinPathAsync()).Returns(Task.FromResult(binPath)); - mockExtensionBundleManager.Setup(e => e.IsLegacyExtensionBundle()).Returns(false); - mockExtensionBundleManager.Setup(e => e.GetExtensionBundleDetails()).Returns(Task.FromResult(new ExtensionBundleDetails - { - Id = bundleId, - Version = bundleVersion - })); - - var languageWorkerOptions = new TestOptionsMonitor(new LanguageWorkerOptions()); - var mockFunctionMetadataManager = GetTestFunctionMetadataManager(languageWorkerOptions); - OptionsWrapper optionsWrapper = new(new ExtensionRequirementOptions()); - var discoverer = new ScriptStartupTypeLocator(directory.Path, testLogger, mockExtensionBundleManager.Object, mockFunctionMetadataManager, testMetricsLogger, optionsWrapper); - - // Act - we just need to ensure CompareWithLatestMajorVersion is called - try - { - await discoverer.GetExtensionsStartupTypesAsync(); - } - catch (HostInitializationException) - { - // We might get this exception for certain bundle versions, but it's not relevant to this test - } - - // Assert - var traces = testLoggerProvider.GetAllLogMessages(); - string message = string.Format(Resources.OutdatedExtensionBundlesVersionInfoFormat, bundleVersion, LatestMajorBundleVersion, LatestMajorBundleVersion + 1); - - // Check for logs matching the pattern for outdated bundle version - bool hasOutdatedBundleLog = traces.Any(m => - m.Level == LogLevel.Information && - m.FormattedMessage.Contains(message) && - m.FormattedMessage.Contains(bundleVersion)); - - Assert.Equal(shouldLogEvent, hasOutdatedBundleLog); - } - } - private IFunctionMetadataManager GetTestFunctionMetadataManager(IOptionsMonitor options, ICollection metadataCollection = null, bool hasPrecompiledFunction = false, bool hasNodeFunctions = false, bool hasDotnetIsolatedFunctions = false) { var functionMetadata = new FunctionMetadata(); From ea0106d186b5b5f25dda857c6801bf41631ec90f Mon Sep 17 00:00:00 2001 From: manvkaur <67894494+manvkaur@users.noreply.github.com> Date: Thu, 22 May 2025 15:28:03 -0700 Subject: [PATCH 14/14] revert some changes --- .../DependencyInjection/ScriptStartupTypeLocator.cs | 1 + src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs | 1 + test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs b/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs index a0b5bb1112..e8c44f7a2d 100644 --- a/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs +++ b/src/WebJobs.Script/DependencyInjection/ScriptStartupTypeLocator.cs @@ -30,6 +30,7 @@ namespace Microsoft.Azure.WebJobs.Script.DependencyInjection public sealed class ScriptStartupTypeLocator : IWebJobsStartupTypeLocator { private const string ApplicationInsightsStartupType = "Microsoft.Azure.WebJobs.Extensions.ApplicationInsights.ApplicationInsightsWebJobsStartup, Microsoft.Azure.WebJobs.Extensions.ApplicationInsights, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9475d07f10cb09df"; + private readonly string _rootScriptPath; private readonly ILogger _logger; private readonly IExtensionBundleManager _extensionBundleManager; diff --git a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs index 4806f149cc..ecce4a6d06 100644 --- a/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs +++ b/src/WebJobs.Script/ExtensionBundle/ExtensionBundleManager.cs @@ -50,6 +50,7 @@ public async Task GetExtensionBundleDetails() } _extensionBundleVersion = _extensionBundleVersion ?? await GetLatestMatchingBundleVersionAsync(); + return new ExtensionBundleDetails() { Id = _options.Id, diff --git a/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs b/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs index cfb76c5a2d..a924e0b995 100644 --- a/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs +++ b/test/WebJobs.Script.Tests/ScriptStartupTypeDiscovererTests.cs @@ -17,7 +17,6 @@ using Microsoft.Azure.WebJobs.Script.ExtensionBundle; using Microsoft.Azure.WebJobs.Script.ExtensionRequirements; using Microsoft.Azure.WebJobs.Script.Models; -using Microsoft.Azure.WebJobs.Script.Properties; using Microsoft.Azure.WebJobs.Script.Workers.Rpc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options;