Skip to content

Commit

Permalink
Merge branch 'users/ismayilov-ismayil/remove_node6_runner' of https:/…
Browse files Browse the repository at this point in the history
…/github.com/microsoft/azure-pipelines-agent into users/ismayilov-ismayil/remove_node6_runner
  • Loading branch information
ismayilov-ismayil committed Dec 9, 2023
2 parents 4dc7dec + e3d3a4f commit 1d4e1d6
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 19 deletions.
18 changes: 12 additions & 6 deletions assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
"version": "<AGENT_VERSION>",
"downloadUrl": "https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-osx-x64-<AGENT_VERSION>.tar.gz"
},
{
"name": "vsts-agent-osx-arm64-<AGENT_VERSION>.tar.gz",
"platform": "osx-arm64",
"version": "<AGENT_VERSION>",
"downloadUrl": "https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/vsts-agent-osx-arm64-<AGENT_VERSION>.tar.gz"
},
{
"name": "pipelines-agent-osx-arm64-<AGENT_VERSION>.tar.gz",
"platform": "osx-arm64",
"version": "<AGENT_VERSION>",
"downloadUrl": "https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-osx-arm64-<AGENT_VERSION>.tar.gz"
},
{
"name": "vsts-agent-linux-x64-<AGENT_VERSION>.tar.gz",
"platform": "linux-x64",
Expand Down Expand Up @@ -76,11 +88,5 @@
"platform": "linux-musl-x64",
"version": "<AGENT_VERSION>",
"downloadUrl": "https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/vsts-agent-linux-musl-x64-<AGENT_VERSION>.tar.gz"
},
{
"name": "pipelines-agent-linux-musl-x64-<AGENT_VERSION>.tar.gz",
"platform": "linux-musl-x64",
"version": "<AGENT_VERSION>",
"downloadUrl": "https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-linux-musl-x64-<AGENT_VERSION>.tar.gz"
}
]
2 changes: 1 addition & 1 deletion releaseNote.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ See [notes](docs/node6.md) on Node version support for more details.
| Windows x64 | [pipelines-agent-win-x64-<AGENT_VERSION>.zip](https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-win-x64-<AGENT_VERSION>.zip) | <HASH> |
| Windows x86 | [pipelines-agent-win-x86-<AGENT_VERSION>.zip](https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-win-x86-<AGENT_VERSION>.zip) | <HASH> |
| macOS x64 | [pipelines-agent-osx-x64-<AGENT_VERSION>.tar.gz](https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-osx-x64-<AGENT_VERSION>.tar.gz) | <HASH> |
| macOS ARM64 | [pipelines-agent-osx-arm64-<AGENT_VERSION>.tar.gz](https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-osx-x64-<AGENT_VERSION>.tar.gz) | <HASH> |
| macOS ARM64 | [pipelines-agent-osx-arm64-<AGENT_VERSION>.tar.gz](https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-osx-arm64-<AGENT_VERSION>.tar.gz) | <HASH> |
| Linux x64 | [pipelines-agent-linux-x64-<AGENT_VERSION>.tar.gz](https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-linux-x64-<AGENT_VERSION>.tar.gz) | <HASH> |
| Linux ARM | [pipelines-agent-linux-arm-<AGENT_VERSION>.tar.gz](https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-linux-arm-<AGENT_VERSION>.tar.gz) | <HASH> |
| Linux ARM64 | [pipelines-agent-linux-arm64-<AGENT_VERSION>.tar.gz](https://vstsagentpackage.azureedge.net/agent/<AGENT_VERSION>/pipelines-agent-linux-arm64-<AGENT_VERSION>.tar.gz) | <HASH> |
3 changes: 2 additions & 1 deletion src/Agent.Listener/Configuration/FeatureFlagProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ public async Task<FeatureFlag> GetFeatureFlagAsync(IHostContext context, string

var credMgr = context.GetService<ICredentialManager>();
var configManager = context.GetService<IConfigurationManager>();
var agentCertManager = context.GetService<IAgentCertificateManager>();

VssCredentials creds = credMgr.LoadCredentials();
ArgUtil.NotNull(creds, nameof(creds));

AgentSettings settings = configManager.LoadSettings();
using var vssConnection = VssUtil.CreateConnection(new Uri(settings.ServerUrl), creds, traceWriter);
using var vssConnection = VssUtil.CreateConnection(new Uri(settings.ServerUrl), creds, traceWriter, agentCertManager.SkipServerCertificateValidation);
var client = vssConnection.GetClient<FeatureAvailabilityHttpClient>();
try
{
Expand Down
39 changes: 38 additions & 1 deletion src/Agent.Listener/JobDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Agent.Sdk.Knob;
using Agent.Sdk.Util;
using Agent.Listener.Configuration;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand All @@ -17,7 +18,9 @@
using System.Linq;
using Microsoft.VisualStudio.Services.Common;
using System.Diagnostics;
using Agent.Listener.Configuration;
using Newtonsoft.Json;
using Microsoft.VisualStudio.Services.Agent.Listener.Telemetry;


namespace Microsoft.VisualStudio.Services.Agent.Listener
{
Expand Down Expand Up @@ -610,6 +613,13 @@ await processChannel.SendAsync(
var messageType = MessageType.CancelRequest;
if (HostContext.AgentShutdownToken.IsCancellationRequested)
{
var service = HostContext.GetService<IFeatureFlagProvider>();
var ffState = await service.GetFeatureFlagAsync(HostContext, "DistributedTask.Agent.FailJobWhenAgentDies", Trace);
if (ffState.EffectiveState == "On")
{
await PublishTelemetry(message, TaskResult.Failed.ToString(), "100");
resultOnAbandonOrCancel = TaskResult.Failed;
}
switch (HostContext.AgentShutdownReason)
{
case ShutdownReason.UserCancelled:
Expand Down Expand Up @@ -915,6 +925,33 @@ private async Task LogWorkerProcessUnhandledException(Pipelines.AgentJobRequestM
}
}

private async Task PublishTelemetry(Pipelines.AgentJobRequestMessage message, string Task_Result, string TracePoint)
{
try
{
var telemetryData = new Dictionary<string, string>
{
{ "JobId", message.JobId.ToString()},
{ "JobResult", Task_Result },
{ "TracePoint", TracePoint},
};
var cmd = new Command("telemetry", "publish")
{
Data = JsonConvert.SerializeObject(telemetryData)
};
cmd.Properties.Add("area", "PipelinesTasks");
cmd.Properties.Add("feature", "AgentShutdown");

var telemetryPublisher = HostContext.GetService<IAgenetListenerTelemetryPublisher>();

await telemetryPublisher.PublishEvent(HostContext, cmd);
}
catch (Exception ex)
{
Trace.Warning($"Unable to publish agent shutdown telemetry data. Exception: {ex}");
}
}

private class WorkerDispatcher : IDisposable
{
public long RequestId { get; }
Expand Down
3 changes: 2 additions & 1 deletion src/Agent.Listener/Telemetry/TelemetryPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ public async Task PublishEvent(IHostContext context, Command command)

var configManager = context.GetService<IConfigurationManager>();
AgentSettings settings = configManager.LoadSettings();
var agentCertManager = context.GetService<IAgentCertificateManager>();

using var vsConnection = VssUtil.CreateConnection(new Uri(settings.ServerUrl), creds, Trace);
using var vsConnection = VssUtil.CreateConnection(new Uri(settings.ServerUrl), creds, Trace, agentCertManager.SkipServerCertificateValidation);
_ciService.Initialize(vsConnection);
await PublishEventsAsync(context, ciEvent);

Expand Down
7 changes: 7 additions & 0 deletions src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ public class AgentKnobs
new EnvironmentKnobSource("AZP_AGENT_IGNORE_VSTSTASKLIB"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob FailJobWhenAgentDies = new Knob(
nameof(FailJobWhenAgentDies),
"Mark the Job as Failed instead of Canceled when the Agent dies due to User Cancellation or Shutdown",
new RuntimeKnobSource("FAIL_JOB_WHEN_AGENT_DIES"),
new EnvironmentKnobSource("FAIL_JOB_WHEN_AGENT_DIES"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob AllowWorkDirectoryRepositories = new Knob(
nameof(AllowWorkDirectoryRepositories),
"Allows repositories to be checked out below work directory level on self hosted agents.",
Expand Down
47 changes: 43 additions & 4 deletions src/Agent.Worker/JobExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using System.Diagnostics;
using Agent.Sdk;
using Agent.Sdk.Knob;
using Newtonsoft.Json;
using Microsoft.VisualStudio.Services.Agent.Worker.Telemetry;

namespace Microsoft.VisualStudio.Services.Agent.Worker
{
Expand Down Expand Up @@ -479,10 +481,22 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
catch (OperationCanceledException ex) when (jobContext.CancellationToken.IsCancellationRequested)
{
// Log the exception and cancel the JobExtension Initialization.
Trace.Error($"Caught cancellation exception from JobExtension Initialization: {ex}");
context.Error(ex);
context.Result = TaskResult.Canceled;
throw;
if (AgentKnobs.FailJobWhenAgentDies.GetValue(jobContext).AsBoolean() &&
HostContext.AgentShutdownToken.IsCancellationRequested)
{
PublishTelemetry(jobContext, TaskResult.Failed.ToString(), "110");
Trace.Error($"Caught Agent Shutdown exception from JobExtension Initialization: {ex.Message}");
context.Error(ex);
context.Result = TaskResult.Failed;
throw;
}
else
{
Trace.Error($"Caught cancellation exception from JobExtension Initialization: {ex}");
context.Error(ex);
context.Result = TaskResult.Canceled;
throw;
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -659,6 +673,31 @@ private void OutputSetupInfo(IExecutionContext context)
Trace.Error(ex);
}
}

private void PublishTelemetry(IExecutionContext context, string Task_Result, string TracePoint)
{
try
{
var telemetryData = new Dictionary<string, string>
{
{ "JobId", context.Variables.System_JobId.ToString()},
{ "JobResult", Task_Result },
{ "TracePoint", TracePoint},
};
var cmd = new Command("telemetry", "publish");
cmd.Data = JsonConvert.SerializeObject(telemetryData, Formatting.None);
cmd.Properties.Add("area", "PipelinesTasks");
cmd.Properties.Add("feature", "AgentShutdown");

var publishTelemetryCmd = new TelemetryCommandExtension();
publishTelemetryCmd.Initialize(HostContext);
publishTelemetryCmd.ProcessCommand(context, cmd);
}
catch (Exception ex)
{
Trace.Warning($"Unable to publish agent shutdown telemetry data. Exception: {ex}");
}
}
}

public class UnsupportedOsException : Exception
Expand Down
44 changes: 41 additions & 3 deletions src/Agent.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using System.Threading.Tasks;
using System.Net.Http;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Microsoft.VisualStudio.Services.Agent.Worker.Telemetry;

namespace Microsoft.VisualStudio.Services.Agent.Worker
{
Expand Down Expand Up @@ -297,9 +299,20 @@ public async Task<TaskResult> RunAsync(Pipelines.AgentJobRequestMessage message,
{
// set the job to canceled
// don't log error issue to job ExecutionContext, since server owns the job level issue
Trace.Error($"Job is canceled during initialize.");
Trace.Error($"Caught exception: {ex}");
return await CompleteJobAsync(jobServer, jobContext, message, TaskResult.Canceled);
if (AgentKnobs.FailJobWhenAgentDies.GetValue(jobContext).AsBoolean() &&
HostContext.AgentShutdownToken.IsCancellationRequested)
{
PublishTelemetry(jobContext, TaskResult.Failed.ToString(), "111");
Trace.Error($"Job is canceled during initialize.");
Trace.Error($"Caught exception: {ex}");
return await CompleteJobAsync(jobServer, jobContext, message, TaskResult.Failed);
}
else
{
Trace.Error($"Job is canceled during initialize.");
Trace.Error($"Caught exception: {ex}");
return await CompleteJobAsync(jobServer, jobContext, message, TaskResult.Canceled);
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -597,5 +610,30 @@ private void ReplaceConfigUriBaseInJobRequestMessage(Pipelines.AgentJobRequestMe
Trace.Info($"Ensure System.TFServerUrl match config url base. {message.Variables[Constants.Variables.System.TFServerUrl].Value}");
}
}

private void PublishTelemetry(IExecutionContext context, string Task_Result, string TracePoint)
{
try
{
var telemetryData = new Dictionary<string, string>
{
{ "JobId", context.Variables.System_JobId.ToString()},
{ "JobResult", Task_Result },
{ "TracePoint", TracePoint},
};
var cmd = new Command("telemetry", "publish");
cmd.Data = JsonConvert.SerializeObject(telemetryData, Formatting.None);
cmd.Properties.Add("area", "PipelinesTasks");
cmd.Properties.Add("feature", "AgentShutdown");

var publishTelemetryCmd = new TelemetryCommandExtension();
publishTelemetryCmd.Initialize(HostContext);
publishTelemetryCmd.ProcessCommand(context, cmd);
}
catch (Exception ex)
{
Trace.Warning($"Unable to publish agent shutdown telemetry data. Exception: {ex}");
}
}
}
}
Loading

0 comments on commit 1d4e1d6

Please sign in to comment.