-
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
17
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.
Open
Changes from 11 commits
Commits
Show all changes
17 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 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
Some comments aren't visible on the classic Files Changed page.
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
37 changes: 37 additions & 0 deletions
37
src/Agent.Worker/NodeVersionStrategies/INodeVersionStrategy.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,37 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.VisualStudio.Services.Agent.Worker.NodeVersionStrategies | ||
| { | ||
| /// <summary> | ||
| /// Strategy interface for both host and container node selection. | ||
| /// </summary> | ||
| public interface INodeVersionStrategy | ||
| { | ||
| /// <summary> | ||
| /// Human-readable name of this strategy for logging and debugging. | ||
| /// Examples: "Node24", "Node20", "Node16", "CustomNode" | ||
| /// </summary> | ||
| string Name { get; } | ||
|
|
||
| /// <summary> | ||
| /// Checks if this strategy can handle the given context. | ||
| /// Includes handler type, knob checks, EOL policy, and glibc compatibility. | ||
| /// </summary> | ||
| /// <param name="context">Context with environment, task, and glibc information</param> | ||
| /// <returns>True if this strategy can handle the context, false otherwise</returns> | ||
| bool CanHandle(NodeContext context); | ||
|
|
||
| /// <summary> | ||
| /// Gets the Node path for the given context. | ||
| /// Works for both host and container (path translation handled internally). | ||
| /// May throw NotSupportedException if EOL policy is violated. | ||
| /// </summary> | ||
| /// <param name="context">Context with environment, task, and glibc information</param> | ||
| /// <returns>NodeRunnerInfo with path, version, reason, and optional warning</returns> | ||
| /// <exception cref="NotSupportedException">If EOL policy prevents using this version</exception> | ||
| NodeRunnerInfo GetNodePath(NodeContext context); | ||
| } | ||
| } |
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,69 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using Agent.Sdk.Knob; | ||
| using Microsoft.TeamFoundation.DistributedTask.WebApi; | ||
| using Microsoft.VisualStudio.Services.Agent.Util; | ||
| using Microsoft.VisualStudio.Services.Agent.Worker; | ||
|
|
||
| namespace Microsoft.VisualStudio.Services.Agent.Worker.NodeVersionStrategies | ||
| { | ||
| public sealed class Node10Strategy : INodeVersionStrategy | ||
| { | ||
| public string Name => "Node10"; | ||
|
|
||
| public bool CanHandle(NodeContext context) | ||
| { | ||
| bool hasNode10Handler = context.HandlerData is Node10HandlerData; | ||
| bool eolPolicyEnabled = AgentKnobs.EnableEOLNodeVersionPolicy.GetValue(context.ExecutionContext).AsBoolean(); | ||
|
|
||
| if (hasNode10Handler) | ||
| { | ||
| return DetermineNodeVersionAndSetContext(context, eolPolicyEnabled, "Selected for Node10 task handler"); | ||
| } | ||
|
|
||
| bool isAlpine = context.IsAlpine; | ||
| if (isAlpine) | ||
| { | ||
| context.ExecutionContext.Warning( | ||
| "Using Node10 on Alpine Linux because Node6 is not compatible. " + | ||
| "Node10 has reached End-of-Life. Please upgrade to Node20 or Node24 for continued support."); | ||
|
|
||
| return DetermineNodeVersionAndSetContext(context, eolPolicyEnabled, "Selected for Alpine Linux compatibility (Node6 incompatible)"); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private bool DetermineNodeVersionAndSetContext(NodeContext context, bool eolPolicyEnabled, string baseReason) | ||
| { | ||
| if (eolPolicyEnabled) | ||
| { | ||
| throw new NotSupportedException(StringUtil.Loc("NodeEOLPolicyBlocked", "Node10")); | ||
| } | ||
|
|
||
| context.SelectedNodeVersion = "node10"; | ||
| context.SelectionReason = baseReason; | ||
| context.SelectionWarning = StringUtil.Loc("NodeEOLWarning", "Node10"); | ||
| return true; | ||
| } | ||
|
|
||
| public NodeRunnerInfo GetNodePath(NodeContext context) | ||
| { | ||
| string externalsPath = context.HostContext.GetDirectory(WellKnownDirectory.Externals); | ||
| string hostPath = Path.Combine(externalsPath, context.SelectedNodeVersion, "bin", $"node{IOUtil.ExeExtension}"); | ||
| string finalPath = context.IsContainer && context.Container != null ? | ||
| context.Container.TranslateToContainerPath(hostPath) : hostPath; | ||
|
|
||
| return new NodeRunnerInfo | ||
| { | ||
| NodePath = finalPath, | ||
| NodeVersion = context.SelectedNodeVersion, | ||
| Reason = context.SelectionReason, | ||
| Warning = context.SelectionWarning | ||
| }; | ||
| } | ||
| } | ||
| } |
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,59 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using Agent.Sdk.Knob; | ||
| using Microsoft.TeamFoundation.DistributedTask.WebApi; | ||
| using Microsoft.VisualStudio.Services.Agent.Util; | ||
| using Microsoft.VisualStudio.Services.Agent.Worker; | ||
|
|
||
| namespace Microsoft.VisualStudio.Services.Agent.Worker.NodeVersionStrategies | ||
| { | ||
| public sealed class Node16Strategy : INodeVersionStrategy | ||
| { | ||
| public string Name => "Node16"; | ||
|
|
||
| public bool CanHandle(NodeContext context) | ||
| { | ||
| bool hasNode16Handler = context.HandlerData is Node16HandlerData; | ||
| bool eolPolicyEnabled = AgentKnobs.EnableEOLNodeVersionPolicy.GetValue(context.ExecutionContext).AsBoolean(); | ||
|
|
||
| if (hasNode16Handler) | ||
| { | ||
| return DetermineNodeVersionAndSetContext(context, eolPolicyEnabled, "Selected for Node16 task handler"); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private bool DetermineNodeVersionAndSetContext(NodeContext context, bool eolPolicyEnabled, string baseReason) | ||
| { | ||
| if (eolPolicyEnabled) | ||
| { | ||
| throw new NotSupportedException(StringUtil.Loc("NodeEOLPolicyBlocked", "Node16")); | ||
| } | ||
|
|
||
| context.SelectedNodeVersion = "node16"; | ||
| context.SelectionReason = baseReason; | ||
| context.SelectionWarning = StringUtil.Loc("NodeEOLWarning", "Node16"); | ||
| return true; | ||
| } | ||
|
|
||
| public NodeRunnerInfo GetNodePath(NodeContext context) | ||
| { | ||
| string externalsPath = context.HostContext.GetDirectory(WellKnownDirectory.Externals); | ||
| string hostPath = Path.Combine(externalsPath, context.SelectedNodeVersion, "bin", $"node{IOUtil.ExeExtension}"); | ||
| string finalPath = context.IsContainer && context.Container != null ? | ||
| context.Container.TranslateToContainerPath(hostPath) : hostPath; | ||
|
|
||
| return new NodeRunnerInfo | ||
| { | ||
| NodePath = finalPath, | ||
| NodeVersion = context.SelectedNodeVersion, | ||
| Reason = context.SelectionReason, | ||
| Warning = context.SelectionWarning | ||
| }; | ||
| } | ||
| } | ||
| } |
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,79 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using Agent.Sdk.Knob; | ||
| using Microsoft.TeamFoundation.DistributedTask.WebApi; | ||
| using Microsoft.VisualStudio.Services.Agent.Util; | ||
| using Microsoft.VisualStudio.Services.Agent.Worker; | ||
|
|
||
| namespace Microsoft.VisualStudio.Services.Agent.Worker.NodeVersionStrategies | ||
| { | ||
| public sealed class Node20Strategy : INodeVersionStrategy | ||
| { | ||
| public string Name => "Node20"; | ||
|
|
||
| public bool CanHandle(NodeContext context) | ||
| { | ||
| bool useNode20Globally = AgentKnobs.UseNode20_1.GetValue(context.ExecutionContext).AsBoolean(); | ||
| bool hasNode20Handler = context.HandlerData is Node20_1HandlerData; | ||
| bool eolPolicyEnabled = AgentKnobs.EnableEOLNodeVersionPolicy.GetValue(context.ExecutionContext).AsBoolean(); | ||
|
|
||
| if (useNode20Globally) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have this flag? isn't all tasks moved to Node 20 and this should be default |
||
| { | ||
| return DetermineNodeVersionAndSetContext(context, eolPolicyEnabled, "Selected via global AGENT_USE_NODE20_1 override"); | ||
| } | ||
|
|
||
| if (hasNode20Handler) | ||
| { | ||
| return DetermineNodeVersionAndSetContext(context, eolPolicyEnabled, "Selected for Node20 task handler"); | ||
| } | ||
|
|
||
| if (eolPolicyEnabled) | ||
rishabhmalikMS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return DetermineNodeVersionAndSetContext(context, eolPolicyEnabled, "Upgraded from end-of-life Node version due to EOL policy"); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private bool DetermineNodeVersionAndSetContext(NodeContext context, bool eolPolicyEnabled, string baseReason) | ||
| { | ||
| if (!context.Node20HasGlibcError) | ||
| { | ||
| context.SelectedNodeVersion = "node20_1"; | ||
| context.SelectionReason = baseReason; | ||
| context.SelectionWarning = null; | ||
| return true; | ||
| } | ||
|
|
||
| if (eolPolicyEnabled) | ||
| { | ||
| throw new NotSupportedException(StringUtil.Loc("NodeEOLFallbackBlocked", "Node20", "Node16")); | ||
| } | ||
|
|
||
| string systemType = context.IsContainer ? "container" : "agent"; | ||
| context.SelectedNodeVersion = "node16"; | ||
| context.SelectionReason = $"{baseReason}, fallback to Node16 due to Node20 glibc compatibility issue"; | ||
| context.SelectionWarning = StringUtil.Loc("NodeGlibcFallbackWarning", systemType, "Node20", "Node16"); | ||
rishabhmalikMS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return true; | ||
| } | ||
|
|
||
| public NodeRunnerInfo GetNodePath(NodeContext context) | ||
| { | ||
| string externalsPath = context.HostContext.GetDirectory(WellKnownDirectory.Externals); | ||
| string hostPath = Path.Combine(externalsPath, context.SelectedNodeVersion, "bin", $"node{IOUtil.ExeExtension}"); | ||
| string finalPath = context.IsContainer && context.Container != null ? | ||
| context.Container.TranslateToContainerPath(hostPath) : hostPath; | ||
|
|
||
| return new NodeRunnerInfo | ||
| { | ||
| NodePath = finalPath, | ||
| NodeVersion = context.SelectedNodeVersion, | ||
| Reason = context.SelectionReason, | ||
| Warning = context.SelectionWarning | ||
| }; | ||
| } | ||
| } | ||
| } | ||
102 changes: 102 additions & 0 deletions
102
src/Agent.Worker/NodeVersionStrategies/Node24Strategy.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,102 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using Agent.Sdk.Knob; | ||
| using Microsoft.TeamFoundation.DistributedTask.WebApi; | ||
| using Microsoft.VisualStudio.Services.Agent.Util; | ||
| using Microsoft.VisualStudio.Services.Agent.Worker; | ||
|
|
||
| namespace Microsoft.VisualStudio.Services.Agent.Worker.NodeVersionStrategies | ||
| { | ||
| public sealed class Node24Strategy : INodeVersionStrategy | ||
| { | ||
| public string Name => "Node24"; | ||
|
|
||
| public bool CanHandle(NodeContext context) | ||
| { | ||
| bool useNode24Globally = AgentKnobs.UseNode24.GetValue(context.ExecutionContext).AsBoolean(); | ||
| bool hasNode24Handler = context.HandlerData is Node24HandlerData; | ||
| bool useNode24WithHandlerData = AgentKnobs.UseNode24withHandlerData.GetValue(context.ExecutionContext).AsBoolean(); | ||
| bool eolPolicyEnabled = AgentKnobs.EnableEOLNodeVersionPolicy.GetValue(context.ExecutionContext).AsBoolean(); | ||
|
|
||
| if (useNode24Globally) | ||
| { | ||
| context.ExecutionContext.Debug("[Node24Strategy] AGENT_USE_NODE24=true → Global override"); | ||
| return DetermineNodeVersionAndSetContext(context, eolPolicyEnabled, "Selected via global AGENT_USE_NODE24 override"); | ||
| } | ||
|
|
||
| if (hasNode24Handler) | ||
| { | ||
| if (useNode24WithHandlerData) | ||
| { | ||
| return DetermineNodeVersionAndSetContext(context, eolPolicyEnabled, "Selected for Node24 task with handler knob enabled"); | ||
| } | ||
| else | ||
| { | ||
| context.SelectedNodeVersion = "node20_1"; | ||
| context.SelectionReason = "Node24 task detected but handler knob disabled, falling back to Node20"; | ||
| context.SelectionWarning = null; | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| if (eolPolicyEnabled) | ||
| { | ||
| return DetermineNodeVersionAndSetContext(context, eolPolicyEnabled, "Upgraded from end-of-life Node version due to EOL policy"); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| private bool DetermineNodeVersionAndSetContext(NodeContext context, bool eolPolicyEnabled, string baseReason) | ||
rishabhmalikMS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| string systemType = context.IsContainer ? "container" : "agent"; | ||
|
|
||
| if (!context.Node24HasGlibcError) | ||
| { | ||
| context.SelectedNodeVersion = "node24"; | ||
| context.SelectionReason = baseReason; | ||
| context.SelectionWarning = null; | ||
| return true; | ||
| } | ||
|
|
||
| if (!context.Node20HasGlibcError) | ||
| { | ||
| context.SelectedNodeVersion = "node20_1"; | ||
| context.SelectionReason = $"{baseReason}, fallback to Node20 due to Node24 glibc compatibility issue"; | ||
| context.SelectionWarning = StringUtil.Loc("NodeGlibcFallbackWarning", systemType, "Node24", "Node20"); | ||
| return true; | ||
| } | ||
|
|
||
| if (eolPolicyEnabled) | ||
| { | ||
| context.ExecutionContext.Debug("[Node24Strategy] Would need Node16 but EOL policy being enabled this is not supported"); | ||
| string handlerType = context.HandlerData != null ? context.HandlerData.GetType().Name : "UnknownHandlerData"; | ||
| throw new NotSupportedException($"No compatible Node.js version available for host execution. Handler type: {handlerType}. This may occur if all available versions are blocked by EOL policy. Please update your pipeline to use Node20 or Node24 tasks. To temporarily disable EOL policy: Set AGENT_ENABLE_EOL_NODE_VERSION_POLICY=false"); | ||
| } | ||
|
|
||
| context.SelectedNodeVersion = "node16"; | ||
| context.SelectionReason = $"{baseReason}, fallback to Node16 due to both Node24 and Node20 glibc compatibility issues"; | ||
| context.SelectionWarning = StringUtil.Loc("NodeGlibcFallbackWarning", systemType, "Node24 or Node20", "Node16"); | ||
| return true; | ||
| } | ||
|
|
||
| public NodeRunnerInfo GetNodePath(NodeContext context) | ||
| { | ||
| string externalsPath = context.HostContext.GetDirectory(WellKnownDirectory.Externals); | ||
| string hostPath = Path.Combine(externalsPath, context.SelectedNodeVersion, "bin", $"node{IOUtil.ExeExtension}"); | ||
| string finalPath = context.IsContainer && context.Container != null ? | ||
| context.Container.TranslateToContainerPath(hostPath) : hostPath; | ||
|
|
||
| return new NodeRunnerInfo | ||
| { | ||
| NodePath = finalPath, | ||
| NodeVersion = context.SelectedNodeVersion, | ||
| Reason = context.SelectionReason, | ||
| Warning = context.SelectionWarning | ||
| }; | ||
| } | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DO we need both sources for toggle to work ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are we planning to do E2E test for this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One knob is used as a feature flag to enable/disable the feature all together. Another is used to read the value of toggle from UI injected from server side. The same feature flag can be used to enable/disable Ui toggle & agent side functionality to maintain consistency on both ends.
Regarding E2E testing: Planning to use devfabric for updated server-side logic along with updated agent logic to test integrated functionality.