-
Notifications
You must be signed in to change notification settings - Fork 910
Add Node.js version selection strategy framework with EOL policy support #5422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rishabhmalikMS
wants to merge
19
commits into
master
Choose a base branch
from
users/rishabhmalikMS/NodehandlerStrategies
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,391
−142
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
68d2621
Adding Strategies for node 24 to node 6 | Adding Interfaces created f…
rishabhmalikMS 0854386
Merge branch 'master' into users/rishabhmalikMS/NodehandlerStrategies
rishabhmalikMS e3b655a
adding EnableEOLNodeVersionPolicy knob
rishabhmalikMS 32e38b9
Merge branch 'users/rishabhmalikMS/NodehandlerStrategies' of https://…
rishabhmalikMS 11d1b64
adding agent knob AGENT_RESTRICT_EOL_NODE_VERSIONS
rishabhmalikMS b5a899b
Minor fix
rishabhmalikMS a52fbdf
Adding localized strings in string.json.
rishabhmalikMS 3e73fe2
Added NodeVersionNotAvailable string
rishabhmalikMS baec4a9
Added IUnifiedNodeVersionStrategy in ServiceInterfaceL0 test
rishabhmalikMS 79110c8
Removed NodeVersionNotAvailable string temporarily.
rishabhmalikMS 7ae51f0
Updating nomenclature
rishabhmalikMS e785a37
- Add NodeVersionOrchestrator to centralize Node.js version selection…
rishabhmalikMS 90b4c7a
_ Added integration for node strategy orchestrator in nodehandler to …
rishabhmalikMS 61fb138
Merge branch 'master' into users/rishabhmalikMS/NodehandlerStrategies
rishabhmalikMS 04ee161
- Consolidate glibc functionality into single provider class
rishabhmalikMS 99ab6bd
Added comment in orchestrator for priorities of strategies which is u…
rishabhmalikMS 92584a2
- Added check for only performing glibc compatibility checks on Linux…
rishabhmalikMS 0cc45e3
- Replace hardcoded string literals with NodeVersion enum across all …
rishabhmalikMS 8f937b1
Minor update to log stack trace
rishabhmalikMS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
40 changes: 40 additions & 0 deletions
40
src/Agent.Worker/NodeVersionStrategies/GlibcCompatibilityInfo.cs
This file contains hidden or 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,40 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.VisualStudio.Services.Agent.Worker.NodeVersionStrategies | ||
| { | ||
| /// <summary> | ||
| /// Contains glibc compatibility information for different Node.js versions. | ||
| /// </summary> | ||
| public class GlibcCompatibilityInfo | ||
| { | ||
| /// <summary> | ||
| /// True if Node24 has glibc compatibility errors (requires glibc 2.28+). | ||
| /// </summary> | ||
| public bool Node24HasGlibcError { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// True if Node20 has glibc compatibility errors (requires glibc 2.17+). | ||
| /// </summary> | ||
| public bool Node20HasGlibcError { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance with no glibc errors (compatible system). | ||
| /// </summary> | ||
| public static GlibcCompatibilityInfo Compatible => new GlibcCompatibilityInfo | ||
| { | ||
| Node24HasGlibcError = false, | ||
| Node20HasGlibcError = false | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance with specific compatibility information. | ||
| /// </summary> | ||
| public static GlibcCompatibilityInfo Create(bool node24HasGlibcError, bool node20HasGlibcError) => | ||
| new GlibcCompatibilityInfo | ||
| { | ||
| Node24HasGlibcError = node24HasGlibcError, | ||
| Node20HasGlibcError = node20HasGlibcError | ||
| }; | ||
| } | ||
| } |
198 changes: 198 additions & 0 deletions
198
src/Agent.Worker/NodeVersionStrategies/GlibcCompatibilityInfoProvider.cs
This file contains hidden or 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,198 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Threading.Tasks; | ||
| using System.Threading; | ||
| using Agent.Sdk; | ||
| using Agent.Sdk.Knob; | ||
| using Microsoft.VisualStudio.Services.Agent.Util; | ||
|
|
||
| namespace Microsoft.VisualStudio.Services.Agent.Worker.NodeVersionStrategies | ||
| { | ||
| /// <summary> | ||
| /// Utility class for checking glibc compatibility with Node.js versions on Linux systems. | ||
| /// </summary> | ||
| public class GlibcCompatibilityInfoProvider : AgentService, IGlibcCompatibilityInfoProvider | ||
| { | ||
| private readonly IExecutionContext _executionContext; | ||
| private readonly IHostContext _hostContext; | ||
| private static bool? _supportsNode20; | ||
| private static bool? _supportsNode24; | ||
|
|
||
| public GlibcCompatibilityInfoProvider(IExecutionContext executionContext, IHostContext hostContext) | ||
| { | ||
| ArgUtil.NotNull(executionContext, nameof(executionContext)); | ||
| ArgUtil.NotNull(hostContext, nameof(hostContext)); | ||
| _executionContext = executionContext; | ||
| _hostContext = hostContext; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks glibc compatibility for both Node20 and Node24. | ||
| /// This method combines the behavior from NodeHandler for both Node versions. | ||
| /// </summary> | ||
| /// <returns>GlibcCompatibilityInfo containing compatibility results for both Node versions</returns> | ||
| public virtual async Task<GlibcCompatibilityInfo> CheckGlibcCompatibilityAsync() | ||
| { | ||
| bool useNode20InUnsupportedSystem = AgentKnobs.UseNode20InUnsupportedSystem.GetValue(_executionContext).AsBoolean(); | ||
| bool useNode24InUnsupportedSystem = AgentKnobs.UseNode24InUnsupportedSystem.GetValue(_executionContext).AsBoolean(); | ||
|
|
||
| bool node20HasGlibcError = false; | ||
| bool node24HasGlibcError = false; | ||
|
|
||
| // Only perform glibc compatibility checks on Linux systems | ||
| if (!IsLinuxPlatform()) | ||
| { | ||
| // Non-Linux systems (Windows, macOS) don't have glibc compatibility issues | ||
| return GlibcCompatibilityInfo.Create(node24HasGlibcError: false, node20HasGlibcError: false); | ||
| } | ||
|
|
||
| if (!useNode20InUnsupportedSystem) | ||
rishabhmalikMS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if (_supportsNode20.HasValue) | ||
| { | ||
| node20HasGlibcError = !_supportsNode20.Value; | ||
rishabhmalikMS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| else | ||
| { | ||
| node20HasGlibcError = await CheckIfNodeResultsInGlibCErrorAsync("node20_1"); | ||
| _executionContext.EmitHostNode20FallbackTelemetry(node20HasGlibcError); | ||
| _supportsNode20 = !node20HasGlibcError; | ||
| } | ||
| } | ||
|
|
||
| if (!useNode24InUnsupportedSystem) | ||
| { | ||
| if (_supportsNode24.HasValue) | ||
| { | ||
| node24HasGlibcError = !_supportsNode24.Value; | ||
| } | ||
| else | ||
| { | ||
| node24HasGlibcError = await CheckIfNodeResultsInGlibCErrorAsync("node24"); | ||
| _executionContext.EmitHostNode24FallbackTelemetry(node24HasGlibcError); | ||
| _supportsNode24 = !node24HasGlibcError; | ||
| } | ||
| } | ||
|
|
||
| return GlibcCompatibilityInfo.Create(node24HasGlibcError, node20HasGlibcError); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets glibc compatibility information based on the execution context (host vs container). | ||
| /// </summary> | ||
| /// <param name="context">The task context containing container and handler information</param> | ||
| /// <returns>Glibc compatibility information for the current execution environment</returns> | ||
| public virtual async Task<GlibcCompatibilityInfo> GetGlibcCompatibilityAsync(TaskContext context) | ||
| { | ||
| ArgUtil.NotNull(context, nameof(context)); | ||
|
|
||
| string environmentType = context.Container != null ? "Container" : "Host"; | ||
|
|
||
| if (context.Container == null) | ||
| { | ||
| // Host execution - check actual glibc compatibility | ||
| var glibcInfo = await CheckGlibcCompatibilityAsync(); | ||
|
|
||
| _executionContext.Debug($"[{environmentType}] Host glibc compatibility - Node24: {!glibcInfo.Node24HasGlibcError}, Node20: {!glibcInfo.Node20HasGlibcError}"); | ||
|
|
||
| return glibcInfo; | ||
| } | ||
| else | ||
| { | ||
| // Container execution - use container-specific redirect information | ||
| var glibcInfo = GlibcCompatibilityInfo.Create( | ||
| node24HasGlibcError: context.Container.NeedsNode20Redirect, | ||
rishabhmalikMS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| node20HasGlibcError: context.Container.NeedsNode16Redirect); | ||
|
|
||
| _executionContext.Debug($"[{environmentType}] Container glibc compatibility - Node24: {!glibcInfo.Node24HasGlibcError}, Node20: {!glibcInfo.Node20HasGlibcError}"); | ||
|
|
||
| return glibcInfo; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks if the specified Node.js version results in glibc compatibility errors. | ||
| /// </summary> | ||
| /// <param name="nodeFolder">The node folder name (e.g., "node20_1", "node24")</param> | ||
| /// <returns>True if glibc error is detected, false otherwise</returns> | ||
| public virtual async Task<bool> CheckIfNodeResultsInGlibCErrorAsync(string nodeFolder) | ||
| { | ||
| var nodePath = Path.Combine(_hostContext.GetDirectory(WellKnownDirectory.Externals), nodeFolder, "bin", $"node{IOUtil.ExeExtension}"); | ||
| List<string> nodeVersionOutput = await ExecuteCommandAsync(_executionContext, nodePath, "-v", requireZeroExitCode: false, showOutputOnFailureOnly: true); | ||
| var nodeResultsInGlibCError = WorkerUtilities.IsCommandResultGlibcError(_executionContext, nodeVersionOutput, out string nodeInfoLine); | ||
|
|
||
| return nodeResultsInGlibCError; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines if the current platform is Linux. Virtual for testing override. | ||
| /// </summary> | ||
| /// <returns>True if running on Linux, false otherwise</returns> | ||
| protected virtual bool IsLinuxPlatform() | ||
| { | ||
| return PlatformUtil.HostOS == PlatformUtil.OS.Linux; | ||
| } | ||
|
|
||
| private async Task<List<string>> ExecuteCommandAsync(IExecutionContext context, string command, string arg, bool requireZeroExitCode, bool showOutputOnFailureOnly) | ||
| { | ||
| string commandLog = $"{command} {arg}"; | ||
| if (!showOutputOnFailureOnly) | ||
| { | ||
| context.Command(commandLog); | ||
| } | ||
|
|
||
| List<string> outputs = new List<string>(); | ||
| object outputLock = new object(); | ||
| var processInvoker = _hostContext.CreateService<IProcessInvoker>(); | ||
| processInvoker.OutputDataReceived += delegate (object sender, ProcessDataReceivedEventArgs message) | ||
| { | ||
| if (!string.IsNullOrEmpty(message.Data)) | ||
| { | ||
| lock (outputLock) | ||
| { | ||
| outputs.Add(message.Data); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| processInvoker.ErrorDataReceived += delegate (object sender, ProcessDataReceivedEventArgs message) | ||
| { | ||
| if (!string.IsNullOrEmpty(message.Data)) | ||
| { | ||
| lock (outputLock) | ||
| { | ||
| outputs.Add(message.Data); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| var exitCode = await processInvoker.ExecuteAsync( | ||
| workingDirectory: _hostContext.GetDirectory(WellKnownDirectory.Work), | ||
| fileName: command, | ||
| arguments: arg, | ||
| environment: null, | ||
| requireExitCodeZero: requireZeroExitCode, | ||
| outputEncoding: null, | ||
| cancellationToken: System.Threading.CancellationToken.None); | ||
|
|
||
| if (!showOutputOnFailureOnly || exitCode != 0) | ||
| { | ||
| if (showOutputOnFailureOnly) | ||
| { | ||
| context.Command(commandLog); | ||
| } | ||
|
|
||
| foreach (var outputLine in outputs) | ||
| { | ||
| context.Debug(outputLine); | ||
| } | ||
| } | ||
|
|
||
| return outputs; | ||
| } | ||
| } | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
src/Agent.Worker/NodeVersionStrategies/IGlibcCompatibilityInfoProvider.cs
This file contains hidden or 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,36 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Threading.Tasks; | ||
| using Microsoft.VisualStudio.Services.Agent; | ||
| using Microsoft.VisualStudio.Services.Agent.Worker; | ||
|
|
||
| namespace Microsoft.VisualStudio.Services.Agent.Worker.NodeVersionStrategies | ||
| { | ||
| /// <summary> | ||
| /// Interface for checking glibc compatibility with Node.js versions on Linux systems. | ||
| /// </summary> | ||
| [ServiceLocator(Default = typeof(GlibcCompatibilityInfoProvider))] | ||
| public interface IGlibcCompatibilityInfoProvider : IAgentService | ||
| { | ||
| /// <summary> | ||
| /// Checks glibc compatibility for both Node20 and Node24. | ||
| /// </summary> | ||
| /// <returns>GlibcCompatibilityInfo containing compatibility results for both Node versions</returns> | ||
| Task<GlibcCompatibilityInfo> CheckGlibcCompatibilityAsync(); | ||
|
|
||
| /// <summary> | ||
| /// Gets glibc compatibility information, adapting to execution context (host vs container). | ||
| /// </summary> | ||
| /// <param name="context">Task execution context for determining environment</param> | ||
| /// <returns>GlibcCompatibilityInfo containing compatibility results for both Node versions</returns> | ||
| Task<GlibcCompatibilityInfo> GetGlibcCompatibilityAsync(TaskContext context); | ||
|
|
||
| /// <summary> | ||
| /// Checks if the specified Node.js version results in glibc compatibility errors. | ||
| /// </summary> | ||
| /// <param name="nodeFolder">The node folder name (e.g., "node20_1", "node24")</param> | ||
| /// <returns>True if glibc error is detected, false otherwise</returns> | ||
| Task<bool> CheckIfNodeResultsInGlibCErrorAsync(string nodeFolder); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.