Skip to content

Commit 41d0ce3

Browse files
committed
Merge remote-tracking branch 'origin/master' into Localization
2 parents 161c02b + c660a56 commit 41d0ce3

File tree

10 files changed

+56
-61
lines changed

10 files changed

+56
-61
lines changed

src/Agent.Listener/Agent.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,6 @@ public async Task<int> ExecuteCommand(CommandSettings command)
216216
Trace.Info($"Set agent startup type - {startType}");
217217
HostContext.StartupType = startType;
218218

219-
bool debugModeEnabled = command.GetDebugMode();
220-
settings.DebugMode = debugModeEnabled;
221-
store.SaveSettings(settings);
222-
if (debugModeEnabled)
223-
{
224-
Trace.Warning("Agent is running in debug mode, don't use it in production");
225-
}
226219
if (PlatformUtil.RunningOnWindows)
227220
{
228221
if (store.IsAutoLogonConfigured())

src/Agent.Listener/CommandLine/RunAgent.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,5 @@ public class RunAgent : BaseCommand
1818

1919
[Option(Constants.Agent.CommandLine.Args.StartupType)]
2020
public string StartupType { get; set; }
21-
22-
[Option(Constants.Agent.CommandLine.Flags.DebugMode)]
23-
public bool DebugMode { get; set; }
2421
}
2522
}

src/Agent.Listener/CommandSettings.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,6 @@ public bool GetRunOnce()
550550
TestFlag(Run?.RunOnce, Constants.Agent.CommandLine.Flags.Once);
551551
}
552552

553-
public bool GetDebugMode()
554-
{
555-
return TestFlag(Run?.DebugMode, Constants.Agent.CommandLine.Flags.DebugMode);
556-
}
557-
558553
public bool GetDeploymentPool()
559554
{
560555
return TestFlag(Configure?.DeploymentPool, Constants.Agent.CommandLine.Flags.DeploymentPool);

src/Agent.Sdk/Knob/AgentKnobs.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ public class AgentKnobs
213213
new EnvironmentKnobSource("VSTSAGENT_TRACE"),
214214
new BuiltInDefaultKnobSource(string.Empty));
215215

216-
public static readonly Knob DebugTask = new Knob(
217-
nameof(DebugTask),
218-
"If the agent executes a task which ID or name matches the value provided, it will run the task so that it will wait for debugger to attach",
219-
new EnvironmentKnobSource("VSTSAGENT_DEBUG_TASK"),
220-
new BuiltInDefaultKnobSource(string.Empty));
221-
222216
public static readonly Knob DumpJobEventLogs = new Knob(
223217
nameof(DumpJobEventLogs),
224218
"If true, dump event viewer logs",

src/Agent.Worker/Handlers/NodeHandler.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,6 @@ public async Task RunAsync()
224224
var sigtermTimeout = TimeSpan.FromMilliseconds(AgentKnobs.ProccessSigtermTimeout.GetValue(ExecutionContext).AsInt());
225225
var useGracefulShutdown = AgentKnobs.UseGracefulProcessShutdown.GetValue(ExecutionContext).AsBoolean();
226226

227-
var configStore = HostContext.GetService<IConfigurationStore>();
228-
var agentSettings = configStore.GetSettings();
229-
if (agentSettings.DebugMode)
230-
{
231-
var debugTask = AgentKnobs.DebugTask.GetValue(ExecutionContext).AsString();
232-
if (!string.IsNullOrEmpty(debugTask))
233-
{
234-
if (string.Equals(Task?.Id.ToString("D"), debugTask, StringComparison.OrdinalIgnoreCase) || string.Equals(Task?.Name, debugTask, StringComparison.OrdinalIgnoreCase))
235-
{
236-
arguments = $"--inspect-brk {arguments}";
237-
}
238-
}
239-
}
240-
241-
242227
try
243228
{
244229
// Execute the process. Exit code 0 should always be returned.

src/Agent.Worker/Handlers/ProcessHandler/ProcessHandlerHelper.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using Agent.Sdk.Knob;
7+
using Microsoft.TeamFoundation.DistributedTask.WebApi;
78
using Microsoft.VisualStudio.Services.Agent.Util;
89
using Microsoft.VisualStudio.Services.Common;
910

@@ -132,7 +133,13 @@ public static (bool, Dictionary<string, object>) ValidateInputArguments(
132133
{
133134
if (enableAudit && !enableValidation)
134135
{
135-
context.Warning(StringUtil.Loc("ProcessHandlerInvalidScriptArgs"));
136+
var issue = new Issue
137+
{
138+
Type = IssueType.Warning,
139+
Message = StringUtil.Loc("ProcessHandlerInvalidScriptArgs"),
140+
};
141+
issue.Data.Add("auditAction", "1"); // ShellTasksValidation = 1
142+
context.AddIssue(issue);
136143
}
137144
if (enableValidation)
138145
{

src/Agent.Worker/Handlers/ProcessHandler/ProcessHandlerV2.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using Agent.Sdk.Knob;
5+
using Microsoft.TeamFoundation.DistributedTask.WebApi;
56
using Microsoft.VisualStudio.Services.Agent.Util;
67
using Newtonsoft.Json;
78
using System;
@@ -288,7 +289,13 @@ private void ValidateScriptArgs(
288289

289290
if (!shouldThrow && enableSecureArgumentsAudit)
290291
{
291-
ExecutionContext.Warning(StringUtil.Loc("ProcessHandlerInvalidScriptArgs"));
292+
var issue = new Issue
293+
{
294+
Type = IssueType.Warning,
295+
Message = StringUtil.Loc("ProcessHandlerInvalidScriptArgs"),
296+
};
297+
issue.Data.Add("auditAction", "1"); // ShellTasksValidation = 1
298+
ExecutionContext.AddIssue(issue);
292299
}
293300
}
294301
if (enableTelemetry && telemetry != null)

src/Agent.Worker/JobExtension.cs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,7 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
129129

130130
// Machine specific setup info
131131
OutputSetupInfo(context);
132-
133-
string imageVersion = System.Environment.GetEnvironmentVariable(Constants.ImageVersionVariable);
134-
if (imageVersion != null)
135-
{
136-
context.Output(StringUtil.Loc("ImageVersionLog", imageVersion));
137-
}
138-
132+
OutputImageVersion(context);
139133
context.Output(StringUtil.Loc("UserNameLog", System.Environment.UserName));
140134

141135
// Print proxy setting information for better diagnostic experience
@@ -498,7 +492,6 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
498492
}
499493
}
500494
}
501-
502495
List<IStep> steps = new List<IStep>();
503496
steps.AddRange(preJobSteps);
504497
steps.AddRange(jobSteps);
@@ -515,7 +508,6 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
515508
// Set the VSTS_PROCESS_LOOKUP_ID env variable.
516509
context.SetVariable(Constants.ProcessLookupId, _processLookupId, false, false);
517510
context.Output("Start tracking orphan processes.");
518-
519511
// Take a snapshot of current running processes
520512
Dictionary<int, Process> processes = SnapshotProcesses();
521513
foreach (var proc in processes)
@@ -534,7 +526,7 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
534526
if (AgentKnobs.FailJobWhenAgentDies.GetValue(jobContext).AsBoolean() &&
535527
HostContext.AgentShutdownToken.IsCancellationRequested)
536528
{
537-
PublishTelemetry(jobContext, TaskResult.Failed.ToString(), "110");
529+
PublishAgentShutdownTelemetry(jobContext, context);
538530
Trace.Error($"Caught Agent Shutdown exception from JobExtension Initialization: {ex.Message}");
539531
context.Error(ex);
540532
context.Result = TaskResult.Failed;
@@ -564,6 +556,18 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
564556
}
565557
}
566558

559+
private void PublishAgentShutdownTelemetry(IExecutionContext jobContext, IExecutionContext childContext)
560+
{
561+
var telemetryData = new Dictionary<string, string>
562+
{
563+
{ "JobId", childContext?.Variables?.System_JobId?.ToString() ?? string.Empty },
564+
{ "JobResult", TaskResult.Failed.ToString() },
565+
{ "TracePoint", "110" },
566+
};
567+
568+
PublishTelemetry(jobContext, telemetryData, "AgentShutdown");
569+
}
570+
567571
public async Task FinalizeJob(IExecutionContext jobContext)
568572
{
569573
Trace.Entering();
@@ -691,6 +695,29 @@ private Dictionary<int, Process> SnapshotProcesses()
691695
return snapshot;
692696
}
693697

698+
private void OutputImageVersion(IExecutionContext context)
699+
{
700+
string imageVersion = System.Environment.GetEnvironmentVariable(Constants.ImageVersionVariable);
701+
string jobId = context?.Variables?.System_JobId?.ToString() ?? string.Empty;
702+
703+
if (imageVersion != null)
704+
{
705+
context.Output(StringUtil.Loc("ImageVersionLog", imageVersion));
706+
}
707+
else
708+
{
709+
Trace.Info($"Image version for job id {jobId} is not set");
710+
}
711+
712+
var telemetryData = new Dictionary<string, string>()
713+
{
714+
{ "JobId", jobId },
715+
{ "ImageVersion", imageVersion },
716+
};
717+
718+
PublishTelemetry(context, telemetryData, "ImageVersionTelemetry");
719+
}
720+
694721
private void OutputSetupInfo(IExecutionContext context)
695722
{
696723
try
@@ -724,28 +751,22 @@ private void OutputSetupInfo(IExecutionContext context)
724751
}
725752
}
726753

727-
private void PublishTelemetry(IExecutionContext context, string Task_Result, string TracePoint)
754+
private void PublishTelemetry(IExecutionContext context, Dictionary<string, string> telemetryData, string feature)
728755
{
729756
try
730757
{
731-
var telemetryData = new Dictionary<string, string>
732-
{
733-
{ "JobId", context.Variables.System_JobId.ToString()},
734-
{ "JobResult", Task_Result },
735-
{ "TracePoint", TracePoint},
736-
};
737758
var cmd = new Command("telemetry", "publish");
738759
cmd.Data = JsonConvert.SerializeObject(telemetryData, Formatting.None);
739760
cmd.Properties.Add("area", "PipelinesTasks");
740-
cmd.Properties.Add("feature", "AgentShutdown");
761+
cmd.Properties.Add("feature", feature);
741762

742763
var publishTelemetryCmd = new TelemetryCommandExtension();
743764
publishTelemetryCmd.Initialize(HostContext);
744765
publishTelemetryCmd.ProcessCommand(context, cmd);
745766
}
746767
catch (Exception ex)
747768
{
748-
Trace.Warning($"Unable to publish agent shutdown telemetry data. Exception: {ex}");
769+
Trace.Warning($"Unable to publish telemetry data. Exception: {ex}");
749770
}
750771
}
751772
}

src/Microsoft.VisualStudio.Services.Agent/ConfigurationStore.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ public string Fingerprint
132132

133133
[DataMember(EmitDefaultValue = false)]
134134
public int MaxDedupParallelism { get; set; }
135-
136-
[DataMember(EmitDefaultValue = false)]
137-
public bool DebugMode { get; set; }
138135
}
139136

140137
[DataContract]

src/Microsoft.VisualStudio.Services.Agent/Constants.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ public static class Flags
225225
public const string NoRestart = "norestart";
226226
public const string LaunchBrowser = "launchbrowser";
227227
public const string Once = "once";
228-
public const string DebugMode = "debug";
229228
public const string RunAsAutoLogon = "runasautologon";
230229
public const string RunAsService = "runasservice";
231230
public const string PreventServiceStart = "preventservicestart";

0 commit comments

Comments
 (0)